blob: 51860adca77192f360e8dc6d1aff3ee5586cb989 (
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
31
32
33
34
35
36
37
38
39
40
|
# frozen_string_literal: true
module Snippets
class CreateService < Snippets::BaseService
include SpamCheckMethods
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, snippet.visibility_level)
deny_visibility_level(snippet)
return snippet_error_response(snippet, 403)
end
snippet.author = current_user
spam_check(snippet, current_user)
snippet_saved = snippet.with_transaction_returning_status do
snippet.save
end
if snippet_saved
UserAgentDetailService.new(snippet, @request).create
Gitlab::UsageDataCounters::SnippetCounter.count(:create)
ServiceResponse.success(payload: { snippet: snippet } )
else
snippet_error_response(snippet, 400)
end
end
end
end
|