mirror of
https://github.com/discourse/discourse.git
synced 2025-01-19 05:43:16 +08:00
Merge pull request #4839 from techAPJ/bulk-add-group
FEATURE: provide more details when performing a bulk add to group
This commit is contained in:
commit
9b0ecdaf7e
|
@ -0,0 +1,4 @@
|
|||
export default Ember.Controller.extend({
|
||||
adminGroupsBulk: Ember.inject.controller(),
|
||||
bulkAddResponse: Ember.computed.alias('adminGroupsBulk.bulkAddResponse')
|
||||
});
|
|
@ -6,6 +6,7 @@ export default Ember.Controller.extend({
|
|||
users: null,
|
||||
groupId: null,
|
||||
saving: false,
|
||||
bulkAddResponse: null,
|
||||
|
||||
@computed('saving', 'users', 'groupId')
|
||||
buttonDisabled(saving, users, groupId) {
|
||||
|
@ -24,7 +25,8 @@ export default Ember.Controller.extend({
|
|||
ajax('/admin/groups/bulk', {
|
||||
data: { users, group_id: this.get('groupId') },
|
||||
method: 'PUT'
|
||||
}).then(() => {
|
||||
}).then(result => {
|
||||
this.set('bulkAddResponse', result);
|
||||
this.transitionToRoute('adminGroups.bulkComplete');
|
||||
}).catch(popupAjaxError).finally(() => {
|
||||
this.set('saving', false);
|
||||
|
|
|
@ -1 +1,11 @@
|
|||
<p>{{i18n "admin.groups.bulk_complete"}}</p>
|
||||
{{#if bulkAddResponse}}
|
||||
<p>{{{bulkAddResponse.message}}}</p>
|
||||
{{#if bulkAddResponse.users_not_added}}
|
||||
<p>{{i18n "admin.groups.bulk_complete_users_not_added"}}</p>
|
||||
{{#each bulkAddResponse.users_not_added as |user|}}
|
||||
{{user}}<br/>
|
||||
{{/each}}
|
||||
{{/if}}
|
||||
{{else}}
|
||||
<p>{{i18n "admin.groups.bulk_complete"}}</p>
|
||||
{{/if}}
|
||||
|
|
|
@ -24,13 +24,22 @@ class Admin::GroupsController < Admin::AdminController
|
|||
|
||||
def bulk_perform
|
||||
group = Group.find(params[:group_id].to_i)
|
||||
users_added = 0
|
||||
if group.present?
|
||||
users = (params[:users] || []).map {|u| u.downcase}
|
||||
user_ids = User.where("username_lower in (:users) OR email IN (:users)", users: users).pluck(:id)
|
||||
group.bulk_add(user_ids) if user_ids.present?
|
||||
valid_emails = valid_usernames = {}
|
||||
valid_users = User.where("username_lower IN (:users) OR email IN (:users)", users: users).pluck(:id, :username_lower, :email)
|
||||
valid_users.each do |vu|
|
||||
valid_emails[vu[1]] = valid_usernames[vu[2]] = vu[0]
|
||||
vu.slice!(1..2)
|
||||
end
|
||||
invalid_users = users.reject! { |u| valid_emails[u] || valid_usernames[u] }
|
||||
valid_users.flatten!
|
||||
group.bulk_add(valid_users) if valid_users.present?
|
||||
users_added = valid_users.count
|
||||
end
|
||||
|
||||
render json: success_json
|
||||
render json: { success: true, message: I18n.t('groups.success.bulk_add', users_added: users_added), users_not_added: invalid_users }
|
||||
end
|
||||
|
||||
def create
|
||||
|
|
|
@ -2601,6 +2601,7 @@ en:
|
|||
add_members: "Add members"
|
||||
custom: "Custom"
|
||||
bulk_complete: "The users have been added to the group."
|
||||
bulk_complete_users_not_added: "These users were not added:"
|
||||
bulk: "Bulk Add to Group"
|
||||
bulk_paste: "Paste a list of usernames or emails, one per line:"
|
||||
bulk_select: "(select a group)"
|
||||
|
|
|
@ -255,6 +255,8 @@ en:
|
|||
delete_reason: "Deleted via post moderation queue"
|
||||
|
||||
groups:
|
||||
success:
|
||||
bulk_add: "%{users_added} users have been added to the group."
|
||||
errors:
|
||||
can_not_modify_automatic: "You cannot modify an automatic group"
|
||||
member_already_exist: "'%{username}' is already a member of this group."
|
||||
|
|
|
@ -69,6 +69,11 @@ describe Admin::GroupsController do
|
|||
expect(user2.primary_group).to eq(group)
|
||||
expect(user2.title).to eq("WAT")
|
||||
expect(user2.trust_level).to eq(4)
|
||||
|
||||
# verify JSON response
|
||||
json = ::JSON.parse(response.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
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user