Commit 17105038caf237687ad0fc9f34bf5f368d0cc8a5
1 parent
4c47a89f
Exists in
spb-stable
and in
3 other branches
add rake gitlab:import: all_users_to_all_groups and user_to_groups
I opted for admins to be added as "owners" instead of "masters" because project masters can managers members, but only group owners can manage members.
Showing
2 changed files
with
40 additions
and
0 deletions
Show diff stats
doc/raketasks/user_management.md
... | ... | @@ -14,3 +14,19 @@ Notes: |
14 | 14 | ``` |
15 | 15 | bundle exec rake gitlab:import:all_users_to_all_projects |
16 | 16 | ``` |
17 | + | |
18 | +### Add user as a developer to all projects | |
19 | + | |
20 | +``` | |
21 | +bundle exec rake gitlab:import:user_to_groups[username@domain.tld] | |
22 | +``` | |
23 | + | |
24 | +### Add all users to all groups | |
25 | + | |
26 | +Notes: | |
27 | + | |
28 | +* admin users are added as owners so they can add additional users to the group | |
29 | + | |
30 | +``` | |
31 | +bundle exec rake gitlab:import:all_users_to_all_groups | |
32 | +``` | ... | ... |
lib/tasks/gitlab/bulk_add_permission.rake
... | ... | @@ -20,5 +20,29 @@ namespace :gitlab do |
20 | 20 | puts "Importing #{user.email} users into #{project_ids.size} projects" |
21 | 21 | UsersProject.add_users_into_projects(project_ids, Array.wrap(user.id), UsersProject::DEVELOPER) |
22 | 22 | end |
23 | + | |
24 | + desc "GITLAB | Add all users to all groups (admin users are added as owners)" | |
25 | + task all_users_to_all_groups: :environment do |t, args| | |
26 | + user_ids = User.where(admin: false).pluck(:id) | |
27 | + admin_ids = User.where(admin: true).pluck(:id) | |
28 | + groups = Group.all | |
29 | + | |
30 | + puts "Importing #{user_ids.size} users into #{groups.size} groups" | |
31 | + puts "Importing #{admin_ids.size} admins into #{groups.size} groups" | |
32 | + groups.each do |group| | |
33 | + group.add_users(user_ids, UsersGroup::DEVELOPER) | |
34 | + group.add_users(admin_ids, UsersGroup::OWNER) | |
35 | + end | |
36 | + end | |
37 | + | |
38 | + desc "GITLAB | Add a specific user to all groups (as a developer)" | |
39 | + task :user_to_groups, [:email] => :environment do |t, args| | |
40 | + user = User.find_by_email args.email | |
41 | + groups = Group.all | |
42 | + puts "Importing #{user.email} users into #{groups.size} groups" | |
43 | + groups.each do |group| | |
44 | + group.add_users(Array.wrap(user.id), UsersGroup::DEVELOPER) | |
45 | + end | |
46 | + end | |
23 | 47 | end |
24 | 48 | end | ... | ... |