From abfbaa8d9b43c446d6af09c203b381804abb488c Mon Sep 17 00:00:00 2001 From: Naz Date: Wed, 28 Apr 2021 18:07:18 +0400 Subject: [PATCH] Added upgrade moal when unsuspending staff user refs https://github.com/TryGhost/Team/issues/587 - Previous behavior wa showing a generic API error in the top banner which wasn't ideal UX - With these changes user is informed about the limitation before performing any action with clear call to upgrade through the billing page --- ...odal-upgrade-unsuspend-user-host-limit.hbs | 20 +++++++++++++++++ ...modal-upgrade-unsuspend-user-host-limit.js | 12 ++++++++++ ghost/admin/app/controllers/staff/user.js | 22 ++++++++++++++++++- ghost/admin/app/services/limit.js | 3 ++- ghost/admin/app/templates/staff/user.hbs | 19 +++++++++++----- 5 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 ghost/admin/app/components/modal-upgrade-unsuspend-user-host-limit.hbs create mode 100644 ghost/admin/app/components/modal-upgrade-unsuspend-user-host-limit.js diff --git a/ghost/admin/app/components/modal-upgrade-unsuspend-user-host-limit.hbs b/ghost/admin/app/components/modal-upgrade-unsuspend-user-host-limit.hbs new file mode 100644 index 0000000000..cf16fb53f5 --- /dev/null +++ b/ghost/admin/app/components/modal-upgrade-unsuspend-user-host-limit.hbs @@ -0,0 +1,20 @@ + + + + + + \ No newline at end of file diff --git a/ghost/admin/app/components/modal-upgrade-unsuspend-user-host-limit.js b/ghost/admin/app/components/modal-upgrade-unsuspend-user-host-limit.js new file mode 100644 index 0000000000..11f1e858c2 --- /dev/null +++ b/ghost/admin/app/components/modal-upgrade-unsuspend-user-host-limit.js @@ -0,0 +1,12 @@ +import ModalComponent from 'ghost-admin/components/modal-base'; +import {inject as service} from '@ember/service'; + +export default ModalComponent.extend({ + router: service(), + + actions: { + upgrade: function () { + this.router.transitionTo('pro'); + } + } +}); diff --git a/ghost/admin/app/controllers/staff/user.js b/ghost/admin/app/controllers/staff/user.js index d82e5089fc..2ba1e1538a 100644 --- a/ghost/admin/app/controllers/staff/user.js +++ b/ghost/admin/app/controllers/staff/user.js @@ -16,11 +16,13 @@ export default Controller.extend({ config: service(), dropdown: service(), ghostPaths: service(), + limit: service(), notifications: service(), session: service(), slugGenerator: service(), personalToken: null, + limitErrorMessage: null, personalTokenRegenerated: false, leaveSettingsTransition: null, dirtyAttributes: false, @@ -117,7 +119,25 @@ export default Controller.extend({ toggleUnsuspendUserModal() { if (this.deleteUserActionIsVisible) { - this.toggleProperty('showUnsuspendUserModal'); + if (this.user.role.name !== 'Contributor' + && this.limit.limiter + && this.limit.limiter.isLimited('staff') + ) { + this.limit.limiter.errorIfWouldGoOverLimit('staff') + .then(() => { + this.toggleProperty('showUnsuspendUserModal'); + }) + .catch((error) => { + if (error.errorType === 'HostLimitError') { + this.limitErrorMessage = error.message; + this.toggleProperty('showUnsuspendUserModal'); + } else { + this.notifications.showAPIError(error, {key: 'staff.limit'}); + } + }); + } else { + this.toggleProperty('showUnsuspendUserModal'); + } } }, diff --git a/ghost/admin/app/services/limit.js b/ghost/admin/app/services/limit.js index 1403e2a6e4..43766150c2 100644 --- a/ghost/admin/app/services/limit.js +++ b/ghost/admin/app/services/limit.js @@ -78,7 +78,8 @@ export default class LimitsService extends Service { async getStaffUsersCount() { return RSVP.hash({ users: this.store.findAll('user', {reload: true}), - invites: this.store.findAll('invite', {reload: true}) + invites: this.store.findAll('invite', {reload: true}), + roles: this.store.findAll('role', {reload: true}) // NOTE: roles have to be fetched as they are not always loaded with invites }).then((data) => { const staffUsers = data.users.filter(u => u.get('status') !== 'inactive' && u.role.get('name') !== 'Contributor'); const staffInvites = data.invites.filter(i => i.role.get('name') !== 'Contributor'); diff --git a/ghost/admin/app/templates/staff/user.hbs b/ghost/admin/app/templates/staff/user.hbs index e98b289811..a38824e7f9 100644 --- a/ghost/admin/app/templates/staff/user.hbs +++ b/ghost/admin/app/templates/staff/user.hbs @@ -84,11 +84,20 @@ {{/if}} {{#if this.showUnsuspendUserModal}} - + {{#if this.limitErrorMessage}} + + {{else}} + + {{/if}} {{/if}}