debian-mirror-gitlab/app/services/members/destroy_service.rb

39 lines
943 B
Ruby
Raw Normal View History

2016-08-24 12:49:21 +05:30
module Members
2018-03-27 19:54:05 +05:30
class DestroyService < Members::BaseService
def execute(member, skip_authorization: false)
raise Gitlab::Access::AccessDeniedError unless skip_authorization || can_destroy_member?(member)
2016-08-24 12:49:21 +05:30
2018-03-27 19:54:05 +05:30
return member if member.is_a?(GroupMember) && member.source.last_owner?(member.user)
2016-11-03 12:29:30 +05:30
2018-03-27 19:54:05 +05:30
member.destroy
2016-11-03 12:29:30 +05:30
2018-03-27 19:54:05 +05:30
member.user&.invalidate_cache_counts
2016-11-03 12:29:30 +05:30
2018-03-27 19:54:05 +05:30
if member.request? && member.user != current_user
notification_service.decline_access_request(member)
end
2016-11-03 12:29:30 +05:30
2018-03-27 19:54:05 +05:30
after_execute(member: member)
2016-11-03 12:29:30 +05:30
2018-03-27 19:54:05 +05:30
member
2016-08-24 12:49:21 +05:30
end
2016-11-03 12:29:30 +05:30
private
def can_destroy_member?(member)
2018-03-27 19:54:05 +05:30
can?(current_user, destroy_member_permission(member), member)
2018-03-17 18:26:18 +05:30
end
def destroy_member_permission(member)
case member
when GroupMember
:destroy_group_member
when ProjectMember
:destroy_project_member
2018-03-27 19:54:05 +05:30
else
raise "Unknown member type: #{member}!"
2018-03-17 18:26:18 +05:30
end
2016-11-03 12:29:30 +05:30
end
2016-08-24 12:49:21 +05:30
end
end