2018-07-05 06:18:17 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-03-07 14:47:06 -05:00
|
|
|
class CreateSnippetService < BaseService
|
2017-02-14 14:07:11 -05:00
|
|
|
include SpamCheckService
|
|
|
|
|
2015-03-07 14:47:06 -05:00
|
|
|
def execute
|
2017-02-14 14:07:11 -05:00
|
|
|
filter_spam_check_params
|
2017-02-01 13:15:59 -05:00
|
|
|
|
2016-07-06 09:26:59 -04:00
|
|
|
snippet = if project
|
|
|
|
project.snippets.build(params)
|
|
|
|
else
|
|
|
|
PersonalSnippet.new(params)
|
|
|
|
end
|
2015-03-07 14:47:06 -05:00
|
|
|
|
2019-08-27 13:31:59 -04:00
|
|
|
unless Gitlab::VisibilityLevel.allowed_for?(current_user, snippet.visibility_level)
|
2015-03-07 14:47:06 -05:00
|
|
|
deny_visibility_level(snippet)
|
|
|
|
return snippet
|
|
|
|
end
|
|
|
|
|
|
|
|
snippet.author = current_user
|
2017-02-14 14:07:11 -05:00
|
|
|
|
|
|
|
spam_check(snippet, current_user)
|
2017-02-01 13:15:59 -05:00
|
|
|
|
|
|
|
if snippet.save
|
2017-02-14 14:07:11 -05:00
|
|
|
UserAgentDetailService.new(snippet, @request).create
|
2019-08-08 09:18:57 -04:00
|
|
|
Gitlab::UsageDataCounters::SnippetCounter.count(:create)
|
2017-02-01 13:15:59 -05:00
|
|
|
end
|
2015-03-07 14:47:06 -05:00
|
|
|
|
|
|
|
snippet
|
|
|
|
end
|
|
|
|
end
|