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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

78 lines
2.4 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2018-03-27 19:54:05 +05:30
module Members
class BaseService < ::BaseService
# current_user - The user that performs the action
# params - A hash of parameters
def initialize(current_user = nil, params = {})
@current_user = current_user
@params = params
2020-10-04 03:57:07 +05:30
# could be a string, force to an integer, part of fix
# https://gitlab.com/gitlab-org/gitlab/-/issues/219496
# Allow the ArgumentError to be raised if it can't be converted to an integer.
@params[:access_level] = Integer(@params[:access_level]) if @params[:access_level]
2018-03-27 19:54:05 +05:30
end
def after_execute(args)
2018-12-13 13:39:08 +05:30
# overridden in EE::Members modules
2018-03-27 19:54:05 +05:30
end
private
def update_member_permission(member)
case member
when GroupMember
:update_group_member
when ProjectMember
:update_project_member
else
raise "Unknown member type: #{member}!"
end
end
def override_member_permission(member)
case member
when GroupMember
:override_group_member
when ProjectMember
:override_project_member
else
raise "Unknown member type: #{member}!"
end
end
def action_member_permission(action, member)
case action
when :update
update_member_permission(member)
when :override
override_member_permission(member)
else
raise "Unknown action '#{action}' on #{member}!"
end
end
2019-01-03 12:48:30 +05:30
def enqueue_delete_todos(member)
type = member.is_a?(GroupMember) ? 'Group' : 'Project'
# don't enqueue immediately to prevent todos removal in case of a mistake
2019-10-12 21:52:04 +05:30
member.run_after_commit_or_now do
TodosDestroyer::EntityLeaveWorker.perform_in(Todo::WAIT_FOR_DELETE, member.user_id, member.source_id, type)
end
2019-01-03 12:48:30 +05:30
end
2022-07-23 23:45:48 +05:30
def cannot_assign_owner_responsibilities_to_member_in_project?(member)
# The purpose of this check is -
# We can have direct members who are "Owners" in a project going forward and
# we do not want Maintainers of the project updating/adding/removing other "Owners"
# within the project.
# Only OWNERs in a project should be able to manage any action around OWNERship in that project.
member.is_a?(ProjectMember) &&
!can?(current_user, :manage_owners, member.source)
end
alias_method :cannot_revoke_owner_responsibilities_from_member_in_project?,
:cannot_assign_owner_responsibilities_to_member_in_project?
2018-03-27 19:54:05 +05:30
end
end