2015-03-01 10:06:46 -05:00
|
|
|
class UpdateSnippetService < BaseService
|
|
|
|
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]
|
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
|
|
|
|
|
|
|
|
snippet.update_attributes(params)
|
|
|
|
end
|
|
|
|
end
|