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
|
|
|
|
new_visibility = params[: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)
|
|
|
|
|
|
|
|
snippet.save
|
2015-03-01 10:06:46 -05:00
|
|
|
end
|
|
|
|
end
|