Commit 168e0341a30bccdb481591f939bac1c0d751a8c0
Exists in
spb-stable
and in
3 other branches
Merge pull request #5520 from gabetax/rake_group_bulk_add_permissions
add rake gitlab:import: all_users_to_all_groups and user_to_groups
Showing
2 changed files
with
40 additions
and
0 deletions
Show diff stats
doc/raketasks/user_management.md
@@ -14,3 +14,19 @@ Notes: | @@ -14,3 +14,19 @@ Notes: | ||
14 | ```bash | 14 | ```bash |
15 | bundle exec rake gitlab:import:all_users_to_all_projects | 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,5 +20,29 @@ namespace :gitlab do | ||
20 | puts "Importing #{user.email} users into #{project_ids.size} projects" | 20 | puts "Importing #{user.email} users into #{project_ids.size} projects" |
21 | UsersProject.add_users_into_projects(project_ids, Array.wrap(user.id), UsersProject::DEVELOPER) | 21 | UsersProject.add_users_into_projects(project_ids, Array.wrap(user.id), UsersProject::DEVELOPER) |
22 | end | 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 | end | 47 | end |
24 | end | 48 | end |