From 959069bd1791361c4c8b67da88b184a810b53f13 Mon Sep 17 00:00:00 2001 From: Mae Beale Date: Sun, 14 Jun 2020 14:44:02 -0400 Subject: [PATCH 1/4] Allow volunteers to be deactivated (and differentiate on casa_cases/edit) --- app/controllers/volunteers_controller.rb | 12 +++ app/models/user.rb | 4 + .../casa_cases/_volunteer_assignment.html.erb | 2 +- app/views/volunteers/edit.html.erb | 86 ++++++++++++------- config/routes.rb | 7 +- 5 files changed, 78 insertions(+), 33 deletions(-) diff --git a/app/controllers/volunteers_controller.rb b/app/controllers/volunteers_controller.rb index 0b77e3acff..0632d7ae88 100644 --- a/app/controllers/volunteers_controller.rb +++ b/app/controllers/volunteers_controller.rb @@ -21,6 +21,7 @@ def create def edit @volunteer = User.find(params[:id]) + @volunteer_active = @volunteer.active_volunteer end def update @@ -33,6 +34,17 @@ def update end end + def deactivate + @volunteer = User.find(params[:id]) + + if @volunteer.update_attributes(role: "inactive") + @volunteer.case_assignments.update_all(is_active: false) + redirect_to edit_volunteer_path(@volunteer), notice: "Volunteer was deactivated." + else + render :edit + end + end + private def generate_devise_password diff --git a/app/models/user.rb b/app/models/user.rb index 44a38d1f45..db64df8c80 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -14,6 +14,10 @@ class User < ApplicationRecord ALL_ROLES = %w[volunteer supervisor casa_admin inactive].freeze enum role: ALL_ROLES.zip(ALL_ROLES).to_h + def active_volunteer + role == "volunteer" # !inactive + end + # all contacts this user has with this casa case def case_contacts_for(casa_case_id) found_casa_case = casa_cases.find { |cc| cc.id == casa_case_id } diff --git a/app/views/casa_cases/_volunteer_assignment.html.erb b/app/views/casa_cases/_volunteer_assignment.html.erb index 786f034111..454022adec 100644 --- a/app/views/casa_cases/_volunteer_assignment.html.erb +++ b/app/views/casa_cases/_volunteer_assignment.html.erb @@ -21,7 +21,7 @@ <% if assignment.is_active? %> Assigned <% else %> - Unassigned + <%= assignment.volunteer.active_volunteer ? "Unassigned" : "Deactivated volunteer" %> <% end %> diff --git a/app/views/volunteers/edit.html.erb b/app/views/volunteers/edit.html.erb index a42ff34721..68bb373ed3 100644 --- a/app/views/volunteers/edit.html.erb +++ b/app/views/volunteers/edit.html.erb @@ -38,19 +38,23 @@
- <%= form.label "Status" %> -
- checked<% end %>> - -
-
- checked<% end %> onclick="return confirm('WARNING: Marking a volunteer inactive will make them unable to login. They will receive an email saying their account has been marked inactive. Are you sure you want to do this?')"> - -
+ <% if @volunteer_active %> + Volunteer is Active + <%= link_to "Deactivate volunteer", + deactivate_volunteer_path(@volunteer), + method: :patch, + class: "btn btn-outline-danger", + data: + { confirm: "WARNING: Marking a volunteer inactive will make them unable to login. +

They will receive an email saying their account has been marked inactive. +

Are you sure you want to do this?".html_safe }, + hint: "NOTE: This will make connected cases unassigned and
+ the volunteer won't be able to log in to the system anymore".html_safe %> + <% else %> +
+ Volunteer was deactivated on: <%= @volunteer.updated_at.strftime("%m-%d-%Y") %> +
+ <% end %>
@@ -70,7 +74,10 @@ Case Number Transition Aged Youth - Actions + Assignment status + <% if @volunteer_active %> + Actions + <% end %> @@ -78,7 +85,22 @@ <%= link_to assignment.casa_case.case_number, edit_casa_case_path(assignment.casa_case) %> <%= assignment.casa_case.transition_aged_youth %> - <%= button_to 'Unassign Case', case_assignment_path(assignment, volunteer_id: @volunteer.id), method: :delete, class: "btn btn-danger" %> + + <% if assignment.is_active? %> + Assigned + <% else %> + <%= assignment.volunteer.active_volunteer ? "Unassigned" : "Deactivated volunteer" %> + <% end %> + + <% if @volunteer_active %> + + <% if assignment.is_active? %> + <%= link_to 'Unassign Case', unassign_case_assignment_path(assignment, redirect_to_path: "volunteer"), method: :patch, class: "btn btn-outline-danger" %> + <% else %> + N/A + <% end %> + + <% end %> <% end %> @@ -87,24 +109,26 @@
<% end %> -
+<% if @volunteer_active %> +
-
-
-

Assign a New Case

+
+
+

Assign a New Case

- <%= form_for CaseAssignment.new, url: case_assignments_path(volunteer_id: @volunteer.id) do |form| %> + <%= form_for CaseAssignment.new, url: case_assignments_path(volunteer_id: @volunteer.id) do |form| %> -
- - -
+
+ + +
- <%= form.submit 'Assign Case', class: 'btn btn-primary' %> - <% end %> + <%= form.submit 'Assign Case', class: 'btn btn-primary' %> + <% end %> +
-
+<% end %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index e1a4d65ca3..79e9170099 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,7 +9,12 @@ resources :reports, only: %i[index] resources :case_contact_reports, only: %i[index] - resources :volunteers, only: %i[new edit create update] + resources :volunteers, only: %i[new edit create update] do + member do + get :deactivate + patch :deactivate + end + end resources :case_assignments, only: %i[create destroy] do member do get :unassign From 8e799fc9a9587551eb7c4ee8eb4333c5975353af Mon Sep 17 00:00:00 2001 From: Mae Beale Date: Sun, 14 Jun 2020 14:45:27 -0400 Subject: [PATCH 2/4] Change Assign volunteer button to secondary instead of primary --- app/views/casa_cases/_volunteer_assignment.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/casa_cases/_volunteer_assignment.html.erb b/app/views/casa_cases/_volunteer_assignment.html.erb index 454022adec..1985362807 100644 --- a/app/views/casa_cases/_volunteer_assignment.html.erb +++ b/app/views/casa_cases/_volunteer_assignment.html.erb @@ -56,7 +56,7 @@
- <%= form.submit 'Assign Volunteer', class: 'btn btn-primary' %> + <%= form.submit 'Assign Volunteer', class: 'btn btn-secondary' %> <% end %> From 80ad742d6f98334506cfbdebbaaf1aff302232d4 Mon Sep 17 00:00:00 2001 From: Mae Beale Date: Sun, 14 Jun 2020 15:17:01 -0400 Subject: [PATCH 3/4] Only casa_admins or direct supervisors can deactivate volunteers --- app/views/volunteers/edit.html.erb | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/app/views/volunteers/edit.html.erb b/app/views/volunteers/edit.html.erb index 68bb373ed3..dcc837ff55 100644 --- a/app/views/volunteers/edit.html.erb +++ b/app/views/volunteers/edit.html.erb @@ -40,16 +40,18 @@
<% if @volunteer_active %> Volunteer is Active - <%= link_to "Deactivate volunteer", - deactivate_volunteer_path(@volunteer), - method: :patch, - class: "btn btn-outline-danger", - data: - { confirm: "WARNING: Marking a volunteer inactive will make them unable to login. -

They will receive an email saying their account has been marked inactive. -

Are you sure you want to do this?".html_safe }, - hint: "NOTE: This will make connected cases unassigned and
- the volunteer won't be able to log in to the system anymore".html_safe %> + <% if current_user.role == "casa_admin" || @volunteer.supervisor == current_user %> + <%= link_to "Deactivate volunteer", + deactivate_volunteer_path(@volunteer), + method: :patch, + class: "btn btn-outline-danger", + data: + { confirm: "WARNING: Marking a volunteer inactive will make them unable to login. +

They will receive an email saying their account has been marked inactive. +

Are you sure you want to do this?".html_safe }, + hint: "NOTE: This will make connected cases unassigned and
+ the volunteer won't be able to log in to the system anymore".html_safe %> + <% end %> <% else %>
Volunteer was deactivated on: <%= @volunteer.updated_at.strftime("%m-%d-%Y") %> From 3a03897a06c9b22ce46e2dd7513c6e666cf164e4 Mon Sep 17 00:00:00 2001 From: Linda Date: Sun, 14 Jun 2020 14:55:06 -0700 Subject: [PATCH 4/4] Fix test to deactivate volunteer --- spec/system/admin_edit_volunteer_spec.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/spec/system/admin_edit_volunteer_spec.rb b/spec/system/admin_edit_volunteer_spec.rb index 4013765139..b9b1182b09 100644 --- a/spec/system/admin_edit_volunteer_spec.rb +++ b/spec/system/admin_edit_volunteer_spec.rb @@ -9,16 +9,15 @@ visit edit_volunteer_path(volunteer) dismiss_confirm do - choose "Inactive" + click_on "Deactivate volunteer" end - expect(find_field("statusRadio2")).not_to be_checked + expect(page).not_to have_text('Volunteer was deactivated on') accept_confirm do - choose "Inactive" + click_on "Deactivate volunteer" end - expect(find_field("statusRadio2")).to be_checked + expect(page).to have_text('Volunteer was deactivated on') - click_on "Submit" expect { volunteer.reload }.to change { volunteer.role }.from("volunteer").to("inactive")