Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.1.0 - implementing permission, policy, and role control via iam #16

Merged
merged 12 commits into from
Aug 30, 2024
Prev Previous commit
improved IAM controls
  • Loading branch information
roncodes committed Aug 30, 2024
commit 7a60575fcac5a16b05179e3b8f12a7be15b246a3
20 changes: 20 additions & 0 deletions addon/components/modals/view-role-permissions.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Modal::Default @modalIsOpened={{@modalIsOpened}} @options={{@options}} @confirm={{@onConfirm}} @decline={{@onDecline}}>
<div class="modal-body-container">
<div class="bg-white border border-gray-200 rounded shadow-sm dark:bg-gray-700 dark:border-gray-900 text-xs">
<div class="w-full dark:bg-gray-800">
<div class="grid grid-cols-12 text-xs px-3 py-1.5 font-bold text-sm text-gray-800 dark:text-gray-100 border-b border-gray-200 dark:border-gray-900 shadow">
<div class="col-span-6 flex items-center">{{t "iam.common.permission"}}</div>
<div class="col-span-6 flex items-center">{{t "iam.common.description"}}</div>
</div>
</div>
<div class="h-48 overflow-y-scroll">
{{#each @options.role.permissions as |permission|}}
<div class="grid grid-cols-12 text-xs py-2 px-3 text-gray-800 border-b border-gray-200 dark:border-gray-900 dark:text-gray-100">
<div class="col-span-6 flex items-center truncate">{{permission.name}}</div>
<div class="col-span-6 flex items-center truncate text-xs">{{permission.description}}</div>
</div>
{{/each}}
</div>
</div>
</div>
</Modal::Default>
20 changes: 20 additions & 0 deletions addon/components/modals/view-user-permissions.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Modal::Default @modalIsOpened={{@modalIsOpened}} @options={{@options}} @confirm={{@onConfirm}} @decline={{@onDecline}}>
<div class="modal-body-container">
<div class="bg-white border border-gray-200 rounded shadow-sm dark:bg-gray-700 dark:border-gray-900 text-xs">
<div class="w-full dark:bg-gray-800">
<div class="grid grid-cols-12 text-xs px-3 py-1.5 font-bold text-sm text-gray-800 dark:text-gray-100 border-b border-gray-200 dark:border-gray-900 shadow">
<div class="col-span-6 flex items-center">{{t "iam.common.permission"}}</div>
<div class="col-span-6 flex items-center">{{t "iam.common.description"}}</div>
</div>
</div>
<div class="h-48 overflow-y-scroll">
{{#each @options.user.allPermissions as |permission|}}
<div class="grid grid-cols-12 text-xs py-2 px-3 text-gray-800 border-b border-gray-200 dark:border-gray-900 dark:text-gray-100">
<div class="col-span-6 flex items-center truncate">{{permission.name}}</div>
<div class="col-span-6 flex items-center truncate text-xs">{{permission.description}}</div>
</div>
{{/each}}
</div>
</div>
</div>
</Modal::Default>
58 changes: 54 additions & 4 deletions addon/controllers/policies/index.js
Original file line number Diff line number Diff line change
@@ -15,13 +15,15 @@ export default class PoliciesIndexController extends Controller {
@service crud;
@service fetch;
@service abilities;
@service filters;
@service iam;

/**
* Queryable parameters for this controller's model
*
* @var {Array}
*/
queryParams = ['page', 'limit', 'sort', 'query', 'type', 'created_by', 'updated_by', 'status'];
queryParams = ['page', 'limit', 'sort', 'query', 'type', 'created_by', 'updated_by', 'status', 'service', 'type'];

/**
* The current page of data being viewed
@@ -51,6 +53,20 @@ export default class PoliciesIndexController extends Controller {
*/
@tracked sort = 'name';

/**
* All services for policies.
*
* @memberof PoliciesIndexController
*/
@tracked services = [];

/**
* All types of policies.
*
* @memberof PoliciesIndexController
*/
@tracked types = this.iam.schemeTypes;

/**
* All columns applicable for roles
*
@@ -70,13 +86,27 @@ export default class PoliciesIndexController extends Controller {
label: this.intl.t('iam.common.description'),
valuePath: 'description',
sortable: false,
width: '40%',
width: '35%',
},
{
label: this.intl.t('iam.common.service'),
valuePath: 'service',
sortable: false,
width: '10%',
filterable: true,
filterComponent: 'filter/select',
filterOptions: this.services,
},
{
label: this.intl.t('iam.common.type'),
valuePath: 'type',
sortable: false,
width: '20%',
width: '10%',
filterable: true,
filterComponent: 'filter/select',
filterOptionLabel: 'name',
filterOptionValue: 'id',
filterOptions: this.types,
},
{
label: this.intl.t('iam.common.create'),
@@ -95,7 +125,7 @@ export default class PoliciesIndexController extends Controller {
ddMenuLabel: this.intl.t('iam.policies.index.policy-actions'),
cellClassNames: 'overflow-visible',
wrapperClass: 'flex items-center justify-end mx-2',
width: '10%',
width: '15%',
actions: [
{
label: this.intl.t('iam.policies.index.edit-policy'),
@@ -112,6 +142,19 @@ export default class PoliciesIndexController extends Controller {
},
];

/**
* Creates an instance of PoliciesIndexController.
* @memberof PoliciesIndexController
*/
constructor() {
super(...arguments);
this.iam.getServices.perform({
onSuccess: (services) => {
this.services = services;
},
});
}

/**
* The search task.
*
@@ -285,4 +328,11 @@ export default class PoliciesIndexController extends Controller {
@action exportPolicies() {
this.crud.export('policy');
}

/**
* Reload data.
*/
@action reload() {
return this.hostRouter.refresh();
}
}
89 changes: 84 additions & 5 deletions addon/controllers/roles/index.js
Original file line number Diff line number Diff line change
@@ -12,16 +12,18 @@ export default class RolesIndexController extends Controller {
@service currentUser;
@service modalsManager;
@service hostRouter;
@service filters;
@service crud;
@service fetch;
@service abilities;
@service iam;

/**
* Queryable parameters for this controller's model
*
* @var {Array}
*/
queryParams = ['page', 'limit', 'sort', 'query'];
queryParams = ['page', 'limit', 'sort', 'query', 'service', 'type'];

/**
* The current page of data being viewed
@@ -51,6 +53,20 @@ export default class RolesIndexController extends Controller {
*/
@tracked sort = '-created_at';

/**
* All services for roles.
*
* @memberof RolesIndexController
*/
@tracked services = [];

/**
* All types of roles.
*
* @memberof RolesIndexController
*/
@tracked types = this.iam.schemeTypes;

/**
* All columns applicable for roles
*
@@ -63,20 +79,40 @@ export default class RolesIndexController extends Controller {
cellComponent: 'table/cell/anchor',
permission: 'iam view role',
onClick: this.editRole,
width: '30%',
width: '20%',
sortable: false,
},
{
label: this.intl.t('iam.common.description'),
valuePath: 'description',
sortable: false,
width: '50%',
width: '28%',
},
{
label: this.intl.t('iam.common.service'),
valuePath: 'service',
sortable: false,
width: '12%',
filterable: true,
filterComponent: 'filter/select',
filterOptions: this.services,
},
{
label: this.intl.t('iam.common.type'),
valuePath: 'type',
sortable: false,
width: '13%',
filterable: true,
filterComponent: 'filter/select',
filterOptionLabel: 'name',
filterOptionValue: 'id',
filterOptions: this.types,
},
{
label: this.intl.t('iam.common.create'),
valuePath: 'createdAt',
sortable: false,
width: '10%',
width: '12%',
tooltip: true,
cellClassNames: 'overflow-visible',
},
@@ -89,7 +125,7 @@ export default class RolesIndexController extends Controller {
ddMenuLabel: this.intl.t('iam.roles.index.role-actions'),
cellClassNames: 'overflow-visible',
wrapperClass: 'flex items-center justify-end mx-2',
width: '10%',
width: '15%',
actions: [
{
label: this.intl.t('iam.roles.index.edit-role'),
@@ -106,6 +142,19 @@ export default class RolesIndexController extends Controller {
},
];

/**
* Creates an instance of RolesIndexController.
* @memberof RolesIndexController
*/
constructor() {
super(...arguments);
this.iam.getServices.perform({
onSuccess: (services) => {
this.services = services;
},
});
}

/**
* The search task.
*
@@ -189,6 +238,10 @@ export default class RolesIndexController extends Controller {
* @void
*/
@action editRole(role, options = {}) {
if (!role.is_mutable) {
return this.viewRolePermissions(role);
}

const formPermission = 'iam update role';
this.modalsManager.show('modals/role-form', {
title: this.intl.t('iam.roles.index.edit-role-title'),
@@ -227,6 +280,10 @@ export default class RolesIndexController extends Controller {
* @void
*/
@action deleteRole(role) {
if (!role.is_deletable) {
return this.notifications.warning(this.intl.t('iam.roles.index.unable-delete-role-warning', { roleType: role.type }));
}

this.modalsManager.confirm({
title: `Delete (${role.name || 'Untitled'}) role`,
body: this.intl.t('iam.roles.index.data-assosciated-this-role-deleted'),
@@ -244,6 +301,21 @@ export default class RolesIndexController extends Controller {
});
}

/**
* View role permissions
*
* @param {RoleModel} role
* @memberof RolesIndexController
*/
@action viewRolePermissions(role) {
this.modalsManager.show('modals/view-role-permissions', {
title: this.intl.t('iam.components.modals.view-role-permissions.view-permissions', { roleName: role.name }),
hideDeclineButton: true,
acceptButtonText: this.intl.t('common.done'),
role,
});
}

/**
* Toggles dialog to export roles
*
@@ -252,4 +324,11 @@ export default class RolesIndexController extends Controller {
@action exportRoles() {
this.crud.export('role');
}

/**
* Reload data.
*/
@action reload() {
return this.hostRouter.refresh();
}
}
Loading