-
Notifications
You must be signed in to change notification settings - Fork 166
LG-8390 Write rake tasks to pass or reject users #7536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ad284da
initial steps for rake script to review profile
theabrad 0f924af
rewrite tasks for passing and rejecting
theabrad 9f265ec
add tests for review_profile rake task
theabrad c09150a
add changelog
theabrad 00d8476
activate profile upon passing review
theabrad fe6f773
check for deactivation reason in passing
theabrad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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') | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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') | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need/want a new |
||
| 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.