summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Greiling <mike@pixelcog.com>2017-08-25 15:01:56 -0500
committerMike Greiling <mike@pixelcog.com>2017-08-26 03:31:14 -0500
commitfc95395c5dc8b297e831a51bcec04c0644eb06d2 (patch)
tree839e5dcba78fe57f45c84472fc5d8154f071ca34
parent8cf504a71c326033a5a0885fa950a7d2c37ca93c (diff)
downloadgitlab-ce-fc95395c5dc8b297e831a51bcec04c0644eb06d2.tar.gz
display specific reasons when visibility options are disabled
-rw-r--r--app/helpers/visibility_level_helper.rb50
-rw-r--r--app/views/shared/_visibility_radios.html.haml4
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)