summaryrefslogtreecommitdiff
path: root/app/policies/project_member_policy.rb
blob: 9aedb620be96a6f0c611e186e3f8e19b9ef6a725 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class ProjectMemberPolicy < BasePolicy
  delegate { @subject.project }

  condition(:target_is_owner, scope: :subject) { @subject.user == @subject.project.owner }
  condition(:target_is_self) { @user && @subject.user == @user }

  rule { anonymous }.prevent_all
  rule { target_is_owner }.prevent_all

  rule { can?(:admin_project_member) }.policy do
    enable :update_project_member
    enable :destroy_project_member
  end

  rule { target_is_self }.enable :destroy_project_member
end