Class: UpdateSnippetService

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

Instance Attribute Summary collapse

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods inherited from BaseService

#abilities, #can?, #deny_visibility_level, #event_service, #log_info, #notification_service, #repository, #system_hook_service, #todo_service

Methods included from Gitlab::CurrentSettings

#current_application_settings, #fake_application_settings

Constructor Details

#initialize(project, user, snippet, params) ⇒ UpdateSnippetService

Returns a new instance of UpdateSnippetService


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

def initialize(project, user, snippet, params)
  super(project, user, params)
  @snippet = snippet
end

Instance Attribute Details

#snippetObject

Returns the value of attribute snippet


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

def snippet
  @snippet
end

Instance Method Details

#executeObject


9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/services/update_snippet_service.rb', line 9

def execute
  # check that user is allowed to set specified visibility_level
  new_visibility = params[:visibility_level]
  if new_visibility && new_visibility.to_i != snippet.visibility_level
    unless Gitlab::VisibilityLevel.allowed_for?(current_user, new_visibility)
      deny_visibility_level(snippet, new_visibility)
      return snippet
    end
  end

  snippet.update_attributes(params)
end