summaryrefslogtreecommitdiff
path: root/app/helpers/namespaces_helper.rb
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2012-11-27 17:48:25 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2012-11-27 17:48:25 +0200
commit81f8114f24313bb90f09f5ed1ff656759cb55020 (patch)
tree8d8dbf27f3b01bfce136192e921771d8aaedc580 /app/helpers/namespaces_helper.rb
parent039996bd0a9e547cd5dbcb7f12fa43152f0589c1 (diff)
downloadgitlab-ce-81f8114f24313bb90f09f5ed1ff656759cb55020.tar.gz
NamespacesHelper
Diffstat (limited to 'app/helpers/namespaces_helper.rb')
-rw-r--r--app/helpers/namespaces_helper.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/app/helpers/namespaces_helper.rb b/app/helpers/namespaces_helper.rb
new file mode 100644
index 00000000000..fdf6725cc13
--- /dev/null
+++ b/app/helpers/namespaces_helper.rb
@@ -0,0 +1,26 @@
+module NamespacesHelper
+ def namespaces_options(selected = :current_user, scope = :default)
+ groups = current_user.namespaces.select {|n| n.type == 'Group'}
+
+ users = if scope == :all
+ Namespace.root
+ else
+ current_user.namespaces.reject {|n| n.type == 'Group'}
+ end
+
+ global_opts = ["Global", [['/', Namespace.global_id]] ]
+ group_opts = ["Groups", groups.map {|g| [g.human_name, g.id]} ]
+ users_opts = [ "Users", users.map {|u| [u.human_name, u.id]} ]
+
+ options = []
+ options << global_opts if current_user.admin
+ options << group_opts
+ options << users_opts
+
+ if selected == :current_user && current_user.namespace
+ selected = current_user.namespace.id
+ end
+
+ grouped_options_for_select(options, selected)
+ end
+end