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
|
|
|
|
2022-04-06 08:08:29 -04:00
|
|
|
condition(:target_is_holder_of_the_personal_namespace, scope: :subject) do
|
|
|
|
@subject.project.personal_namespace_holder?(@subject.user)
|
|
|
|
end
|
|
|
|
|
2017-04-06 17:06:42 -04:00
|
|
|
condition(:target_is_self) { @user && @subject.user == @user }
|
2020-07-14 20:09:23 -04:00
|
|
|
condition(:project_bot) { @subject.user&.project_bot? }
|
2016-08-16 19:46:35 -04:00
|
|
|
|
2017-04-06 17:06:42 -04:00
|
|
|
rule { anonymous }.prevent_all
|
2021-04-22 08:09:49 -04:00
|
|
|
|
2022-04-06 08:08:29 -04:00
|
|
|
rule { target_is_holder_of_the_personal_namespace }.policy do
|
2021-04-22 08:09:49 -04:00
|
|
|
prevent :update_project_member
|
|
|
|
prevent :destroy_project_member
|
|
|
|
end
|
2016-08-16 19:46:35 -04:00
|
|
|
|
2020-07-14 20:09:23 -04:00
|
|
|
rule { ~project_bot & can?(:admin_project_member) }.policy do
|
2017-04-06 17:06:42 -04:00
|
|
|
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
|
|
|
|
2020-07-14 20:09:23 -04:00
|
|
|
rule { project_bot & can?(:admin_project_member) }.enable :destroy_project_bot_member
|
|
|
|
|
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
|