diff options
Diffstat (limited to 'app/helpers/namespaces_helper.rb')
-rw-r--r-- | app/helpers/namespaces_helper.rb | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/app/helpers/namespaces_helper.rb b/app/helpers/namespaces_helper.rb index 94c6b548ecd..af06833ef91 100644 --- a/app/helpers/namespaces_helper.rb +++ b/app/helpers/namespaces_helper.rb @@ -1,6 +1,9 @@ module NamespacesHelper - def namespaces_options(selected = :current_user, display_path: false) + def namespaces_options(selected = :current_user, extra_groups = [], display_path: false) groups = current_user.owned_groups + current_user.masters_groups + + groups += process_extra_groups(extra_groups) if extra_groups.any? + users = [current_user.namespace] data_attr_group = { 'data-options-parent' => 'groups' } @@ -25,6 +28,15 @@ module NamespacesHelper grouped_options_for_select(options, selected) end + def process_extra_groups(extra_groups) + # Remove duplicate groups - we either keep the ones that exist for the user + # (already in groups) or ignore those that do not belong to the user. + duplicated_groups = extra_groups.map { |name| Namespace.where(name: name).map(&:name) } + extra_groups = extra_groups - duplicated_groups.flatten + + extra_groups.map { |name| Group.new(name: name) } + end + def namespace_icon(namespace, size = 40) if namespace.kind_of?(Group) group_icon(namespace) |