diff options
author | Rubén Dávila <ruben@gitlab.com> | 2017-08-29 08:49:01 +0300 |
---|---|---|
committer | Rubén Dávila <ruben@gitlab.com> | 2017-08-29 08:53:35 +0300 |
commit | 6f03ddcdc3af1fbb840498a0e4765458079f0b0f (patch) | |
tree | 9301cd3835e573d491dd8799533799365df996bd /app/helpers | |
parent | 0a8d0924fe9a1525b92423411dc1bfcdc9760833 (diff) |
Address some suggestions from first code review
Diffstat (limited to 'app/helpers')
-rw-r--r-- | app/helpers/namespaces_helper.rb | 15 | ||||
-rw-r--r-- | app/helpers/visibility_level_helper.rb | 12 |
2 files changed, 13 insertions, 14 deletions
diff --git a/app/helpers/namespaces_helper.rb b/app/helpers/namespaces_helper.rb index 33d6875a704..3c784272df2 100644 --- a/app/helpers/namespaces_helper.rb +++ b/app/helpers/namespaces_helper.rb @@ -6,7 +6,6 @@ module NamespacesHelper def namespaces_options(selected = :current_user, display_path: false, extra_group: nil) groups = current_user.owned_groups + current_user.masters_groups users = [current_user.namespace] - options = [] unless extra_group.nil? || extra_group.is_a?(Group) extra_group = Group.find(extra_group) if Namespace.find(extra_group).kind == 'group' @@ -16,8 +15,9 @@ module NamespacesHelper groups |= [extra_group] end - options << options_for_group(groups, display_path) - options << options_for_group(users, display_path) + options = [] + options << options_for_group(groups, display_path: display_path, type: 'group') + options << options_for_group(users, display_path: display_path, type: 'user') if selected == :current_user && current_user.namespace selected = current_user.namespace.id @@ -36,13 +36,12 @@ module NamespacesHelper private - def options_for_group(namespaces, display_path) - type = namespaces.first.is_a?(Group) ? 'group' : 'users' - + def options_for_group(namespaces, display_path:, type:) + group_label = type.pluralize elements = namespaces.sort_by(&:human_name).map! do |n| [display_path ? n.full_path : n.human_name, n.id, data: { - options_parent: type, + options_parent: group_label, visibility_level: n.visibility_level_value, visibility: n.visibility, name: n.name, @@ -51,6 +50,6 @@ module NamespacesHelper }] end - [type.camelize, elements] + [group_label.camelize, elements] end end diff --git a/app/helpers/visibility_level_helper.rb b/app/helpers/visibility_level_helper.rb index 347f796fdc1..caadc12019c 100644 --- a/app/helpers/visibility_level_helper.rb +++ b/app/helpers/visibility_level_helper.rb @@ -65,7 +65,7 @@ module VisibilityLevelHelper def restricted_visibility_level_description(level) level_name = Gitlab::VisibilityLevel.level_name(level) - "#{level_name.capitalize} visibilitiy has been restricted by the administrator." + "#{level_name.capitalize} visibility has been restricted by the administrator." end def disallowed_visibility_level_description(level, form_model) @@ -82,11 +82,11 @@ module VisibilityLevelHelper reasons = [] unless project.visibility_level_allowed_as_fork?(level) - reasons << "the fork source project has lower visibility" + reasons << project.visibility_error_for(:fork, level: level_name) end unless project.visibility_level_allowed_by_group?(level) - reasons << "the visibility of #{project.group.name} is #{project.group.visibility}" + reasons << project.visibility_error_for(:group, level: level_name, group_level: project.group.visibility) end reasons = reasons.any? ? ' because ' + reasons.to_sentence : '' @@ -98,15 +98,15 @@ module VisibilityLevelHelper reasons = [] unless group.visibility_level_allowed_by_projects?(level) - reasons << "it contains projects with higher visibility" + reasons << group.visibility_error_for(:projects, level: level_name) end unless group.visibility_level_allowed_by_sub_groups?(level) - reasons << "it contains sub-groups with higher visibility" + reasons << group.visibility_error_for(:sub_groups, level: level_name) end unless group.visibility_level_allowed_by_parent?(level) - reasons << "the visibility of its parent group is #{group.parent.visibility}" + reasons << group.visibility_error_for(:parent, level: level_name, parent_level: group.parent.visibility) end reasons = reasons.any? ? ' because ' + reasons.to_sentence : '' |