summaryrefslogtreecommitdiff
path: root/app/services/create_snippet_service.rb
blob: 6f1fce4989e7736228e1a5151855c8b7bc3f38cd (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
29
30
# frozen_string_literal: true

class CreateSnippetService < BaseService
  include SpamCheckService

  def execute
    filter_spam_check_params

    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

    spam_check(snippet, current_user)

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

    snippet
  end
end