2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
class UpdateSnippetService < BaseService
|
2017-08-17 22:00:37 +05:30
|
|
|
include SpamCheckService
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
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 = params[:visibility_level]
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
if new_visibility && new_visibility.to_i != snippet.visibility_level
|
2015-09-11 14:41:01 +05:30
|
|
|
unless Gitlab::VisibilityLevel.allowed_for?(current_user, new_visibility)
|
2015-04-26 12:48:37 +05:30
|
|
|
deny_visibility_level(snippet, new_visibility)
|
|
|
|
return snippet
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
filter_spam_check_params
|
|
|
|
snippet.assign_attributes(params)
|
|
|
|
spam_check(snippet, current_user)
|
|
|
|
|
|
|
|
snippet.save
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
end
|