Skip to content

Commit

Permalink
Rewrote delete into generator function
Browse files Browse the repository at this point in the history
- Wasn't necessary, but thought this might fix the problem when there's no 'meta' in the reponse object
  • Loading branch information
naz committed Dec 18, 2019
1 parent 92cb485 commit 71c0cd1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
25 changes: 15 additions & 10 deletions app/controllers/staff/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,6 @@ export default Controller.extend({
this.set('dirtyAttributes', true);
},

deleteUser() {
return this._deleteUser()
.then(filename => this._exportDb(filename))
.then(() => {
this._deleteUserSuccess();
}, () => {
this._deleteUserFailure();
});
},

toggleDeleteUserModal() {
if (this.deleteUserActionIsVisible) {
Expand Down Expand Up @@ -358,7 +349,7 @@ export default Controller.extend({
this.notifications.showAlert('The user could not be deleted. Please try again.', {type: 'error', key: 'user.delete.failed'});
},

async _exportDb(filename) {
_exportDb(filename) {
let exportUrl = this.get('ghostPaths.url').api('db');
let downloadURL = `${exportUrl}?filename=${filename}`;
let iframe = document.getElementById('iframeDownload');
Expand All @@ -373,6 +364,20 @@ export default Controller.extend({
iframe.setAttribute('src', downloadURL);
},

deleteUser: task(function *() {
try {
const result = yield this.user.destroyRecord();

if (result.get('meta') && result.get('meta.filename')) {
yield this._exportDb(result.meta.filename);
}

this._deleteUserSuccess();
} catch {
this._deleteUserFailure();
}
}),

updateSlug: task(function* (newSlug) {
let slug = this.get('user.slug');

Expand Down
2 changes: 1 addition & 1 deletion app/templates/staff/user.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
{{#if this.showDeleteUserModal}}
{{gh-fullscreen-modal "delete-user"
model=this.user
confirm=(action "deleteUser")
confirm=(action (perform this.deleteUser))
close=(action "toggleDeleteUserModal")
modifier="action wide"}}
{{/if}}
Expand Down

0 comments on commit 71c0cd1

Please sign in to comment.