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
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ end

group :development do
gem 'annotate' # for adding db field listings to models as comments
gem 'letter_opener' # Opens emails in new tab for easier testing
gem 'listen', '>= 3.0.5', '< 3.2'
gem 'rails-erd'
gem 'spring' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring-watcher-listen', '~> 2.0.0'
gem 'letter_opener'
gem 'web-console', '>= 3.3.0' # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
end

Expand Down
7 changes: 7 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@ class ApplicationController < ActionController::Base
include Pundit
protect_from_forgery
before_action :set_paper_trail_whodunnit

def must_be_admin
return if current_user&.casa_admin?

flash[:notice] = 'You do not have permission to view that page.'
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.

Nice :)

redirect_to root_url
end
end
31 changes: 31 additions & 0 deletions app/controllers/case_assignments_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class CaseAssignmentsController < ApplicationController
before_action :must_be_admin

def index
@volunteer = User.find(params[:volunteer_id]).decorate
end

def create
volunteer = User.find(params[:volunteer_id])
case_assignment = volunteer.case_assignments.new(case_assignment_params)
Comment thread
compwron marked this conversation as resolved.

case_assignment.save

redirect_to volunteer_case_assignments_path(volunteer)
end

def destroy
volunteer = User.find(params[:volunteer_id])
case_assignment = volunteer.case_assignments.find(params[:id])

case_assignment.destroy
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.

Eventually we will want to use case_assignment.is_active instead of .destroy so we can view previously-assigned volunteers but because case_contact has case_id (so case contacts never vanish) it's not needed for MVP


redirect_to volunteer_case_assignments_path(volunteer)
end

private

def case_assignment_params
params.require(:case_assignment).permit(:casa_case_id)
end
end
10 changes: 4 additions & 6 deletions app/controllers/volunteers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
class VolunteersController < ApplicationController
before_action :authenticate_user!

def index
@case_contact = CaseContact.new
end
before_action :must_be_admin

def new
@volunteer = User.new(role: :volunteer)
Expand All @@ -19,7 +15,9 @@ def create
end
end

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

private

Expand Down
2 changes: 1 addition & 1 deletion app/models/case_contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CaseContact < ApplicationRecord
enum contact_type: CONTACT_TYPES.zip(CONTACT_TYPES).to_h

def humanized_type
"#{contact_type.humanize.titleize}"
contact_type.humanize.titleize.to_s
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.

:)

end

# Generate array of attributes for All Case Contacts report
Expand Down
48 changes: 48 additions & 0 deletions app/views/case_assignments/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<%= link_to 'Back', root_path %>

<h1>Edit Volunteer Assignments for <%= @volunteer.name %></h1>

<br>

<% if @volunteer.casa_cases %>
<table class='table case-list' id='casa_cases'>
<thead>
<tr>
<th>Case Number</th>
<th>Transition Aged Youth</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<% @volunteer.case_assignments.each do |assignment| %>
<tr>
<td><%= assignment.casa_case.case_number %></td>
<td><%= assignment.casa_case.transition_aged_youth %></td>
<td><%= button_to 'Unassign Case', volunteer_case_assignment_path(@volunteer, assignment), method: :delete, class: "btn btn-danger" %></td>
</tr>
<% end %>
</tbody>
</table>
<% end %>

<br>

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

<%= form_for CaseAssignment.new, url: volunteer_case_assignments_path do |form| %>

<div class='form-group'>
<label for="case_assignment_casa_case_id">Select a Case</label>
<select 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 %>
</div>
</div>
2 changes: 1 addition & 1 deletion app/views/dashboard/_admin_dashboard.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<td><%= volunteer&.most_recent_contact&.occurred_at&.strftime('%B %e, %Y') %></td>
<td><%= volunteer&.recent_contacts_made %></td>
<td>
<%= link_to 'Edit', edit_volunteer_path(volunteer) %>
<%= link_to 'Edit', volunteer_case_assignments_path(volunteer) %>
</td>
</tr>
<% end %>
Expand Down
38 changes: 19 additions & 19 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<title>PG CASA</title>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= render 'shared/favicons' %>
<head>
<title>PG CASA</title>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= render 'shared/favicons' %>

<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>

<body>
<%= render 'layouts/header' %>
<body>
<%= render 'layouts/header' %>

<div class="container">
<% if notice %>
<p class="notice alert alert-success"><%= notice %></p>
<% elsif alert %>
<p class="notice alert alert-danger"><%= alert %></p>
<% end %>
<div class="container">
<% if notice %>
<p class="notice alert alert-success"><%= notice %></p>
<% elsif alert %>
<p class="notice alert alert-danger"><%= alert %></p>
<% end %>

<%= yield %>
</div>
</body>
<%= yield %>
</div>
</body>
</html>
4 changes: 2 additions & 2 deletions app/views/volunteers/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<h1>Editing Volunteer</h1>

<%= link_to 'Back', root_path %>

<h1>Editing Volunteer</h1>
5 changes: 4 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
resources :casa_cases
resources :case_contacts
resources :casa_orgs
resources :volunteers, only: %i[new edit create]
resources :reports, only: %i[show index]

resources :volunteers, only: %i[new edit create] do
resources :case_assignments, only: %i[create destroy index]
end

resources :users, only: [] do
collection do
get :edit
Expand Down
2 changes: 1 addition & 1 deletion spec/features/admin_views_dashboard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
click_on 'Edit'
end

expect(page).to have_text('Editing Volunteer')
expect(page).to have_text('Edit Volunteer Assignments')
end

it 'can go to the new volunteer page' do
Expand Down
62 changes: 62 additions & 0 deletions spec/requests/case_assignments_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
require 'rails_helper'

RSpec.describe '/case_assignments', type: :request do
describe 'GET /index' do
context 'with a volunteer signed in' do
it 'redirects back to dashboard with an unauthorized notice' do
volunteer = create(:user, :volunteer)
sign_in volunteer

get volunteer_case_assignments_path(volunteer)

expect(response).to redirect_to(root_path)
end
end

context 'with an admin signed in' do
it 'renders a successful response' do
admin = create(:user, :casa_admin)
volunteer = create(:user, :volunteer)
sign_in admin

get volunteer_case_assignments_path(volunteer)

expect(response).to be_successful
end
end
end

describe 'POST /create' do
it 'creates a new case assignment' do
admin = create(:user, :casa_admin)
volunteer = create(:user, :volunteer)
casa_case = create(:casa_case)

sign_in admin

expect do
post volunteer_case_assignments_url(volunteer),
params: { case_assignment: { casa_case_id: casa_case.id } }
end.to change(volunteer.casa_cases, :count).by(1)

expect(response).to redirect_to volunteer_case_assignments_path(volunteer)
end
end

describe 'DELETE /destroy' do
it 'destroys the case assignment' do
admin = create(:user, :casa_admin)
volunteer = create(:user, :volunteer)
casa_case = create(:casa_case)
assignment = create(:case_assignment, volunteer: volunteer, casa_case: casa_case)

sign_in admin

expect do
delete volunteer_case_assignment_url(volunteer, assignment)
end.to change(volunteer.casa_cases, :count).by(-1)

expect(response).to redirect_to volunteer_case_assignments_path(volunteer)
end
end
end