From 889239b326137fe94fb9c43b596c547cd032d7be Mon Sep 17 00:00:00 2001 From: Maurice Williams Date: Tue, 8 Jul 2014 01:24:07 -0400 Subject: [PATCH] Wiring up "resend" and "revoke" button on user management screen fixes #3214 - new ```resendInvite``` method on the User model encapsulates all logic - only sending users email address when re-inviting, since the user already exists on the back-end - ```revoke``` calls DELETE on /ghost/api/v0.1/users/:user_id --- .../client/controllers/settings/users/user.js | 21 +++++++++++++++++-- core/client/models/user.js | 12 +++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/core/client/controllers/settings/users/user.js b/core/client/controllers/settings/users/user.js index 4fd9c24f6c..7a572aa8b1 100644 --- a/core/client/controllers/settings/users/user.js +++ b/core/client/controllers/settings/users/user.js @@ -40,11 +40,28 @@ var SettingsUserController = Ember.ObjectController.extend({ actions: { revoke: function () { - alert('@TODO: revoke users invitation'); + var self = this, + email = this.get('email'); + + this.get('model').destroyRecord().then(function () { + var notificationText = 'Invitation revoked. (' + email + ')'; + self.notifications.showSuccess(notificationText, false); + }).catch(function (error) { + self.notifications.closePassive(); + self.notifications.showAPIError(error); + }); }, resend: function () { - alert('@TODO: resend users invitation'); + var self = this; + + this.get('model').resendInvite().then(function () { + var notificationText = 'Invitation resent! (' + self.get('email') + ')'; + self.notifications.showSuccess(notificationText, false); + }).catch(function (error) { + self.notifications.closePassive(); + self.notifications.showAPIError(error); + }); }, save: function () { diff --git a/core/client/models/user.js b/core/client/models/user.js index 13a3d85d91..22597868e5 100644 --- a/core/client/models/user.js +++ b/core/client/models/user.js @@ -57,6 +57,18 @@ var User = DS.Model.extend({ }); }, + resendInvite: function () { + var userData = {}; + + userData.email = this.get('email'); + + return ic.ajax.request(this.get('ghostPaths').apiUrl('users'), { + type: 'POST', + data: JSON.stringify({users: [userData]}), + contentType: 'application/json' + }); + }, + passwordValidationErrors: function (password) { var validationErrors = [];