Class: Namespaces::Groups::UnarchiveService

Inherits:
Groups::BaseService show all
Includes:
ArchiveEvents
Defined in:
app/services/namespaces/groups/unarchive_service.rb

Constant Summary collapse

NotAuthorizedError =
ServiceResponse.error(
  message: "You don't have permissions to unarchive this group!"
)
AlreadyUnarchivedError =
ServiceResponse.error(
  message: 'Group is already unarchived!'
)
AncestorArchivedError =
ServiceResponse.error(
  message: 'Cannot unarchive group since one of the ancestor groups is archived!'
)
Error =
Class.new(StandardError)
UpdateError =
Class.new(Error)

Constants inherited from BaseService

BaseService::UnauthorizedError

Instance Attribute Summary

Attributes inherited from Groups::BaseService

#current_user, #group, #params

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods included from ArchiveEvents

#publish_events, #publish_group_archived_event

Methods inherited from Groups::BaseService

#initialize

Methods inherited from BaseService

#initialize

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?, #can_all?, #can_any?

Constructor Details

This class inherits a constructor from Groups::BaseService

Instance Method Details

#executeObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/services/namespaces/groups/unarchive_service.rb', line 21

def execute
  return NotAuthorizedError unless can?(current_user, :archive_group, group)
  return AncestorArchivedError if group.ancestors_archived?
  return AlreadyUnarchivedError unless group.archived

  if unarchive_descendants?
    group.transaction do
      group.unarchive_descendants!
      group.unarchive_all_projects!
      unarchive_group
    end
  else
    unarchive_group
  end

  after_unarchive
  ServiceResponse.success
rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved, StateMachines::InvalidTransition
  ServiceResponse.error(message: "Failed to unarchive group! #{group.errors.full_messages.to_sentence}")
end