Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions lib/action_account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def banner
* #{basename} reinstate-user uuid1 uuid2

* #{basename} confirm-suspend-user uuid1 uuid2

* #{basename} clear-device-profiling-failure uuid1 uuid2
Options:
EOS
end
Expand All @@ -59,6 +61,7 @@ def subtask(name)
'suspend-user' => SuspendUser,
'reinstate-user' => ReinstateUser,
'confirm-suspend-user' => ConfirmSuspendUser,
'clear-device-profiling-failure' => ClearDeviceProfilingFailure,
}[name]
end

Expand All @@ -83,6 +86,9 @@ def log_text
user_already_suspended: 'User has already been suspended',
user_is_not_suspended: 'User is not suspended',
user_already_reinstated: 'User has already been reinstated',
device_profiling_approved: 'Device profiling result has been updated to pass',
device_profiling_already_passed: 'Device profiling result already passed',
device_profiling_no_results_found: 'No device profiling results found for this user',
}
end
end
Expand Down Expand Up @@ -124,6 +130,19 @@ def perform_user_action(args:, config:, action:)
else
log_texts << log_text[:user_is_not_suspended]
end
when :clear_device_profiling_failure
result = DeviceProfilingResult.where(
user_id: user.id,
profiling_type: DeviceProfilingResult::PROFILING_TYPES[:account_creation],
).first
if result.nil?
log_texts << log_text[:device_profiling_no_results_found]
elsif result.review_status == 'pass'
log_texts << log_text[:device_profiling_already_passed]
else
result.update!(review_status: 'pass', notes: 'Manually overridden')
log_texts << log_text[:device_profiling_approved]
end
else
raise "unknown subtask=#{action}"
end
Expand Down Expand Up @@ -407,5 +426,16 @@ def run(args:, config:)
)
end
end

class ClearDeviceProfilingFailure
include UserActions
def run(args:, config:)
perform_user_action(
args:,
config:,
action: :clear_device_profiling_failure,
)
end
end
end
# rubocop:enable Metrics/BlockLength
79 changes: 0 additions & 79 deletions lib/tasks/device_profiling.rake

This file was deleted.

34 changes: 34 additions & 0 deletions spec/lib/action_account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -457,4 +457,38 @@
end
end
end

describe ActionAccount::ClearDeviceProfilingFailure do
subject(:subtask) { ActionAccount::ClearDeviceProfilingFailure.new }

describe '#run' do
let(:user) { create(:user) }
let(:user2) { create(:user) }
let!(:device_profiling_result) do
create(
:device_profiling_result,
user:,
review_status: 'reject',
profiling_type: DeviceProfilingResult::PROFILING_TYPES[:account_creation],
)
end
let(:args) { [user.uuid, user2.uuid] }
let(:include_missing) { true }
let(:config) { ScriptBase::Config.new(include_missing:) }
subject(:result) { subtask.run(args:, config:) }

it 'clears device profiling failure for the user', aggregate_failures: true do
expect(result.table).to match_array(
[
['uuid', 'status', 'reason'],
[user.uuid, 'Device profiling result has been updated to pass', nil],
[user2.uuid, 'No device profiling results found for this user', nil],
],
)

expect(result.subtask).to eq('clear-device-profiling-failure-user')
expect(result.uuids).to match_array([user.uuid, user2.uuid])
end
end
end
end