Skip to content

Commit

Permalink
Merge pull request #1295 from sparc-request/sj-admin_rights_bug_fix
Browse files Browse the repository at this point in the history
SJ - Fix for admin access rights [#156556008]
  • Loading branch information
Stuart-Johnson committed Apr 9, 2018
2 parents ca3eef1 + 4c40a1b commit e9efd32
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions app/models/protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,24 +235,27 @@ def unique_rm_id_to_protocol
scope :for_admin, -> (identity_id) {
# returns protocols with ssrs in orgs authorized for identity
return nil if identity_id == '0'
service_provider_ssrs = SubServiceRequest.where.not(status: 'first_draft').where(organization_id: Organization.authorized_for_service_provider(identity_id))

if SuperUser.where(identity_id: identity_id).any?
self.for_super_user(identity_id)
self.for_super_user(identity_id, service_provider_ssrs)
else
ssrs = SubServiceRequest.where.not(status: 'first_draft').where(organization_id: Organization.authorized_for_service_provider(identity_id))
joins(:sub_service_requests).merge(ssrs).distinct
joins(:sub_service_requests).merge(service_provider_ssrs).distinct
end
}

scope :for_super_user, -> (identity_id) {
scope :for_super_user, -> (identity_id, service_provider_ssrs = nil) {
# returns protocols with ssrs in orgs authorized for identity
ssrs = SubServiceRequest.where.not(status: 'first_draft').where(organization_id: Organization.authorized_for_super_user(identity_id))

empty_protocol_ids = includes(:sub_service_requests).where(sub_service_requests: { id: nil }).ids
protocol_ids = ssrs.distinct.pluck(:protocol_id)
all_protocol_ids = (protocol_ids + empty_protocol_ids).uniq
all_protocol_ids = protocol_ids + empty_protocol_ids
if service_provider_ssrs
all_protocol_ids << service_provider_ssrs.distinct.pluck(:protocol_id)
end

where(id: all_protocol_ids)
where(id: all_protocol_ids.uniq)
}

scope :show_archived, -> (boolean) {
Expand Down

0 comments on commit e9efd32

Please sign in to comment.