2018-07-05 10:18:17 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-03-01 15:06:46 +00:00
|
|
|
class UpdateSnippetService < BaseService
|
2017-02-14 19:07:11 +00:00
|
|
|
include SpamCheckService
|
|
|
|
|
2015-03-01 15:06:46 +00:00
|
|
|
attr_accessor :snippet
|
|
|
|
|
2015-03-07 19:47:06 +00:00
|
|
|
def initialize(project, user, snippet, params)
|
2015-03-01 15:06:46 +00:00
|
|
|
super(project, user, params)
|
|
|
|
@snippet = snippet
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
# check that user is allowed to set specified visibility_level
|
2019-08-27 17:31:59 +00:00
|
|
|
new_visibility = visibility_level
|
2017-02-14 19:07:11 +00:00
|
|
|
|
2015-03-07 19:47:06 +00:00
|
|
|
if new_visibility && new_visibility.to_i != snippet.visibility_level
|
2015-06-26 15:18:40 +00:00
|
|
|
unless Gitlab::VisibilityLevel.allowed_for?(current_user, new_visibility)
|
2015-03-07 19:47:06 +00:00
|
|
|
deny_visibility_level(snippet, new_visibility)
|
2015-03-01 15:06:46 +00:00
|
|
|
return snippet
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-02-14 19:07:11 +00:00
|
|
|
filter_spam_check_params
|
|
|
|
snippet.assign_attributes(params)
|
|
|
|
spam_check(snippet, current_user)
|
|
|
|
|
2019-08-08 13:18:57 +00:00
|
|
|
snippet.save.tap do |succeeded|
|
|
|
|
Gitlab::UsageDataCounters::SnippetCounter.count(:update) if succeeded
|
|
|
|
end
|
2015-03-01 15:06:46 +00:00
|
|
|
end
|
|
|
|
end
|