Skip to content

Commit

Permalink
Updated sample policy to only set the effective level once.
Browse files Browse the repository at this point in the history
  • Loading branch information
deepsidhu85 committed Dec 19, 2024
1 parent eb78da3 commit 928be02
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions app/policies/sample_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@

# Policy samples authorization
class SamplePolicy < ApplicationPolicy
def destroy_attachment? # rubocop:disable Metrics/AbcSize
return true if record.project.namespace.parent.user_namespace? && record.project.namespace.parent.owner == user
return true if Member.namespace_owners_include_user?(user, record.project.namespace) == true
def effective_access_level # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize
return unless record.instance_of?(Sample)

if record.project&.namespace&.parent&.user_namespace? && record.project&.namespace&.parent&.owner == user
@access_level = Member::AccessLevel::OWNER
end

@access_level ||= Member.effective_access_level(record.project.namespace, user)
@access_level
end

def destroy_attachment?
# return true if record.project.namespace.parent.user_namespace? && record.project.namespace.parent.owner == user
# return true if Member.namespace_owners_include_user?(user, record.project.namespace) == true
return true if effective_access_level == Member::AccessLevel::OWNER

details[:name] = record.name
false
Expand Down

0 comments on commit 928be02

Please sign in to comment.