Skip to content

Commit

Permalink
separate checking for onwnership and permissions into separate methods
Browse files Browse the repository at this point in the history
  • Loading branch information
colby-swandale committed Sep 6, 2024
1 parent bf2d936 commit a4b0999
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 5 additions & 1 deletion app/policies/application_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ def current_user?(record_user)
user && user == record_user
end

def rubygem_owned_by?(user, minimum_required_role: :maintainer)
def rubygem_owned_by?(user)
rubygem.owned_by?(user) || deny(t(:forbidden))
end

def rubygem_owned_by_with_role?(user, minimum_required_role:)
rubygem.owned_by_with_role?(user, minimum_required_role) || deny(t(:forbidden))
end

Expand Down
8 changes: 4 additions & 4 deletions app/policies/rubygem_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ def close_ownership_requests?
end

def show_unconfirmed_ownerships?
rubygem_owned_by?(user, minimum_required_role: :owner)
rubygem_owned_by_with_role?(user, minimum_required_role: :owner)
end

def add_owner?
rubygem_owned_by?(user, minimum_required_role: :owner)
rubygem_owned_by_with_role?(user, minimum_required_role: :owner)
end

def update_owner?
rubygem_owned_by?(user, minimum_required_role: :owner)
rubygem_owned_by_with_role?(user, minimum_required_role: :owner)
end

def remove_owner?
rubygem_owned_by?(user, minimum_required_role: :owner)
rubygem_owned_by_with_role?(user, minimum_required_role: :owner)
end
end

0 comments on commit a4b0999

Please sign in to comment.