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
|
|
|
|
2016-03-20 16:03:53 -04:00
|
|
|
unless Gitlab::VisibilityLevel.allowed_for?(current_user, params[: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
|
2017-02-01 13:15:59 -05:00
|
|
|
end
|
2015-03-07 14:47:06 -05:00
|
|
|
|
|
|
|
snippet
|
|
|
|
end
|
|
|
|
end
|