2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
class CreateSnippetService < BaseService
|
2017-08-17 22:00:37 +05:30
|
|
|
include SpamCheckService
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
def execute
|
2017-08-17 22:00:37 +05:30
|
|
|
filter_spam_check_params
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
snippet = if project
|
|
|
|
project.snippets.build(params)
|
|
|
|
else
|
|
|
|
PersonalSnippet.new(params)
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
unless Gitlab::VisibilityLevel.allowed_for?(current_user, snippet.visibility_level)
|
2015-04-26 12:48:37 +05:30
|
|
|
deny_visibility_level(snippet)
|
|
|
|
return snippet
|
|
|
|
end
|
|
|
|
|
|
|
|
snippet.author = current_user
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
spam_check(snippet, current_user)
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
snippet_saved = snippet.with_transaction_returning_status do
|
|
|
|
snippet.save && snippet.store_mentions!
|
|
|
|
end
|
|
|
|
|
|
|
|
if snippet_saved
|
2017-08-17 22:00:37 +05:30
|
|
|
UserAgentDetailService.new(snippet, @request).create
|
2019-10-12 21:52:04 +05:30
|
|
|
Gitlab::UsageDataCounters::SnippetCounter.count(:create)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
snippet
|
|
|
|
end
|
|
|
|
end
|