From da9990db27c09a65e0623ae9223d52dac609d6d5 Mon Sep 17 00:00:00 2001 From: Thibaut Patel Date: Mon, 7 Jun 2021 11:05:46 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Added=20the=20"reset=20all=20passwo?= =?UTF-8?q?rds"=20user=20interface?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit issue https://github.com/TryGhost/Team/issues/750 pr https://github.com/TryGhost/Ghost/pull/13005 --- .../components/modal-reset-all-passwords.hbs | 28 ++++++++++++ .../components/modal-reset-all-passwords.js | 45 +++++++++++++++++++ ghost/admin/app/controllers/staff/index.js | 4 ++ ghost/admin/app/templates/staff/index.hbs | 36 +++++++++++++++ 4 files changed, 113 insertions(+) create mode 100644 ghost/admin/app/components/modal-reset-all-passwords.hbs create mode 100644 ghost/admin/app/components/modal-reset-all-passwords.js diff --git a/ghost/admin/app/components/modal-reset-all-passwords.hbs b/ghost/admin/app/components/modal-reset-all-passwords.hbs new file mode 100644 index 0000000000..5a1c609d99 --- /dev/null +++ b/ghost/admin/app/components/modal-reset-all-passwords.hbs @@ -0,0 +1,28 @@ + +{{svg-jar "close"}} + + + + diff --git a/ghost/admin/app/components/modal-reset-all-passwords.js b/ghost/admin/app/components/modal-reset-all-passwords.js new file mode 100644 index 0000000000..72f6aad281 --- /dev/null +++ b/ghost/admin/app/components/modal-reset-all-passwords.js @@ -0,0 +1,45 @@ +import ModalComponent from 'ghost-admin/components/modal-base'; +import {not} from '@ember/object/computed'; +import {inject as service} from '@ember/service'; +import {set} from '@ember/object'; +import {task} from 'ember-concurrency'; + +export default ModalComponent.extend({ + notifications: service(), + + isChecked: false, + isConfirmDisabled: not('isChecked'), + + actions: { + toggleCheckbox() { + set(this, 'isChecked', !this.isChecked); + }, + confirm() { + this.deletePost.perform(); + } + }, + + async _resetPasswords() { + const res = await fetch('/ghost/api/canary/admin/authentication/reset_all_passwords/', { + method: 'POST' + }); + if (res.status < 200 || res.status >= 300) { + throw new Error('api failed ' + res.status + ' ' + res.statusText); + } + }, + + _failure(error) { + this.notifications.showAPIError(error, {key: 'user.resetAllPasswords.failed'}); + }, + + resetPasswords: task(function* () { + try { + yield this._resetPasswords(); + window.location = window.location.href.split('#')[0]; + } catch (e) { + this._failure(e); + } finally { + this.send('closeModal'); + } + }).drop() +}); diff --git a/ghost/admin/app/controllers/staff/index.js b/ghost/admin/app/controllers/staff/index.js index 2b35efd29c..39a7f23941 100644 --- a/ghost/admin/app/controllers/staff/index.js +++ b/ghost/admin/app/controllers/staff/index.js @@ -11,6 +11,7 @@ export default Controller.extend({ store: service(), showInviteUserModal: false, + showResetAllPasswordsModal: false, inviteOrder: null, userOrder: null, @@ -52,6 +53,9 @@ export default Controller.extend({ actions: { toggleInviteUserModal() { this.toggleProperty('showInviteUserModal'); + }, + toggleResetAllPasswordsModal() { + this.toggleProperty('showResetAllPasswordsModal'); } }, diff --git a/ghost/admin/app/templates/staff/index.hbs b/ghost/admin/app/templates/staff/index.hbs index 07705bd236..b0f075b908 100644 --- a/ghost/admin/app/templates/staff/index.hbs +++ b/ghost/admin/app/templates/staff/index.hbs @@ -4,6 +4,36 @@ {{!-- Do not show Invite user button to authors --}} {{#unless this.currentUser.isAuthorOrContributor}}
+ {{#if (enable-developer-experiments)}} + {{#if (gh-user-can-admin this.session.user)}} + + + + {{svg-jar "settings"}} + + + + +
  • + {{!-- + --}} + +
  • +
    +
    + {{/if}} + {{/if}}
    {{/unless}} @@ -15,6 +45,12 @@ @modifier="action wide invite-user" /> {{/if}} + {{#if this.showResetAllPasswordsModal}} + + {{/if}} +
    {{!-- Show invited users to everyone except authors --}} {{#unless this.currentUser.isAuthorOrContributor}}