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
17 changes: 17 additions & 0 deletions app/controllers/case_assignments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,23 @@ def destroy
redirect_to after_action_path(case_assignment_parent)
end

def unassign
case_assignment = CaseAssignment.find(params[:id])
casa_case = case_assignment.casa_case
volunteer = case_assignment.volunteer
flash_message = "Volunteer was unassigned from Case #{casa_case.case_number}."

if case_assignment.update_attributes(is_active: false)
if params[:redirect_to_path] == "volunteer"
redirect_to edit_volunteer_path(volunteer), notice: flash_message
else
redirect_to after_action_path(casa_case), notice: flash_message
end
else
render :edit
end
end

private

def case_assignment_parent
Expand Down
16 changes: 15 additions & 1 deletion app/views/casa_cases/_volunteer_assignment.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<tr>
<th>Volunteer Name</th>
<th>Volunteer Email</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
Expand All @@ -16,7 +17,20 @@
<tr>
<td><%= link_to assignment&.volunteer&.display_name, edit_volunteer_path(assignment.volunteer) %></td>
<td><%= assignment&.volunteer&.email %></td>
<td><%= button_to 'Unassign Volunteer', case_assignment_path(assignment, casa_case_id: @casa_case.id), method: :delete, class: "btn btn-danger" %></td>
<td>
<% if assignment.is_active? %>
<span class='badge badge-success text-uppercase'>Assigned</span>
<% else %>
<span class="badge badge-danger text-uppercase">Unassigned</span>
<% end %>
</td>
<td>
<% if assignment.is_active? && current_user.role == "casa_admin" || assignment.volunteer.supervisor == current_user %>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

volunteer.supervisor should be volunteer&.supervisor because not all volunteers will have supervisors

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@compwron i'm pretty sure that the & in this case is only verifying that the volunteer is present, so if the volunteer doesn't have a supervisor volunteer.supervisor will be nil

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pretty sure the & would be needed if not all assignments have volunteers (but the assignment has a belongs_to that validates volunteer is present)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense :)

<%= button_to 'Unassign Volunteer', unassign_case_assignment_path(assignment), method: :patch, class: "btn btn-outline-danger" %>
<% else %>
N/A
<% end %>
</td>
</tr>
<% end %>
</tbody>
Expand Down
2 changes: 1 addition & 1 deletion app/views/volunteers/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<tr>
<td><%= link_to assignment.casa_case.case_number, edit_casa_case_path(assignment.casa_case) %></td>
<td><%= assignment.casa_case.transition_aged_youth %></td>
<td><%= button_to 'Unassign Case', case_assignment_path(assignment, volunteer_id: @volunteer.id), method: :delete, class: "btn btn-danger" %></td>
<td><%= button_to 'Unassign Case', case_assignment_path(assignment, volunteer_id: @volunteer.id), method: :delete, class: "btn btn-danger" if current_user.role == "casa_admin" || @volunteer.supervisor == current_user%></td>
</tr>
<% end %>
</tbody>
Expand Down
7 changes: 6 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
resources :case_contact_reports, only: %i[index]

resources :volunteers, only: %i[new edit create update]
resources :case_assignments, only: %i[create destroy]
resources :case_assignments, only: %i[create destroy] do
member do
get :unassign
patch :unassign
end
end

resources :users, only: [] do
collection do
Expand Down