Class: DeleteUserService

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current_user) ⇒ DeleteUserService

Returns a new instance of DeleteUserService


4
5
6
# File 'app/services/delete_user_service.rb', line 4

def initialize(current_user)
  @current_user = current_user
end

Instance Attribute Details

#current_userObject

Returns the value of attribute current_user


2
3
4
# File 'app/services/delete_user_service.rb', line 2

def current_user
  @current_user
end

Instance Method Details

#execute(user, options = {}) ⇒ Object


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/services/delete_user_service.rb', line 8

def execute(user, options = {})
  if !options[:delete_solo_owned_groups] && user.solo_owned_groups.present?
    user.errors[:base] << 'You must transfer ownership or delete groups before you can remove user'
    return user
  end

  user.solo_owned_groups.each do |group|
    DestroyGroupService.new(group, current_user).execute
  end

  user.personal_projects.each do |project|
    # Skip repository removal because we remove directory with namespace
    # that contain all this repositories
    ::Projects::DestroyService.new(project, current_user, skip_repo: true).pending_delete!
  end

  user.destroy
end