From fc95395c5dc8b297e831a51bcec04c0644eb06d2 Mon Sep 17 00:00:00 2001 From: Mike Greiling Date: Fri, 25 Aug 2017 15:01:56 -0500 Subject: [PATCH] display specific reasons when visibility options are disabled --- app/helpers/visibility_level_helper.rb | 50 +++++++++++++++++++ app/views/shared/_visibility_radios.html.haml | 4 +- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/app/helpers/visibility_level_helper.rb b/app/helpers/visibility_level_helper.rb index c8401b784f6..347f796fdc1 100644 --- a/app/helpers/visibility_level_helper.rb +++ b/app/helpers/visibility_level_helper.rb @@ -63,6 +63,56 @@ module VisibilityLevelHelper end end + def restricted_visibility_level_description(level) + level_name = Gitlab::VisibilityLevel.level_name(level) + "#{level_name.capitalize} visibilitiy has been restricted by the administrator." + end + + def disallowed_visibility_level_description(level, form_model) + case form_model + when Project + disallowed_project_visibility_level_description(level, form_model) + when Group + disallowed_group_visibility_level_description(level, form_model) + end + end + + def disallowed_project_visibility_level_description(level, project) + level_name = Gitlab::VisibilityLevel.level_name(level).downcase + reasons = [] + + unless project.visibility_level_allowed_as_fork?(level) + reasons << "the fork source project has lower visibility" + end + + unless project.visibility_level_allowed_by_group?(level) + reasons << "the visibility of #{project.group.name} is #{project.group.visibility}" + end + + reasons = reasons.any? ? ' because ' + reasons.to_sentence : '' + "This project cannot be #{level_name}#{reasons}." + end + + def disallowed_group_visibility_level_description(level, group) + level_name = Gitlab::VisibilityLevel.level_name(level).downcase + reasons = [] + + unless group.visibility_level_allowed_by_projects?(level) + reasons << "it contains projects with higher visibility" + end + + unless group.visibility_level_allowed_by_sub_groups?(level) + reasons << "it contains sub-groups with higher visibility" + end + + unless group.visibility_level_allowed_by_parent?(level) + reasons << "the visibility of its parent group is #{group.parent.visibility}" + end + + reasons = reasons.any? ? ' because ' + reasons.to_sentence : '' + "This group cannot be #{level_name}#{reasons}." + end + def visibility_icon_description(form_model) case form_model when Project diff --git a/app/views/shared/_visibility_radios.html.haml b/app/views/shared/_visibility_radios.html.haml index 13eeaeefa9f..4a656ccfeac 100644 --- a/app/views/shared/_visibility_radios.html.haml +++ b/app/views/shared/_visibility_radios.html.haml @@ -12,6 +12,6 @@ = visibility_level_description(level, form_model) .option-disabled-reason - if restricted - This visibility level has been restricted by the administrator. + = restricted_visibility_level_description(level) - elsif disallowed - This option is not available the visibility of parent or child items prevents it. + = disallowed_visibility_level_description(level, form_model) -- GitLab