debian-mirror-gitlab/app/services/concerns/update_visibility_level.rb

22 lines
638 B
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
module UpdateVisibilityLevel
2021-10-29 20:43:33 +05:30
# check that user is allowed to set specified visibility_level
2018-03-17 18:26:18 +05:30
def valid_visibility_level_change?(target, new_visibility)
2021-10-29 20:43:33 +05:30
return true unless new_visibility
new_visibility_level = Gitlab::VisibilityLevel.level_value(new_visibility)
if new_visibility_level != target.visibility_level_value
2018-03-17 18:26:18 +05:30
unless can?(current_user, :change_visibility_level, target) &&
2021-10-29 20:43:33 +05:30
Gitlab::VisibilityLevel.allowed_for?(current_user, new_visibility_level)
2018-03-17 18:26:18 +05:30
2021-10-29 20:43:33 +05:30
deny_visibility_level(target, new_visibility_level)
2018-03-17 18:26:18 +05:30
return false
end
end
true
end
end