Class: WikiPages::UpdateService

Inherits:
BaseService show all
Defined in:
app/services/wiki_pages/update_service.rb

Constant Summary collapse

UpdateError =
Class.new(StandardError)

Instance Attribute Summary

Attributes inherited from BaseContainerService

#container, #current_user, #group, #params, #project

Instance Method Summary collapse

Methods included from Gitlab::InternalEventsTracking

#track_internal_event

Methods inherited from BaseContainerService

#group_container?, #initialize, #namespace_container?, #project_container?, #project_group, #root_ancestor

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 BaseContainerService

Instance Method Details

#event_actionObject



35
36
37
# File 'app/services/wiki_pages/update_service.rb', line 35

def event_action
  :updated
end

#execute(page) ⇒ Object



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

def execute(page)
  # this class is not thread safe!
  @old_slug = page.slug

  if page.update(@params)
    execute_hooks(page)
    ServiceResponse.success(payload: { page: page })
  else
    message = page.template? ? _('Could not update wiki template') : _('Could not update wiki page')
    raise UpdateError, message
  end
rescue UpdateError, WikiPage::PageChangedError, WikiPage::PageRenameError => e
  page.update_attributes(@params) # rubocop:disable Rails/ActiveRecordAliases

  ServiceResponse.error(
    message: e.message,
    payload: { page: page }
  )
end

#external_actionObject



31
32
33
# File 'app/services/wiki_pages/update_service.rb', line 31

def external_action
  'update'
end

#internal_event_nameObject



27
28
29
# File 'app/services/wiki_pages/update_service.rb', line 27

def internal_event_name
  'update_wiki_page'
end

#slug_for_page(page) ⇒ Object



39
40
41
# File 'app/services/wiki_pages/update_service.rb', line 39

def slug_for_page(page)
  @old_slug.presence || super
end