2018-07-17 16:50:37 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-10-11 14:47:08 +00:00
|
|
|
module Members
|
|
|
|
class BaseService < ::BaseService
|
|
|
|
# current_user - The user that performs the action
|
|
|
|
# params - A hash of parameters
|
2018-02-16 14:10:22 +00:00
|
|
|
def initialize(current_user = nil, params = {})
|
2017-10-11 14:47:08 +00:00
|
|
|
@current_user = current_user
|
|
|
|
@params = params
|
|
|
|
end
|
|
|
|
|
2018-02-16 14:10:22 +00:00
|
|
|
def after_execute(args)
|
2018-10-30 10:53:01 +00:00
|
|
|
# overridden in EE::Members modules
|
2017-10-11 14:47:08 +00:00
|
|
|
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
|
2018-12-11 18:15:10 +00:00
|
|
|
|
|
|
|
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-08-07 13:53:57 +00:00
|
|
|
member.run_after_commit_or_now do
|
|
|
|
TodosDestroyer::EntityLeaveWorker.perform_in(Todo::WAIT_FOR_DELETE, member.user_id, member.source_id, type)
|
|
|
|
end
|
2018-12-11 18:15:10 +00:00
|
|
|
end
|
2017-10-11 14:47:08 +00:00
|
|
|
end
|
|
|
|
end
|