feat: Update roles routes for notify decorator

This commit is contained in:
Susmitha Girumala committed 2020-10-08 17:45:28 -04:00
1 parent 7758099ca4
commit 870dc788a4
4 files changed
+25 -45

No files matched your search

+11 -22
View File
@@ -3,6 +3,7 @@ import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import loading from 'ember-loading/decorator';
import { confirm } from '../../../decorators/confirm';
import { notifySuccess, notifyError } from '../../../decorators/notify';
export default class ScopesScopeRolesRoute extends Route {
// =services
@@ -47,20 +48,12 @@ export default class ScopesScopeRolesRoute extends Route {
*/
@action
@loading
@notifyError(({ message }) => message)
@notifySuccess(({ isNew }) => isNew ? 'notifications.create-success' : 'notifications.save-success')
async save(role) {
const { isNew } = role;
try {
await role.save();
await this.transitionTo('scopes.scope.roles.role', role);
this.refresh();
this.notify.success(
this.intl.t(isNew ? 'notifications.create-success' : 'notifications.save-success')
);
} catch (error) {
// TODO: replace with translated strings
this.notify.error(error.message, { closeAfter: null });
throw error;
}
await role.save();
await this.transitionTo('scopes.scope.roles.role', role);
this.refresh();
}
/**
@@ -70,15 +63,11 @@ export default class ScopesScopeRolesRoute extends Route {
@action
@loading
@confirm('questions.delete-confirm')
@notifyError(({ message }) => message, { catch: true })
@notifySuccess('notifications.delete-success')
async delete(role) {
try {
await role.destroyRecord();
await this.replaceWith('scopes.scope.roles');
this.refresh();
this.notify.success(this.intl.t('notifications.delete-success'));
} catch (error) {
// TODO: replace with translated strings
this.notify.error(error.message, { closeAfter: null });
}
await role.destroyRecord();
await this.replaceWith('scopes.scope.roles');
this.refresh();
}
}
@@ -3,6 +3,7 @@ import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import { hash } from 'rsvp';
import loading from 'ember-loading/decorator';
import { notifySuccess, notifyError } from '../../../../../decorators/notify';
export default class ScopesScopeRolesRoleAddPrincipalsRoute extends Route {
// =services
@@ -59,15 +60,11 @@ export default class ScopesScopeRolesRoleAddPrincipalsRoute extends Route {
*/
@action
@loading
@notifyError(({ message }) => message, { catch: true })
@notifySuccess('notifications.add-success')
async addPrincipals(role, principalIDs) {
try {
await role.addPrincipals(principalIDs);
this.replaceWith('scopes.scope.roles.role.principals');
this.notify.success(this.intl.t('notifications.add-success'));
} catch (error) {
// TODO: replace with translated strings
this.notify.error(error.message, { closeAfter: null });
}
await role.addPrincipals(principalIDs);
this.replaceWith('scopes.scope.roles.role.principals');
}
/**
@@ -2,6 +2,7 @@ import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import loading from 'ember-loading/decorator';
import { notifySuccess, notifyError } from '../../../../../decorators/notify';
export default class ScopesScopeRolesRoleGrantsRoute extends Route {
// =services
@@ -56,13 +57,9 @@ export default class ScopesScopeRolesRoleGrantsRoute extends Route {
*/
@action
@loading
@notifyError(({ message }) => message, { catch: true })
@notifySuccess('notifications.save-success')
async save(role) {
try {
await role.saveGrants();
this.notify.success(this.intl.t('notifications.save-success'));
} catch (error) {
// TODO: replace with translated strings
this.notify.error(error.message, { closeAfter: null });
}
}
}
@@ -4,6 +4,7 @@ import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import loading from 'ember-loading/decorator';
import { confirm } from '../../../../../decorators/confirm';
import { notifySuccess, notifyError } from '../../../../../decorators/notify';
export default class ScopesScopeRolesRolePrincipalsRoute extends Route {
// =services
@@ -67,16 +68,12 @@ export default class ScopesScopeRolesRolePrincipalsRoute extends Route {
@action
@loading
@confirm('questions.remove-confirm')
@notifyError(({ message }) => message, { catch: true })
@notifySuccess('notifications.remove-success')
async removePrincipal(principal) {
try {
const role = this.modelFor('scopes.scope.roles.role');
await role.removePrincipal(principal.id);
this.refresh();
this.notify.success(this.intl.t('notifications.remove-success'));
} catch (error) {
// TODO: replace with translated strings
this.notify.error(error.message, { closeAfter: null });
}
const role = this.modelFor('scopes.scope.roles.role');
await role.removePrincipal(principal.id);
this.refresh();
}
}