2018-07-05 06:18:17 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-03-01 10:06:46 -05:00
|
|
|
class UpdateSnippetService < BaseService
|
2017-02-14 14:07:11 -05:00
|
|
|
include SpamCheckService
|
|
|
|
|
2015-03-01 10:06:46 -05:00
|
|
|
attr_accessor :snippet
|
|
|
|
|
2015-03-07 14:47:06 -05:00
|
|
|
def initialize(project, user, snippet, params)
|
2015-03-01 10:06:46 -05:00
|
|
|
super(project, user, params)
|
|
|
|
@snippet = snippet
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
# check that user is allowed to set specified visibility_level
|
2019-08-27 13:31:59 -04:00
|
|
|
new_visibility = visibility_level
|
2017-02-14 14:07:11 -05:00
|
|
|
|
2015-03-07 14:47:06 -05:00
|
|
|
if new_visibility && new_visibility.to_i != snippet.visibility_level
|
2015-06-26 11:18:40 -04:00
|
|
|
unless Gitlab::VisibilityLevel.allowed_for?(current_user, new_visibility)
|
2015-03-07 14:47:06 -05:00
|
|
|
deny_visibility_level(snippet, new_visibility)
|
2015-03-01 10:06:46 -05:00
|
|
|
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)
|
|
|
|
|
2019-12-10 10:07:52 -05:00
|
|
|
snippet_saved = snippet.with_transaction_returning_status do
|
|
|
|
snippet.save && snippet.store_mentions!
|
|
|
|
end
|
|
|
|
|
|
|
|
if snippet_saved
|
|
|
|
Gitlab::UsageDataCounters::SnippetCounter.count(:update)
|
2019-08-08 09:18:57 -04:00
|
|
|
end
|
2015-03-01 10:06:46 -05:00
|
|
|
end
|
|
|
|
end
|