Skip to content

Commit

Permalink
added permission check to routes
Browse files Browse the repository at this point in the history
  • Loading branch information
roncodes committed Aug 18, 2024
1 parent 237072a commit 6afe77e
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 13 deletions.
2 changes: 1 addition & 1 deletion addon/components/permission-picker.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<a href="javascript:;" class="ml-2 text-xs text-blue-500 hover:opacity-50" {{on "click" this.toggleSelected}}>Toggle Selected</a>
</div>
</div>
<div class="text-sm dark:text-gray-100">
<div class="text-xs dark:text-gray-100">
{{t "iam.components.permission-picker.selected"}}
{{this.selected.length}}
</div>
Expand Down
15 changes: 14 additions & 1 deletion addon/routes/groups.js
Original file line number Diff line number Diff line change
@@ -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');
}
}
}
9 changes: 1 addition & 8 deletions addon/routes/home.js
Original file line number Diff line number Diff line change
@@ -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 {}
15 changes: 14 additions & 1 deletion addon/routes/policies.js
Original file line number Diff line number Diff line change
@@ -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');
}
}
}
15 changes: 14 additions & 1 deletion addon/routes/roles.js
Original file line number Diff line number Diff line change
@@ -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');
}
}
}
15 changes: 14 additions & 1 deletion addon/routes/users.js
Original file line number Diff line number Diff line change
@@ -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');
}
}
}

0 comments on commit 6afe77e

Please sign in to comment.