Class: Members::UnassignIssuablesService

Inherits:
Object
  • Object
show all
Defined in:
app/services/members/unassign_issuables_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, entity) ⇒ UnassignIssuablesService

Returns a new instance of UnassignIssuablesService.


7
8
9
10
# File 'app/services/members/unassign_issuables_service.rb', line 7

def initialize(user, entity)
  @user = user
  @entity = entity
end

Instance Attribute Details

#entityObject (readonly)

Returns the value of attribute entity.


5
6
7
# File 'app/services/members/unassign_issuables_service.rb', line 5

def entity
  @entity
end

#userObject (readonly)

Returns the value of attribute user.


5
6
7
# File 'app/services/members/unassign_issuables_service.rb', line 5

def user
  @user
end

Instance Method Details

#executeObject


12
13
14
15
16
17
18
19
20
21
# File 'app/services/members/unassign_issuables_service.rb', line 12

def execute
  return unless entity && user

  project_ids = entity.is_a?(Group) ? entity.all_projects.select(:id) : [entity.id]

  user.issue_assignees.on_issues(Issue.in_projects(project_ids).select(:id)).delete_all
  user.merge_request_assignees.in_projects(project_ids).delete_all

  user.invalidate_cache_counts
end