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
1 change: 1 addition & 0 deletions app/models/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Profile < ApplicationRecord
verification_cancelled: 4,
in_person_verification_pending: 5,
threatmetrix_review_pending: 6,
threatmetrix_review_rejected: 7,
}

attr_reader :personal_key
Expand Down
4 changes: 4 additions & 0 deletions app/models/proofing_component.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
class ProofingComponent < ApplicationRecord
belongs_to :user

def review_eligible?
verified_at.after?(30.days.ago)
end
end
45 changes: 45 additions & 0 deletions lib/tasks/review_profile.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require 'io/console'

namespace :users do
namespace :review do
desc 'Pass a user that has a pending review'
task pass: :environment do |_task, args|
user_uuid = STDIN.getpass('Enter the User UUID to pass (input will be hidden):')
user = User.find_by(uuid: user_uuid)

if user.decorate.threatmetrix_review_pending? && user.proofing_component.review_eligible?
result = ProofingComponent.find_by(user: user)
result.update(threatmetrix_review_status: 'pass')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we also need to activate the associated profile?

user.profiles.
where(deactivation_reason: 'threatmetrix_review_pending').
first.
activate
puts "User's review state has been updated to #{result.threatmetrix_review_status}."
elsif !user.proofing_component.review_eligible?
puts 'User is past the 30 day review eligibility'
else
puts 'User was not found pending a review'
end
end

desc 'Reject a user that has a pending review'
task reject: :environment do |_task, args|
user_uuid = STDIN.getpass('Enter the User UUID to reject (input will be hidden):')
user = User.find_by(uuid: user_uuid)

if user.decorate.threatmetrix_review_pending? && user.proofing_component.review_eligible?
result = ProofingComponent.find_by(user: user)
result.update(threatmetrix_review_status: 'reject')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need/want a new deactivation_reason on the profile of threatmetrix_review_rejected?

user.profiles.
where(deactivation_reason: 'threatmetrix_review_pending').
first.
deactivate(:threatmetrix_review_rejected)
puts "User's review state has been updated to #{result.threatmetrix_review_status}."
elsif !user.proofing_component.review_eligible?
puts 'User is past the 30 day review eligibility'
else
puts 'User was not found pending a review'
end
end
end
end
5 changes: 5 additions & 0 deletions spec/factories/profiles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
deactivation_reason { :password_reset }
end

trait :threatmetrix_review_pending do
deactivation_reason { :threatmetrix_review_pending }
proofing_components { { threatmetrix_review_status: 'review' } }
end

trait :verification_cancelled do
deactivation_reason { :verification_cancelled }
end
Expand Down
10 changes: 10 additions & 0 deletions spec/factories/proofing_components.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FactoryBot.define do
factory :proofing_component do
association :user, factory: %i[user signed_up]

trait :eligible_for_review do
verified_at { Time.zone.now }
threatmetrix_review_status { 'review' }
end
end
end
9 changes: 9 additions & 0 deletions spec/factories/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,15 @@
end
end

trait :deactivated_threatmetrix_profile do
signed_up

after :build do |user|
create(:profile, :threatmetrix_review_pending, :with_pii, user: user)
create(:proofing_component, :eligible_for_review, user: user)
end
end

trait :deactivated_password_reset_profile do
signed_up

Expand Down
33 changes: 33 additions & 0 deletions spec/lib/tasks/review_profile_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'rails_helper'
require 'rake'

describe 'review_profile' do
before do
Rake.application.rake_require('lib/tasks/review_profile', [Rails.root.to_s])
Rake::Task.define_task(:environment)
end

describe 'users:review:pass' do
it 'sets threatmetrix_review_status to pass' do
user = create(:user, :deactivated_threatmetrix_profile)

allow(STDIN).to receive(:getpass) { user.uuid }

Rake::Task['users:review:pass'].invoke
expect(user.reload.proofing_component.threatmetrix_review_status).to eq('pass')
expect(user.reload.profiles.first.active).to eq(true)
end
end

describe 'users:review:reject' do
it 'sets threatmetrix_review_status to reject' do
user = create(:user, :deactivated_threatmetrix_profile)

allow(STDIN).to receive(:getpass) { user.uuid }

Rake::Task['users:review:reject'].invoke
expect(user.reload.proofing_component.threatmetrix_review_status).to eq('reject')
expect(user.reload.profiles.first.deactivation_reason).to eq('threatmetrix_review_rejected')
end
end
end