DEV: Remove bulk group admin endpoints (#11949)

Originally added in 47e25648df. Looks like all related code was removed in c82b2dcc24 and b76731d722.
This commit is contained in:
Jarek Radosz 2021-02-03 18:12:22 +01:00 committed by GitHub
parent 2dc48fd6c1
commit 45931f86be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 0 additions and 80 deletions

View File

@ -1,41 +1,6 @@
# frozen_string_literal: true
class Admin::GroupsController < Admin::AdminController
def bulk
end
def bulk_perform
group = Group.find_by(id: params[:group_id].to_i)
raise Discourse::NotFound unless group
users_added = 0
users = (params[:users] || []).map { |user| user.downcase!; user }
valid_emails = {}
valid_usernames = {}
valid_users = User.joins(:user_emails)
.where("username_lower IN (:users) OR lower(user_emails.email) IN (:users)", users: users)
.pluck(:id, :username_lower, :"user_emails.email")
valid_users.map! do |id, username_lower, email|
valid_emails[email] = valid_usernames[username_lower] = id
id
end
valid_users.uniq!
invalid_users = users.reject { |u| valid_emails[u] || valid_usernames[u] }
group.bulk_add(valid_users) if valid_users.present?
users_added = valid_users.count
response = success_json.merge(users_not_added: invalid_users)
if users_added > 0
response[:message] = I18n.t('groups.success.bulk_add', count: users_added)
end
render json: response
end
def create
guardian.ensure_can_create_group!

View File

@ -3752,10 +3752,6 @@ en:
available: "Group name is available"
not_available: "Group name is not available"
blank: "Group name cannot be blank"
bulk_add:
title: "Bulk Add to Group"
complete_users_not_added: "These users were not added (make sure they have an account):"
paste: "Paste a list of usernames or emails, one per line:"
add_members:
as_owner: "Set user(s) as owner(s) of this group"
manage:

View File

@ -100,9 +100,6 @@ Discourse::Application.routes.draw do
end
resources :groups, except: [:create], constraints: AdminConstraint.new do
collection do
get 'bulk'
get 'bulk-complete' => 'groups#bulk'
put 'bulk' => 'groups#bulk_perform'
put "automatic_membership_count" => "groups#automatic_membership_count"
end
end

View File

@ -237,44 +237,6 @@ RSpec.describe Admin::GroupsController do
end
end
describe "#bulk_perform" do
fab!(:group) do
Fabricate(:group,
name: "test",
primary_group: true,
title: 'WAT',
grant_trust_level: 3
)
end
fab!(:user) { Fabricate(:user, trust_level: 2) }
fab!(:user2) { Fabricate(:user, trust_level: 4) }
it "can assign users to a group by email or username" do
Jobs.run_immediately!
put "/admin/groups/bulk.json", params: {
group_id: group.id, users: [user.username.upcase, user2.email, 'doesnt_exist']
}
expect(response.status).to eq(200)
user.reload
expect(user.primary_group).to eq(group)
expect(user.title).to eq("WAT")
expect(user.trust_level).to eq(3)
user2.reload
expect(user2.primary_group).to eq(group)
expect(user2.title).to eq("WAT")
expect(user2.trust_level).to eq(4)
json = response.parsed_body
expect(json['message']).to eq("2 users have been added to the group.")
expect(json['users_not_added'][0]).to eq("doesnt_exist")
end
end
context "#destroy" do
it 'should return the right response for an invalid group_id' do
max_id = Group.maximum(:id).to_i