Resolve source CE referral on enrollment - #5999
Conversation
| summary_field :created_at, GraphQL::Types::ISO8601DateTime, null: false | ||
| summary_field :source_enrollment_id, ID, null: false | ||
| # source_project_name is resolved separately from source_enrollment as a summary field to minimize data exposure | ||
| summary_field :source_project_name, String, null: false |
There was a problem hiding this comment.
I'm proposing to add source_project_name as a new summary-level field, even though it is also resolvable through the sourceEnrollment field. As we currently have it set up, sourceEnrollment is not a summary-level field, so it's only resolvable by those who can view the referral. I thought about elevating it to a summary field, but it contains a lot of data (like assessments and household members) that are not needed to solve the current requirement.
There was a problem hiding this comment.
I think this makes sense! I needs to be nullable though, because source_enrollment_id is not required on the referral table. (source_enrollment_id graphql field also should be nullable, which I incorporated into wip #6000 , but you can make the change here too).
| summary_field :custom_status, HmisSchema::CeCustomReferralStatus, null: true | ||
| summary_field :client_id, ID, null: false | ||
| summary_field :client_name, String, null: true, description: 'The name of the referred client. Always available to those who can view the full referral, even without full client record access.' | ||
| # Special case: Client is a "summary field" because it doesn't require referral visibility, but resolving it does require permission to view the client record. |
There was a problem hiding this comment.
Removing unrelated - I think this comment was outdated, since client is not a summary-level field.
| # All referrals where this enrollment is the source enrollment. NOT only 'direct' referrals | ||
| has_many :outgoing_ce_referrals, class_name: 'Hmis::Ce::Referral', foreign_key: :source_enrollment_id | ||
| # The referral that created this enrollment (if any) | ||
| has_one :source_ce_referral, class_name: 'Hmis::Ce::Referral', foreign_key: :target_enrollment_id |
There was a problem hiding this comment.
Thanks for adding this. This is a bit unrelated, but we have the same "dangling reference" problem as we do with the outgoing_ce_referrals association. If the target Enrollment is destroyed, the source enrollment will continue to have a target_enrollment_id that doesn't resolve to anything.
I will address this in #6000 since you're just adding the reference and not changing the default behavior here, it will need more tests etc. Just a note to self! I think we want dependent: :nullify In other words if the Target Enrollment is deleted, the referral should remain but have the target_enrollment_id nullified.
There was a problem hiding this comment.
I agree, that makes sense!
| @@ -39,7 +39,13 @@ def can_view? | |||
| def can_view_summary? | |||
| return false unless Hmis::Ce.configuration.enabled? | |||
|
|
|||
There was a problem hiding this comment.
Can we add a return true if can_view?
It doesn't feel logical to have scenarios where the use can view the full referral, but they can't view the summary of it.
| # Users who can view the target enrollment. Bakes in the assumption that the target enrollment is in the referral's project. | ||
| return true if referral.target_enrollment_id.present? && project_permissions.include?(:can_view_enrollment_details) |
There was a problem hiding this comment.
If we had an Enrollment Policy, it would be nice if we could check against that here. Maybe we can add a TODO referencing https://github.com/open-path/Green-River/issues/8549 for that.
Full Enrollment visibility currently requires both can_view_enrollment_details and can_view_project so we should check that both of those are included in project_permissions to be comprehensive. (This is the thing that would be ideal to encapsulate in the policy!)
There was a problem hiding this comment.
Cool thanks for tracking down the open ticket! I'll add a todo and also add an extra check that the user can_view_project. b855f95
| end | ||
| end | ||
|
|
||
| context 'when referral has a target enrollment' do |
There was a problem hiding this comment.
Thanks for these tests! I think we are missing coverage for the case where the referral doesn't have a target enrollment. We should test that because I think we are wanting to limit summary visibility to only referrals that have resulted in an enrollment at the target project.
There was a problem hiding this comment.
Oh yup makes sense, added test coverage for that 77b4f03
There was a problem hiding this comment.
I was beginning to type up the question, Do you think we need coverage for the case where the target enrollment ID points at an enrollment that isn't in the target project? (referring back to my comment here)
But, thinking about this more, that really sounds like it should be a validation on the referral model. I'm taking a stab at that, but wanted to split it out into a separate diff, in case it causes a bunch of tests to fail, so it doesn't block this work. #6007
Co-authored-by: Gig <gig@greenriver.org>
Merging this PR
Description
can_view_summary?referral policy for users who can view the target enrollment, even if they can't necessarily view details of the referral. (This policy was originally designed to display some limited data about the referral to a user who can send direct referrals from the source project, but can't view referrals in the target project.)CeReferralschema object and use itsaccessfield to determine whether to link to the referral from the enrollment.CeReferralthat this would give the user access to, and they all seem okay to expose, especially since under this new use case, the user already can view enrollments in the target project.sourceCeReferralId,sourceCeReferralProjectName, etc.) directly on the enrollment.source_ce_referralassoc on enrollment and resolve it on the graphql typeFrontend PR: greenriver/hmis-frontend#1319
Type of change
New feature
Checklist before requesting review
//: # NOTE: system tests may fail if there is no branch on the hmis-frontend that matches the Source or Target branch of this PR. This is expected