2018-07-16 12:31:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-02 02:59:24 -04:00
|
|
|
module UpdateVisibilityLevel
|
2021-10-28 14:14:18 -04:00
|
|
|
# check that user is allowed to set specified visibility_level
|
2017-09-05 20:10:30 -04:00
|
|
|
def valid_visibility_level_change?(target, new_visibility)
|
2021-10-28 14:14:18 -04:00
|
|
|
return true unless new_visibility
|
|
|
|
|
2022-07-28 14:09:03 -04:00
|
|
|
new_visibility_level = Gitlab::VisibilityLevel.level_value(new_visibility, fallback_value: nil)
|
2021-10-28 14:14:18 -04:00
|
|
|
|
|
|
|
if new_visibility_level != target.visibility_level_value
|
2017-09-02 02:59:24 -04:00
|
|
|
unless can?(current_user, :change_visibility_level, target) &&
|
2021-10-28 14:14:18 -04:00
|
|
|
Gitlab::VisibilityLevel.allowed_for?(current_user, new_visibility_level)
|
2017-09-02 02:59:24 -04:00
|
|
|
|
2021-10-28 14:14:18 -04:00
|
|
|
deny_visibility_level(target, new_visibility_level)
|
2017-09-02 02:59:24 -04:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|