diff --git a/ui/core/app/routes/scopes/scope/roles.js b/ui/core/app/routes/scopes/scope/roles.js index 99cf3061c..fd6991171 100644 --- a/ui/core/app/routes/scopes/scope/roles.js +++ b/ui/core/app/routes/scopes/scope/roles.js @@ -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(); } } diff --git a/ui/core/app/routes/scopes/scope/roles/role/add-principals.js b/ui/core/app/routes/scopes/scope/roles/role/add-principals.js index 6d0bb1d46..861ceb1c5 100644 --- a/ui/core/app/routes/scopes/scope/roles/role/add-principals.js +++ b/ui/core/app/routes/scopes/scope/roles/role/add-principals.js @@ -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'); } /** diff --git a/ui/core/app/routes/scopes/scope/roles/role/grants.js b/ui/core/app/routes/scopes/scope/roles/role/grants.js index d09901515..af56f1990 100644 --- a/ui/core/app/routes/scopes/scope/roles/role/grants.js +++ b/ui/core/app/routes/scopes/scope/roles/role/grants.js @@ -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 }); - } } } diff --git a/ui/core/app/routes/scopes/scope/roles/role/principals.js b/ui/core/app/routes/scopes/scope/roles/role/principals.js index dc6b27677..1bc8e3969 100644 --- a/ui/core/app/routes/scopes/scope/roles/role/principals.js +++ b/ui/core/app/routes/scopes/scope/roles/role/principals.js @@ -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(); } }