diff --git a/app/assets/javascripts/admin/controllers/admin_user_controller.js b/app/assets/javascripts/admin/controllers/admin_user_controller.js index 277be26bd80..f909dec1d47 100644 --- a/app/assets/javascripts/admin/controllers/admin_user_controller.js +++ b/app/assets/javascripts/admin/controllers/admin_user_controller.js @@ -50,23 +50,13 @@ Discourse.AdminUserIndexController = Discourse.ObjectController.extend({ }, groupAdded: function(added){ - var self = this; - Discourse.ajax("/admin/users/" + this.get('id') + "/groups", { - type: 'POST', - data: {group_id: added.id} - }).then(function () { - self.get('model.groups').pushObject(added); - }).catch(function() { + this.get('model').groupAdded(added).catch(function() { bootbox.alert(I18n.t('generic_error')); }); }, + groupRemoved: function(removed){ - var self = this; - Discourse.ajax("/admin/users/" + this.get('id') + "/groups/" + removed.id, { - type: 'DELETE' - }).then(function () { - self.set('model.groups.[]', self.get('model.groups').rejectBy("id", removed.id)); - }).catch(function() { + this.get('model').groupRemoved(removed).catch(function() { bootbox.alert(I18n.t('generic_error')); }); }, diff --git a/app/assets/javascripts/admin/models/admin_user.js b/app/assets/javascripts/admin/models/admin_user.js index 981e1be3674..9cde5b2e8d1 100644 --- a/app/assets/javascripts/admin/models/admin_user.js +++ b/app/assets/javascripts/admin/models/admin_user.js @@ -23,6 +23,25 @@ Discourse.AdminUser = Discourse.User.extend({ }); }, + groupAdded: function(added){ + var self = this; + return Discourse.ajax("/admin/users/" + this.get('id') + "/groups", { + type: 'POST', + data: {group_id: added.id} + }).then(function () { + self.get('groups').pushObject(added); + }); + }, + + groupRemoved: function(removed){ + var self = this; + return Discourse.ajax("/admin/users/" + this.get('id') + "/groups/" + removed.id, { + type: 'DELETE' + }).then(function () { + self.set('groups.[]', self.get('groups').rejectBy("id", removed.id)); + }) + }, + /** Revokes a user's current API key