summaryrefslogtreecommitdiff
path: root/app/services/create_snippet_service.rb
blob: 14f5ba064ffdab0835c3851c7b85561b9c2d9568 (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
class CreateSnippetService < BaseService
  def execute
    request = params.delete(:request)
    api = params.delete(:api)

    snippet = if project
                project.snippets.build(params)
              else
                PersonalSnippet.new(params)
              end

    unless Gitlab::VisibilityLevel.allowed_for?(current_user, params[:visibility_level])
      deny_visibility_level(snippet)
      return snippet
    end

    snippet.author = current_user
    snippet.spam = SpamService.new(snippet, request).check(api)

    if snippet.save
      UserAgentDetailService.new(snippet, request).create
    end

    snippet
  end
end