Welcome to mirror list, hosted at ThFree Co, Russian Federation.

user_management.rake « gitlab « tasks « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dbadc7a2f7acb824cdac303b72e69062193aed84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# frozen_string_literal: true

namespace :gitlab do
  namespace :user_management do
    desc "GitLab | User management | Update all users of a group with personal project limit to 0 and can_create_group to false"
    task :disable_project_and_group_creation, [:group_id] => :environment do |t, args|
      group = Group.find(args.group_id)
      user_ids = Member.from_union([
        group.hierarchy_members_with_inactive.select(:user_id),
        group.descendant_project_members_with_inactive.select(:user_id)
      ], remove_duplicates: false).distinct.pluck(:user_id)

      result = User.where(id: user_ids).update_all(projects_limit: 0, can_create_group: false)

      if result == user_ids.count
        puts "Done".color(:green)
      else
        puts "Something went wrong".color(:red)
      end
    end
  end
end