Extract private method in user role policy

This commit is contained in:
Matt Jankowski 2024-10-15 12:39:02 -04:00
parent 63b8d7dd23
commit 5c30c34a4c

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