Add self_editing? method to user role policy (#33476)

This commit is contained in:
Matt Jankowski 2025-01-07 02:50:19 -05:00 committed by GitHub
parent dd937e115a
commit edf62d4fe3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -10,10 +10,16 @@ class UserRolePolicy < ApplicationPolicy
end
def update?
role.can?(:manage_roles) && (role.overrides?(record) || role.id == record.id)
role.can?(:manage_roles) && (role.overrides?(record) || self_editing?)
end
def destroy?
!record.everyone? && role.can?(:manage_roles) && role.overrides?(record) && role.id != record.id
!record.everyone? && role.can?(:manage_roles) && role.overrides?(record) && !self_editing?
end
private
def self_editing?
role.id == record.id
end
end