gitlab-org--gitlab-foss/app/services/update_snippet_service.rb

37 lines
936 B
Ruby
Raw Normal View History

# frozen_string_literal: true
class UpdateSnippetService < BaseService
2017-02-14 14:07:11 -05:00
include SpamCheckService
attr_accessor :snippet
def initialize(project, user, snippet, params)
super(project, user, params)
@snippet = snippet
end
def execute
# check that user is allowed to set specified visibility_level
new_visibility = visibility_level
2017-02-14 14:07:11 -05:00
if new_visibility && new_visibility.to_i != snippet.visibility_level
unless Gitlab::VisibilityLevel.allowed_for?(current_user, new_visibility)
deny_visibility_level(snippet, new_visibility)
return snippet
end
end
2017-02-14 14:07:11 -05:00
filter_spam_check_params
snippet.assign_attributes(params)
spam_check(snippet, current_user)
snippet_saved = snippet.with_transaction_returning_status do
snippet.save && snippet.store_mentions!
end
if snippet_saved
Gitlab::UsageDataCounters::SnippetCounter.count(:update)
end
end
end