2018-07-24 06:00:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-16 19:46:35 -04:00
|
|
|
class ProjectMemberPolicy < BasePolicy
|
2017-04-06 17:06:42 -04:00
|
|
|
delegate { @subject.project }
|
2016-08-16 19:46:35 -04:00
|
|
|
|
2017-04-06 17:06:42 -04:00
|
|
|
condition(:target_is_owner, scope: :subject) { @subject.user == @subject.project.owner }
|
|
|
|
condition(:target_is_self) { @user && @subject.user == @user }
|
2016-08-16 19:46:35 -04:00
|
|
|
|
2017-04-06 17:06:42 -04:00
|
|
|
rule { anonymous }.prevent_all
|
|
|
|
rule { target_is_owner }.prevent_all
|
2016-08-16 19:46:35 -04:00
|
|
|
|
2017-04-06 17:06:42 -04:00
|
|
|
rule { can?(:admin_project_member) }.policy do
|
|
|
|
enable :update_project_member
|
|
|
|
enable :destroy_project_member
|
2016-08-16 19:46:35 -04:00
|
|
|
end
|
2017-04-06 17:06:42 -04:00
|
|
|
|
|
|
|
rule { target_is_self }.enable :destroy_project_member
|
2016-08-16 19:46:35 -04:00
|
|
|
end
|