Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow supervisors to see *all* volunteers (including those without learning hours) #6066

Closed
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions app/models/supervisor_volunteer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ class SupervisorVolunteer < ApplicationRecord
validates :volunteer_id, uniqueness: {scope: :is_active}, if: :is_active?
validate :ensure_supervisor_and_volunteer_belong_to_same_casa_org, if: -> { supervisor.present? && volunteer.present? }

scope :supervisor_volunteers_learning_hours, ->(supervisor_id) {
lenikadali marked this conversation as resolved.
Show resolved Hide resolved
left_outer_joins(volunteer: [{supervisor: :learning_hours}])
.where(supervisor_volunteers: {supervisor_id: supervisor_id})
.select("users.id as user_id, users.display_name, SUM(learning_hours.duration_minutes + learning_hours.duration_hours * 60) AS total_time_spent")
.group("users.display_name, users.id")
.order("users.display_name")
}

private

def ensure_supervisor_and_volunteer_belong_to_same_casa_org
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<!-- end table row-->
</thead>
<tbody>
<% @learning_hours.each do |learning_hour| %>
<% supervisor_volunteers.each do |learning_hour| %>
<tr>
<td><%= link_to(learning_hour.display_name, learning_hours_volunteer_path(learning_hour.user_id)) %></td>
<td><%= format_time(learning_hour.total_time_spent) %></td>
Expand Down
2 changes: 1 addition & 1 deletion app/views/learning_hours/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% if current_user.volunteer? %>
<%= render "volunteer_learning_hours", learning_hours: @learning_hours %>
<% else %>
<%= render "supervisor_admin_learning_hours" %>
<%= render "supervisor_admin_learning_hours" supervisor_volunteer: supervisor_volunteer %>
<% end %>
Loading