2021-03-11 19:13:27 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
namespace :gitlab do
|
|
|
|
namespace :import do
|
2020-03-13 15:44:24 +05:30
|
|
|
desc "GitLab | Import | Add all users to all projects (admin users are added as maintainers)"
|
2014-09-02 18:07:02 +05:30
|
|
|
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-09-13 17:45:13 +05:30
|
|
|
project_ids = Project.pluck(:id)
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
puts "Importing #{user_ids.size} users into #{project_ids.size} projects"
|
2022-08-13 15:12:31 +05:30
|
|
|
ProjectMember.add_members_to_projects(project_ids, user_ids, ProjectMember::DEVELOPER)
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
puts "Importing #{admin_ids.size} admins into #{project_ids.size} projects"
|
2022-08-13 15:12:31 +05:30
|
|
|
ProjectMember.add_members_to_projects(project_ids, admin_ids, ProjectMember::MAINTAINER)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
desc "GitLab | Import | Add a specific user to all projects (as a developer)"
|
2019-03-02 22:35:43 +05:30
|
|
|
task :user_to_projects, [:email] => :environment do |t, args|
|
2014-09-02 18:07:02 +05:30
|
|
|
user = User.find_by(email: args.email)
|
|
|
|
project_ids = Project.pluck(:id)
|
|
|
|
puts "Importing #{user.email} users into #{project_ids.size} projects"
|
2022-08-13 15:12:31 +05:30
|
|
|
ProjectMember.add_members_to_projects(project_ids, Array.wrap(user.id), ProjectMember::DEVELOPER)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
desc "GitLab | Import | Add all users to all groups (admin users are added as owners)"
|
2019-03-02 22:35:43 +05:30
|
|
|
task all_users_to_all_groups: :environment do |t, args|
|
2014-09-02 18:07:02 +05:30
|
|
|
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|
|
2022-08-13 15:12:31 +05:30
|
|
|
group.add_members(user_ids, GroupMember::DEVELOPER)
|
|
|
|
group.add_members(admin_ids, GroupMember::OWNER)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
desc "GitLab | Import | Add a specific user to all groups (as a developer)"
|
2019-03-02 22:35:43 +05:30
|
|
|
task :user_to_groups, [:email] => :environment do |t, args|
|
2014-09-02 18:07:02 +05:30
|
|
|
user = User.find_by_email args.email
|
|
|
|
groups = Group.all
|
|
|
|
puts "Importing #{user.email} users into #{groups.size} groups"
|
|
|
|
groups.each do |group|
|
2022-08-13 15:12:31 +05:30
|
|
|
group.add_members(Array.wrap(user.id), GroupMember::DEVELOPER)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|