2012-12-20 14:05:01 -05:00
|
|
|
namespace :gitlab do
|
|
|
|
namespace :import do
|
2018-07-11 10:36:08 -04:00
|
|
|
desc "GitLab | Add all users to all projects (admin users are added as maintainers)"
|
2013-05-05 10:01:10 -04:00
|
|
|
task all_users_to_all_projects: :environment do |t, args|
|
|
|
|
user_ids = User.where(admin: false).pluck(:id)
|
|
|
|
admin_ids = User.where(admin: true).pluck(:id)
|
2016-08-04 00:35:17 -04:00
|
|
|
project_ids = Project.pluck(:id)
|
2012-12-20 14:05:01 -05:00
|
|
|
|
2016-08-04 00:35:17 -04:00
|
|
|
puts "Importing #{user_ids.size} users into #{project_ids.size} projects"
|
|
|
|
ProjectMember.add_users_to_projects(project_ids, user_ids, ProjectMember::DEVELOPER)
|
2013-01-28 07:52:30 -05:00
|
|
|
|
2016-08-04 00:35:17 -04:00
|
|
|
puts "Importing #{admin_ids.size} admins into #{project_ids.size} projects"
|
2018-07-11 10:36:08 -04:00
|
|
|
ProjectMember.add_users_to_projects(project_ids, admin_ids, ProjectMember::MAINTAINER)
|
2012-12-20 14:05:01 -05:00
|
|
|
end
|
|
|
|
|
2015-06-23 10:52:40 -04:00
|
|
|
desc "GitLab | Add a specific user to all projects (as a developer)"
|
2012-12-20 14:05:01 -05:00
|
|
|
task :user_to_projects, [:email] => :environment do |t, args|
|
2014-01-19 13:55:59 -05:00
|
|
|
user = User.find_by(email: args.email)
|
2012-12-20 14:05:01 -05:00
|
|
|
project_ids = Project.pluck(:id)
|
2013-01-28 07:52:30 -05:00
|
|
|
puts "Importing #{user.email} users into #{project_ids.size} projects"
|
2016-08-04 00:35:17 -04:00
|
|
|
ProjectMember.add_users_to_projects(project_ids, Array.wrap(user.id), ProjectMember::DEVELOPER)
|
2012-12-20 14:05:01 -05:00
|
|
|
end
|
2013-11-02 18:12:29 -04:00
|
|
|
|
2015-06-23 10:52:40 -04:00
|
|
|
desc "GitLab | Add all users to all groups (admin users are added as owners)"
|
2013-11-02 18:12:29 -04:00
|
|
|
task all_users_to_all_groups: :environment do |t, args|
|
|
|
|
user_ids = User.where(admin: false).pluck(:id)
|
|
|
|
admin_ids = User.where(admin: true).pluck(:id)
|
|
|
|
groups = Group.all
|
|
|
|
|
|
|
|
puts "Importing #{user_ids.size} users into #{groups.size} groups"
|
|
|
|
puts "Importing #{admin_ids.size} admins into #{groups.size} groups"
|
|
|
|
groups.each do |group|
|
2014-09-14 12:32:51 -04:00
|
|
|
group.add_users(user_ids, GroupMember::DEVELOPER)
|
|
|
|
group.add_users(admin_ids, GroupMember::OWNER)
|
2013-11-02 18:12:29 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-06-23 10:52:40 -04:00
|
|
|
desc "GitLab | Add a specific user to all groups (as a developer)"
|
2013-11-02 18:12:29 -04:00
|
|
|
task :user_to_groups, [:email] => :environment do |t, args|
|
|
|
|
user = User.find_by_email args.email
|
|
|
|
groups = Group.all
|
|
|
|
puts "Importing #{user.email} users into #{groups.size} groups"
|
|
|
|
groups.each do |group|
|
2014-09-14 12:32:51 -04:00
|
|
|
group.add_users(Array.wrap(user.id), GroupMember::DEVELOPER)
|
2013-11-02 18:12:29 -04:00
|
|
|
end
|
|
|
|
end
|
2012-12-20 14:05:01 -05:00
|
|
|
end
|
2013-03-20 17:46:30 -04:00
|
|
|
end
|