4a6f959ab8
Generalize wiki page counter for other page types to extend to.
31 lines
701 B
Ruby
31 lines
701 B
Ruby
# 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
|
|
Gitlab::UsageDataCounters::SnippetCounter.count(:create)
|
|
end
|
|
|
|
snippet
|
|
end
|
|
end
|