2015-03-01 15:06:46 +00:00
|
|
|
class UpdateSnippetService < BaseService
|
|
|
|
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
|
|
|
|
new_visibility = params[:visibility_level]
|
2015-03-07 19:47:06 +00:00
|
|
|
if new_visibility && new_visibility.to_i != snippet.visibility_level
|
2015-03-01 15:06:46 +00:00
|
|
|
unless can?(current_user, :change_visibility_level, snippet) &&
|
|
|
|
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
|
|
|
|
|
|
|
|
snippet.update_attributes(params)
|
|
|
|
end
|
|
|
|
end
|