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
12 changes: 12 additions & 0 deletions app/controllers/volunteers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def create

def edit
@volunteer = User.find(params[:id])
@volunteer_active = @volunteer.active_volunteer
end

def update
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
4 changes: 2 additions & 2 deletions app/views/casa_cases/_volunteer_assignment.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<% if assignment.is_active? %>
<span class='badge badge-success text-uppercase'>Assigned</span>
<% else %>
<span class="badge badge-danger text-uppercase">Unassigned</span>
<span class="badge badge-danger text-uppercase"><%= assignment.volunteer.active_volunteer ? "Unassigned" : "Deactivated volunteer" %></span>
<% end %>
</td>
<td>
Expand Down Expand Up @@ -56,7 +56,7 @@
</select>
</div>

<%= form.submit 'Assign Volunteer', class: 'btn btn-primary' %>
<%= form.submit 'Assign Volunteer', class: 'btn btn-secondary' %>
<% end %>
</div>
</div>
71 changes: 41 additions & 30 deletions app/views/volunteers/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,25 @@


<div class="field form-group">
<%= form.label "Status" %>
<div class="form-check">
<input class="form-check-input" type="radio" name="user[role]" id="statusRadio1" value="volunteer" <% if @volunteer.role == "volunteer" %> checked<% end %>>
<label class="form-check-label" for="statusRadio1">
Active
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="user[role]" id="statusRadio2" value="inactive" <% if @volunteer.role == "inactive" %> 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?')">
<label class="form-check-label" for="statusRadio2">
Inactive
</label>
</div>
<% if @volunteer_active %>
Volunteer is <span class="badge badge-success text-uppercase display-1">Active</span>
<% 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.
<br><br>They will receive an email saying their account has been marked inactive.
<br><br>Are you sure you want to do this?".html_safe },
hint: "NOTE: This will make connected cases unassigned and<br>
the volunteer won't be able to log in to the system anymore".html_safe %>
<% end %>
<% else %>
<div class="alert alert-danger">
Volunteer was deactivated on: <%= @volunteer.updated_at.strftime("%m-%d-%Y") %>
</div>
<% end %>
</div>

<div class="actions">
Expand All @@ -70,7 +76,10 @@
<tr>
<th>Case Number</th>
<th>Transition Aged Youth</th>
<th>Actions</th>
<th>Assignment status</th>
<% if @volunteer_active %>
<th>Actions</th>
<% end %>
</tr>
</thead>
<tbody>
Expand All @@ -87,24 +96,26 @@
</div>
<% end %>

<br>
<% if @volunteer_active %>
<br>

<div class="row">
<div class="col-sm-6">
<h3>Assign a New Case</h3>
<div class="row">
<div class="col-sm-6">
<h3>Assign a New Case</h3>

<%= 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| %>

<div class='form-group'>
<label for='case_assignment_casa_case_id'>Select a Case</label>
<select name='case_assignment[casa_case_id]' class='form-control'>
<% CasaCase.all.each do |casa_case| %>
<option value="<%= casa_case.id %>"><%= casa_case.case_number %></option>
<% end %>
</select>
</div>
<div class='form-group'>
<label for='case_assignment_casa_case_id'>Select a Case</label>
<select name='case_assignment[casa_case_id]' class='form-control'>
<% CasaCase.all.each do |casa_case| %>
<option value="<%= casa_case.id %>"><%= casa_case.case_number %></option>
<% end %>
</select>
</div>

<%= form.submit 'Assign Case', class: 'btn btn-primary' %>
<% end %>
<%= form.submit 'Assign Case', class: 'btn btn-primary' %>
<% end %>
</div>
</div>
</div>
<% end %>
7 changes: 6 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions spec/system/admin_edit_volunteer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down