Skip to content

Commit

Permalink
Filter project enrollments and households by assigned staff (#4582)
Browse files Browse the repository at this point in the history
* Add staff assignment DB tables and begin schema

* Add staff assignment pick lists

* Add mutations and spec

* Add arg to query for historical assignments

* Pairing and PR feedback

* Remove fk constraint on staff assignment user

* PR response for pick list options

* remove wip comment

* remove comment

* Fix failing tests

* Make duplicate assignment a user-resolvable error

* Attach error to user_id, not base

* quick fix to permission_for scope to cut dupes

* Improvements per frontend

* Remove comment

* Use viewable_by and don't preload in assign_staff

Co-authored-by: Theron Toomey <ttoomey@greenriver.org>

* Lock to avoid race condition; call create! instead of new

Co-authored-by: Theron Toomey <ttoomey@greenriver.org>

* Move return of assignment inside lock block

* Mirror user scope in assignment to user picklist

Co-authored-by: Theron Toomey <ttoomey@greenriver.org>

* Fix test by adding access control

* Use input type for staff assignment mutation

* Improve staff assignment table indices

Co-authored-by: Theron Toomey <ttoomey@greenriver.org>

* Alphabetize staff user picklist by last,first

* Simplify unassignment to use find instead of find_by

* Use sequence in staff assignment factory

Co-authored-by: Theron Toomey <ttoomey@greenriver.org>

* Use id rather than deleted_at as tiebreaker

Co-authored-by: Theron Toomey <ttoomey@greenriver.org>

* Fix tests

* standardize on current_permission

Co-authored-by: Theron Toomey <ttoomey@greenriver.org>

* Sketch contains_with_inherited scope

* Fix permissions

* Add query for staff assignments by user

* Remove extraneous ??

* Filter project enrollments and households by assigned staff

* Remove unhelpful use of data loader

Co-authored-by: Theron Toomey <ttoomey@greenriver.org>

* Use composition for arel helper

* Fix bad merge

* staff assignments performance improvement

skip join to households as it's not performant right now

* Add back n+1 comment still relevant

---------

Co-authored-by: Theron Toomey <ttoomey@greenriver.org>
  • Loading branch information
martha and ttoomey authored Aug 1, 2024
1 parent abe9da2 commit 4b5e75c
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions drivers/hmis/app/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3555,6 +3555,7 @@ input EnrollmentsForClientFilterOptions {
}

input EnrollmentsForProjectFilterOptions {
assignedStaff: ID
bedNightOnDate: ISO8601Date
householdTasks: [EnrollmentFilterOptionHouseholdTask!]
openOnDate: ISO8601Date
Expand Down Expand Up @@ -5046,6 +5047,7 @@ type HouseholdClient {
}

input HouseholdFilterOptions {
assignedStaff: ID
hohAgeRange: AgeRange
openOnDate: ISO8601Date
searchTerm: String
Expand Down
2 changes: 1 addition & 1 deletion drivers/hmis/app/graphql/types/hmis_schema/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def self.authorized?(object, ctx)
argument :open_on_date, GraphQL::Types::ISO8601Date, required: true
end

enrollments_field filter_args: { omit: [:search_term, :bed_night_on_date], type_name: 'EnrollmentsForClient' } do
enrollments_field filter_args: { omit: [:search_term, :bed_night_on_date, :assigned_staff], type_name: 'EnrollmentsForClient' } do
# Option to include enrollments that the user has "limited" access to
argument :include_enrollments_with_limited_access, Boolean, required: false
end
Expand Down
1 change: 1 addition & 0 deletions drivers/hmis/app/graphql/types/hmis_schema/enrollment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def self.summary_field(name, type = nil, **kwargs)
arg :project_type, [Types::HmisSchema::Enums::ProjectType]
arg :household_tasks, [HmisSchema::Enums::EnrollmentFilterOptionHouseholdTask]
arg :search_term, String
arg :assigned_staff, ID
end

description 'HUD Enrollment'
Expand Down
1 change: 1 addition & 0 deletions drivers/hmis/app/graphql/types/hmis_schema/household.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class HmisSchema::Household < Types::BaseObject
arg :open_on_date, GraphQL::Types::ISO8601Date
arg :hoh_age_range, HmisSchema::Enums::AgeRange
arg :search_term, String
arg :assigned_staff, ID
end

def household_clients
Expand Down
8 changes: 8 additions & 0 deletions drivers/hmis/app/models/hmis/filter/enrollment_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def filter_scope(scope)
yield_self(&method(:with_project_types)).
yield_self(&method(:with_search_term)).
yield_self(&method(:with_household_tasks)).
yield_self(&method(:with_assigned_staff)).
yield_self(&method(:clean_scope))
end

Expand Down Expand Up @@ -133,4 +134,11 @@ def with_household_tasks(scope)
scope.where(id: enrollments_with_annual_due.pluck(:id))
end
end

def with_assigned_staff(scope)
with_filter(scope, :assigned_staff) do
sa_t = Hmis::StaffAssignment.arel_table
scope.joins(household: :staff_assignments).where(sa_t[:user_id].eq(input.assigned_staff))
end
end
end
10 changes: 9 additions & 1 deletion drivers/hmis/app/models/hmis/filter/household_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ def filter_scope(scope)
yield_self(&method(:with_statuses)).
yield_self(&method(:with_open_on_date)).
yield_self(&method(:with_hoh_age_range)).
yield_self(&method(:with_search_term))
yield_self(&method(:with_search_term)).
yield_self(&method(:with_assigned_staff))
end

protected
Expand Down Expand Up @@ -74,4 +75,11 @@ def with_hoh_age_range(scope)
)
end
end

def with_assigned_staff(scope)
with_filter(scope, :assigned_staff) do
sa_t = Hmis::StaffAssignment.arel_table
scope.joins(:staff_assignments).where(sa_t[:user_id].eq(input.assigned_staff))
end
end
end

0 comments on commit 4b5e75c

Please sign in to comment.