Commit 083d4604 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Change dynamic abilities to new format

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent d63371ad
...@@ -246,20 +246,16 @@ class Ability ...@@ -246,20 +246,16 @@ class Ability
[:issue, :note, :project_snippet, :personal_snippet, :merge_request].each do |name| [:issue, :note, :project_snippet, :personal_snippet, :merge_request].each do |name|
define_method "#{name}_abilities" do |user, subject| define_method "#{name}_abilities" do |user, subject|
if subject.author == user || user.is_admin? if user.is_admin?
rules = [ [
:"read_#{name}", :"read_#{name}",
:"write_#{name}", :"update_#{name}",
:"modify_#{name}",
:"admin_#{name}" :"admin_#{name}"
] ]
rules.push(:change_visibility_level) if subject.is_a?(Snippet) elsif subject.author == user || (subject.respond_to?(:assignee) && subject.assignee == user)
rules
elsif subject.respond_to?(:assignee) && subject.assignee == user
[ [
:"read_#{name}", :"read_#{name}",
:"write_#{name}", :"update_#{name}",
:"modify_#{name}",
] ]
else else
if subject.respond_to?(:project) && subject.project if subject.respond_to?(:project) && subject.project
...@@ -299,8 +295,8 @@ class Ability ...@@ -299,8 +295,8 @@ class Ability
def named_abilities(name) def named_abilities(name)
[ [
:"read_#{name}", :"read_#{name}",
:"write_#{name}", :"create_#{name}",
:"modify_#{name}", :"update_#{name}",
:"admin_#{name}" :"admin_#{name}"
] ]
end end
......
...@@ -9,9 +9,9 @@ class UpdateSnippetService < BaseService ...@@ -9,9 +9,9 @@ class UpdateSnippetService < BaseService
def execute def execute
# check that user is allowed to set specified visibility_level # check that user is allowed to set specified visibility_level
new_visibility = params[:visibility_level] new_visibility = params[:visibility_level]
if new_visibility && new_visibility.to_i != snippet.visibility_level if new_visibility && new_visibility.to_i != snippet.visibility_level
unless can?(current_user, :change_visibility_level, snippet) && unless Gitlab::VisibilityLevel.allowed_for?(current_user, new_visibility)
Gitlab::VisibilityLevel.allowed_for?(current_user, new_visibility)
deny_visibility_level(snippet, new_visibility) deny_visibility_level(snippet, new_visibility)
return snippet return snippet
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment