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 1f0bd93325..1be25332fe 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 %> @@ -56,7 +56,7 @@ - <%= form.submit 'Assign Volunteer', class: 'btn btn-primary' %> + <%= form.submit 'Assign Volunteer', class: 'btn btn-secondary' %> <% end %> diff --git a/app/views/volunteers/edit.html.erb b/app/views/volunteers/edit.html.erb index 368ad34e42..455a71ba3f 100644 --- a/app/views/volunteers/edit.html.erb +++ b/app/views/volunteers/edit.html.erb @@ -38,19 +38,25 @@
- <%= 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 + <% 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") %> +
+ <% end %>
@@ -70,7 +76,10 @@ Case Number Transition Aged Youth - Actions + Assignment status + <% if @volunteer_active %> + Actions + <% end %> @@ -87,24 +96,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 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")