Skip to content

Commit

Permalink
Do not show inactive users as options for task assignee (#13111)
Browse files Browse the repository at this point in the history
Resolves #12949

### Description
In "Assign to Person"  task assignment modals, we were offering inactive users 

### Acceptance Criteria
- [ ] Test suite passes.

### Testing Plan
1. Log in as translation team member #1, e.g.  ORG_QUEUE_USER_1
2. Navigate to http://localhost:3000/organizations/translation, open a case (e.g. http://localhost:3000/queue/appeals/2e7d0f5b-f9eb-4767-9b41-40426d9b0562)
3. In task actions, go to "Assign to Person".  You should see Translation team member #5. 
4. Now make Translation team member #5 as inactive in the rails console: 
`User.find_by_css_id("ORG_QUEUE_USER_5").inactive!`
5. Repeat steps 1 through 3.  You should no longer see Team Member 5.

### User Facing Changes
BEFORE: 
<img width="1029" alt="Screen Shot 2020-01-13 at 9 54 00 AM" src="https://user-images.githubusercontent.com/1034221/72265627-ce6b9d80-35ea-11ea-8a78-5fa5fd7e2158.png">

AFTER:
<img width="1070" alt="Screen Shot 2020-01-13 at 9 58 46 AM" src="https://user-images.githubusercontent.com/1034221/72265913-4f2a9980-35eb-11ea-846f-a4242d69edf1.png">
  • Loading branch information
kevmo authored and va-bot committed Jan 13, 2020
1 parent c6f622d commit 2bdd7f3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
20 changes: 13 additions & 7 deletions app/repositories/task_action_repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,7 @@ def send_to_schedule_veterans_list(task, _user = nil)
end

def assign_to_user_data(task, user = nil)
users = if task.assigned_to.is_a?(Organization)
task.assigned_to.users
elsif task.parent&.assigned_to.is_a?(Organization)
task.parent.assigned_to.users.reject { |check_user| check_user == task.assigned_to }
else
[]
end
users = potential_task_assignees(task)

extras = if task.is_a?(HearingAdminActionTask)
{
Expand Down Expand Up @@ -344,5 +338,17 @@ def users_to_options(users)
}
end
end

def potential_task_assignees(task)
if task.assigned_to.is_a?(Organization)
task.assigned_to.users.reject(&:inactive?)
elsif task.parent&.assigned_to.is_a?(Organization)
task.parent.assigned_to.users.reject do |check_user|
check_user == task.assigned_to || check_user.inactive?
end
else
[]
end
end
end
end
4 changes: 4 additions & 0 deletions spec/factories/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
roles { ["Mail Intake"] }
end

trait :inactive do
status { "inactive" }
end

trait :vso_role do
roles { ["VSO"] }
end
Expand Down
8 changes: 4 additions & 4 deletions spec/repositories/task_action_repository_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe TaskActionRepository, :all_dbs do
describe "#assign_to_user_data" do
let(:organization) { create(:organization, name: "Organization") }
let(:users) { create_list(:user, 3) }
let(:users) { create_list(:user, 3) + create_list(:user, 2, :inactive) }

before do
allow(organization).to receive(:users).and_return(users)
Expand All @@ -12,8 +12,8 @@
context "when assigned_to is an organization" do
let(:task) { create(:ama_task, assigned_to: organization) }

it "should return all members" do
match_users = users.map { |u| { label: u.full_name, value: u.id } }
it "should return all active members" do
match_users = users.reject(&:inactive?).map { |u| { label: u.full_name, value: u.id } }
expect(TaskActionRepository.assign_to_user_data(task)[:options]).to match_array match_users
end

Expand All @@ -27,7 +27,7 @@
let(:task) { create(:ama_task, assigned_to: users.first, parent: parent) }

it "should return all members except user" do
user_output = users[1..users.length - 1].map { |u| { label: u.full_name, value: u.id } }
user_output = users[1..users.length - 1].reject(&:inactive?).map { |u| { label: u.full_name, value: u.id } }
expect(TaskActionRepository.assign_to_user_data(task)[:options]).to match_array(user_output)
end
end
Expand Down

0 comments on commit 2bdd7f3

Please sign in to comment.