mirror of
https://github.com/discourse/discourse.git
synced 2025-03-24 21:55:38 +08:00
FEATURE: provide more details when performing a bulk add to group
This commit is contained in:
parent
f499180bb3
commit
285c167fae
app
assets/javascripts/admin
controllers
templates
controllers/admin
config/locales
spec/controllers/admin
@ -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,
|
users: null,
|
||||||
groupId: null,
|
groupId: null,
|
||||||
saving: false,
|
saving: false,
|
||||||
|
bulkAddResponse: null,
|
||||||
|
|
||||||
@computed('saving', 'users', 'groupId')
|
@computed('saving', 'users', 'groupId')
|
||||||
buttonDisabled(saving, users, groupId) {
|
buttonDisabled(saving, users, groupId) {
|
||||||
@ -24,7 +25,8 @@ export default Ember.Controller.extend({
|
|||||||
ajax('/admin/groups/bulk', {
|
ajax('/admin/groups/bulk', {
|
||||||
data: { users, group_id: this.get('groupId') },
|
data: { users, group_id: this.get('groupId') },
|
||||||
method: 'PUT'
|
method: 'PUT'
|
||||||
}).then(() => {
|
}).then(result => {
|
||||||
|
this.set('bulkAddResponse', result);
|
||||||
this.transitionToRoute('adminGroups.bulkComplete');
|
this.transitionToRoute('adminGroups.bulkComplete');
|
||||||
}).catch(popupAjaxError).finally(() => {
|
}).catch(popupAjaxError).finally(() => {
|
||||||
this.set('saving', false);
|
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
|
def bulk_perform
|
||||||
group = Group.find(params[:group_id].to_i)
|
group = Group.find(params[:group_id].to_i)
|
||||||
|
users_added = 0
|
||||||
if group.present?
|
if group.present?
|
||||||
users = (params[:users] || []).map {|u| u.downcase}
|
users = (params[:users] || []).map {|u| u.downcase}
|
||||||
user_ids = User.where("username_lower in (:users) OR email IN (:users)", users: users).pluck(:id)
|
valid_emails = valid_usernames = {}
|
||||||
group.bulk_add(user_ids) if user_ids.present?
|
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
|
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
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
@ -2600,6 +2600,7 @@ en:
|
|||||||
add_members: "Add members"
|
add_members: "Add members"
|
||||||
custom: "Custom"
|
custom: "Custom"
|
||||||
bulk_complete: "The users have been added to the group."
|
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: "Bulk Add to Group"
|
||||||
bulk_paste: "Paste a list of usernames or emails, one per line:"
|
bulk_paste: "Paste a list of usernames or emails, one per line:"
|
||||||
bulk_select: "(select a group)"
|
bulk_select: "(select a group)"
|
||||||
|
@ -255,6 +255,8 @@ en:
|
|||||||
delete_reason: "Deleted via post moderation queue"
|
delete_reason: "Deleted via post moderation queue"
|
||||||
|
|
||||||
groups:
|
groups:
|
||||||
|
success:
|
||||||
|
bulk_add: "%{users_added} users have been added to the group."
|
||||||
errors:
|
errors:
|
||||||
can_not_modify_automatic: "You cannot modify an automatic group"
|
can_not_modify_automatic: "You cannot modify an automatic group"
|
||||||
member_already_exist: "'%{username}' is already a member of this 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.primary_group).to eq(group)
|
||||||
expect(user2.title).to eq("WAT")
|
expect(user2.title).to eq("WAT")
|
||||||
expect(user2.trust_level).to eq(4)
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user