2018-07-24 06:00:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-18 12:52:35 -04:00
|
|
|
class GroupMemberPolicy < BasePolicy
|
2017-04-06 17:06:42 -04:00
|
|
|
delegate :group
|
2016-08-18 12:52:35 -04:00
|
|
|
|
2017-04-06 17:06:42 -04:00
|
|
|
with_scope :subject
|
2021-04-15 05:09:03 -04:00
|
|
|
condition(:last_owner) { @subject.group.member_last_owner?(@subject) || @subject.group.member_last_blocked_owner?(@subject) }
|
2022-01-17 07:17:11 -05:00
|
|
|
condition(:project_bot) { @subject.user&.project_bot? && @subject.group.member?(@subject.user) }
|
2016-08-18 12:52:35 -04:00
|
|
|
|
2017-04-06 17:06:42 -04:00
|
|
|
desc "Membership is users' own"
|
|
|
|
with_score 0
|
|
|
|
condition(:is_target_user) { @user && @subject.user_id == @user.id }
|
2016-08-18 12:52:35 -04:00
|
|
|
|
2021-01-18 04:11:05 -05:00
|
|
|
rule { anonymous }.policy do
|
|
|
|
prevent :update_group_member
|
|
|
|
prevent :destroy_group_member
|
|
|
|
end
|
|
|
|
|
2020-11-12 13:09:26 -05:00
|
|
|
rule { last_owner }.policy do
|
|
|
|
prevent :update_group_member
|
|
|
|
prevent :destroy_group_member
|
|
|
|
end
|
2016-08-18 12:52:35 -04:00
|
|
|
|
2022-01-17 07:17:11 -05:00
|
|
|
rule { ~project_bot & can?(:admin_group_member) }.policy do
|
2017-04-06 17:06:42 -04:00
|
|
|
enable :update_group_member
|
|
|
|
enable :destroy_group_member
|
2016-12-13 08:51:09 -05:00
|
|
|
end
|
|
|
|
|
2022-01-17 07:17:11 -05:00
|
|
|
rule { project_bot & can?(:admin_group_member) }.enable :destroy_project_bot_member
|
|
|
|
|
2017-04-06 17:06:42 -04:00
|
|
|
rule { is_target_user }.policy do
|
|
|
|
enable :destroy_group_member
|
2016-08-18 12:52:35 -04:00
|
|
|
end
|
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
GroupMemberPolicy.prepend_mod_with('GroupMemberPolicy')
|