Class: Todos::Destroy::EntityLeaveService

Inherits:
BaseService
  • Object
show all
Extended by:
Gitlab::Utils::Override
Defined in:
app/services/todos/destroy/entity_leave_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::Utils::Override

extended, extensions, included, method_added, override, prepended, queue_verification, verify!

Constructor Details

#initialize(user_id, entity_id, entity_type) ⇒ EntityLeaveService

Returns a new instance of EntityLeaveService.


10
11
12
13
14
15
16
17
# File 'app/services/todos/destroy/entity_leave_service.rb', line 10

def initialize(user_id, entity_id, entity_type)
  unless %w(Group Project).include?(entity_type)
    raise ArgumentError, "#{entity_type} is not an entity user can leave"
  end

  @user = UserFinder.new(user_id).find_by_id
  @entity = entity_type.constantize.find_by(id: entity_id) # rubocop: disable CodeReuse/ActiveRecord
end

Instance Attribute Details

#entityObject (readonly)

Returns the value of attribute entity.


8
9
10
# File 'app/services/todos/destroy/entity_leave_service.rb', line 8

def entity
  @entity
end

#userObject (readonly)

Returns the value of attribute user.


8
9
10
# File 'app/services/todos/destroy/entity_leave_service.rb', line 8

def user
  @user
end

Instance Method Details

#executeObject


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/services/todos/destroy/entity_leave_service.rb', line 19

def execute
  return unless entity && user

  # if at least reporter, all entities including confidential issues can be accessed
  return if user_has_reporter_access?

  remove_confidential_resource_todos
  remove_group_todos

  if entity.private?
    remove_project_todos
  else
    enqueue_private_features_worker
  end
end