From 6afe77ef1386c17a29b020f5304b4c585b93a0d1 Mon Sep 17 00:00:00 2001 From: "Ronald A. Richardson" Date: Sun, 18 Aug 2024 14:49:44 +0800 Subject: [PATCH] added permission check to routes --- addon/components/permission-picker.hbs | 2 +- addon/routes/groups.js | 15 ++++++++++++++- addon/routes/home.js | 9 +-------- addon/routes/policies.js | 15 ++++++++++++++- addon/routes/roles.js | 15 ++++++++++++++- addon/routes/users.js | 15 ++++++++++++++- 6 files changed, 58 insertions(+), 13 deletions(-) diff --git a/addon/components/permission-picker.hbs b/addon/components/permission-picker.hbs index b0c9d73..c0860ee 100644 --- a/addon/components/permission-picker.hbs +++ b/addon/components/permission-picker.hbs @@ -21,7 +21,7 @@ Toggle Selected -
+
{{t "iam.components.permission-picker.selected"}} {{this.selected.length}}
diff --git a/addon/routes/groups.js b/addon/routes/groups.js index bb8dc3e..3a88e32 100644 --- a/addon/routes/groups.js +++ b/addon/routes/groups.js @@ -1,3 +1,16 @@ import Route from '@ember/routing/route'; +import { inject as service } from '@ember/service'; -export default class GroupsRoute extends Route {} +export default class GroupsRoute extends Route { + @service abilities; + @service notifications; + @service hostRouter; + @service intl; + + beforeModel() { + if (this.abilities.cannot('iam list group')) { + this.notifications.warning(this.intl.t('common.unauthorized-access')); + return this.hostRouter.transitionTo('console.iam.home'); + } + } +} diff --git a/addon/routes/home.js b/addon/routes/home.js index dc2b33c..f9ee296 100644 --- a/addon/routes/home.js +++ b/addon/routes/home.js @@ -1,10 +1,3 @@ import Route from '@ember/routing/route'; -import { inject as service } from '@ember/service'; -export default class HomeRoute extends Route { - @service fetch; - - model() { - return this.fetch.get('metrics/iam'); - } -} +export default class HomeRoute extends Route {} diff --git a/addon/routes/policies.js b/addon/routes/policies.js index 81f068c..6812cc6 100644 --- a/addon/routes/policies.js +++ b/addon/routes/policies.js @@ -1,3 +1,16 @@ import Route from '@ember/routing/route'; +import { inject as service } from '@ember/service'; -export default class PoliciesRoute extends Route {} +export default class PoliciesRoute extends Route { + @service abilities; + @service notifications; + @service hostRouter; + @service intl; + + beforeModel() { + if (this.abilities.cannot('iam list policy')) { + this.notifications.warning(this.intl.t('common.unauthorized-access')); + return this.hostRouter.transitionTo('console.iam.home'); + } + } +} diff --git a/addon/routes/roles.js b/addon/routes/roles.js index 2d3aa86..a8dce01 100644 --- a/addon/routes/roles.js +++ b/addon/routes/roles.js @@ -1,3 +1,16 @@ import Route from '@ember/routing/route'; +import { inject as service } from '@ember/service'; -export default class RolesRoute extends Route {} +export default class RolesRoute extends Route { + @service abilities; + @service notifications; + @service hostRouter; + @service intl; + + beforeModel() { + if (this.abilities.cannot('iam list role')) { + this.notifications.warning(this.intl.t('common.unauthorized-access')); + return this.hostRouter.transitionTo('console.iam.home'); + } + } +} diff --git a/addon/routes/users.js b/addon/routes/users.js index 92f4024..e9fe158 100644 --- a/addon/routes/users.js +++ b/addon/routes/users.js @@ -1,3 +1,16 @@ import Route from '@ember/routing/route'; +import { inject as service } from '@ember/service'; -export default class UsersRoute extends Route {} +export default class UsersRoute extends Route { + @service abilities; + @service notifications; + @service hostRouter; + @service intl; + + beforeModel() { + if (this.abilities.cannot('iam list user')) { + this.notifications.warning(this.intl.t('common.unauthorized-access')); + return this.hostRouter.transitionTo('console.iam.home'); + } + } +}