summaryrefslogtreecommitdiff
path: root/app/services/update_snippet_service.rb
blob: 358bca73aec25ab21637f8cfcadb9e7834ff3f61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class UpdateSnippetService < BaseService
  include SpamCheckService

  attr_accessor :snippet

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

  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

    filter_spam_check_params
    snippet.assign_attributes(params)
    spam_check(snippet, current_user)

    snippet.save
  end
end