Skip to content

Commit

Permalink
implemented all permission locks in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
roncodes committed Aug 17, 2024
1 parent 1ccaeb9 commit 8c9a19d
Show file tree
Hide file tree
Showing 25 changed files with 298 additions and 275 deletions.
7 changes: 4 additions & 3 deletions addon/components/modals/group-form.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<label>
{{t "iam.components.modals.group-form.group-name"}}
</label>
<Input @value={{@options.group.name}} @type="text" class="w-full form-input" placeholder={{t "iam.components.modals.group-form.group-name"}} />
<Input @value={{@options.group.name}} @type="text" class="w-full form-input" placeholder={{t "iam.components.modals.group-form.group-name"}} disabled={{cannot @options.formPermission}} />
</div>
<div class="input-group">
<label>
{{t "iam.components.modals.group-form.group-description"}}
</label>
<Textarea @value={{@options.group.description}} rows="5" class="w-full form-input" placeholder={{t "iam.components.modals.group-form.group-description"}} />
<Textarea @value={{@options.group.description}} rows="5" class="w-full form-input" placeholder={{t "iam.components.modals.group-form.group-description"}} disabled={{cannot @options.formPermission}} />
</div>

<div class="input-group">
Expand All @@ -32,6 +32,7 @@
@infiniteScroll={{false}}
@renderInPlace={{true}}
@onChange={{@options.addUser}}
@disabled={{cannot @options.formPermission}}
as |model|
>
{{model.name}}
Expand All @@ -46,7 +47,7 @@
{{user.name}}
</span>
<span>
<a href="javascript:;" class="text-blue-300 no-underline hover:text-blue-500" {{on "click" (fn @options.removeUser user)}}>
<a href="javascript:;" class="text-blue-300 no-underline hover:text-blue-500" {{on "click" (fn @options.removeUser user)}} disabled={{cannot @options.formPermission}}>
<FaIcon @icon="times" @prefix="fas" />
</a>
</span>
Expand Down
4 changes: 3 additions & 1 deletion addon/components/modals/policy-form.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
@value={{@options.policy.name}}
@name={{t "iam.components.modals.policy-form.policy-name"}}
@placeholder={{t "iam.components.modals.policy-form.enter-name-your-policy"}}
@disabled={{cannot @options.formPermission}}
/>
<InputGroup
@value={{@options.policy.description}}
@name={{t "iam.components.modals.policy-form.policy-description"}}
@placeholder={{t "iam.components.modals.policy-form.enter-description-your-policy"}}
@disabled={{cannot @options.formPermission}}
/>
<InputGroup @name={{t "iam.components.modals.policy-form.select-permissions"}}>
<PermissionPicker @selected={{@options.policy.permissions}} @onChange={{fn (mut @options.policy.permissions)}} />
<PermissionPicker @selected={{@options.policy.permissions}} @onChange={{fn (mut @options.policy.permissions)}} @disabled={{cannot @options.formPermission}} />
</InputGroup>
</div>
</Modal::Default>
7 changes: 4 additions & 3 deletions addon/components/modals/role-form.hbs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<Modal::Default @modalIsOpened={{@modalIsOpened}} @options={{@options}} @confirm={{@onConfirm}} @decline={{@onDecline}}>
<div class="modal-body-container" ...attributes>
<InputGroup @name={{t "iam.components.modals.role-form.role-name"}} @value={{@options.role.name}} @placeholder={{t "iam.components.modals.role-form.enter-name-for-this-role"}} />
<InputGroup @name={{t "iam.components.modals.role-form.role-name"}} @value={{@options.role.name}} @placeholder={{t "iam.components.modals.role-form.enter-name-for-this-role"}} @disabled={{cannot @options.formPermission}} />
<InputGroup
@name={{t "iam.components.modals.role-form.role-description"}}
@value={{@options.role.description}}
@placeholder={{t "iam.components.modals.role-form.enter-description-your-role"}}
@disabled={{cannot @options.formPermission}}
/>
<InputGroup @name={{t "iam.common.attach-policies"}}>
<PolicyAttacher @onChange={{fn (mut @options.role.policies)}} @value={{@options.role.policies}} />
<PolicyAttacher @onChange={{fn (mut @options.role.policies)}} @value={{@options.role.policies}} @disabled={{cannot @options.formPermission}} />
</InputGroup>
<InputGroup @name={{t "iam.components.modals.role-form.select-permission"}}>
<PermissionPicker @selected={{@options.role.permissionsArray}} @onChange={{@options.setPermissions}} />
<PermissionPicker @selected={{@options.role.permissionsArray}} @onChange={{@options.setPermissions}} @disabled={{cannot @options.formPermission}} />
</InputGroup>
</div>
</Modal::Default>
22 changes: 13 additions & 9 deletions addon/components/modals/user-form.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@
<div class="flex">
<div class="w-32 mb-6 mr-6">
<Image src={{@options.user.avatar_url}} @fallbackSrc={{config "defaultValues.userImage"}} alt={{@options.user.name}} height="128" width="128" class="h-32 w-32 rounded-md" />
<UploadButton @name={{t "iam.common.photo"}} @accept="image/*" @onFileAdded={{@options.uploadNewPhoto}} class="w-32" />
<UploadButton @name={{t "iam.common.photo"}} @accept="image/*" @onFileAdded={{@options.uploadNewPhoto}} @disabled={{cannot @options.formPermission}} class="w-32" />
</div>
<div class="flex-1">
<div class="grid grid-cols-2 gap-2 text-xs dark:text-gray-100 mb-2">
<InputGroup @name={{t "iam.common.name"}} @value={{@options.user.name}} />
<InputGroup @name={{t "iam.common.email"}} @type="email" @value={{@options.user.email}} />
<InputGroup @name={{t "iam.common.name"}} @value={{@options.user.name}} @disabled={{cannot @options.formPermission}} />
<InputGroup @name={{t "iam.common.email"}} @type="email" @value={{@options.user.email}} @disabled={{cannot @options.formPermission}} />
<InputGroup @name={{t "iam.common.phone"}}>
<PhoneInput @value={{@options.user.phone}} @onInput={{fn (mut @options.user.phone)}} class="form-input w-full" />
<PhoneInput @value={{@options.user.phone}} @onInput={{fn (mut @options.user.phone)}} disabled={{cannot @options.formPermission}} class="form-input w-full" />
</InputGroup>
<InputGroup @name={{t "iam.common.country"}}>
<CountrySelect
class="w-full form-input form-select form-datalist"
@value={{@options.user.country}}
@onChange={{fn (mut @options.user.country)}}
@disabled={{cannot @options.formPermission}}
placeholder={{t "iam.common.country"}}
/>
</InputGroup>
Expand All @@ -29,17 +30,20 @@
@infiniteScroll={{false}}
@renderInPlace={{true}}
@onChange={{fn (mut @options.user.role)}}
@disabled={{cannot @options.formPermission}}
as |model|
>
{{model.name}}
</ModelSelect>
</InputGroup>
</div>
<div>
<InputGroup @name={{t "iam.common.select-permissions"}}>
<PermissionPicker @selected={{@options.user.permissions}} @onChange={{fn (mut @options.user.permissions)}} />
</InputGroup>
</div>
{{#if (can @options.formPermission)}}
<div>
<InputGroup @name={{t "iam.common.select-permissions"}}>
<PermissionPicker @selected={{@options.user.permissions}} @onChange={{fn (mut @options.user.permissions)}} />
</InputGroup>
</div>
{{/if}}
</div>
</div>
</div>
Expand Down
7 changes: 4 additions & 3 deletions addon/components/permission-picker.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
{{on "input" (perform this.search)}}
placeholder={{t "iam.components.permission-picker.search-permissions-keyword"}}
class="w-64 form-input form-input-sm"
disabled={{@disabled}}
/>
</div>
<div>
Expand All @@ -26,7 +27,7 @@
<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="flex items-center">
<Checkbox @value={{this.allSelected}} @onToggle={{this.selectAll}} @disabled={{not this.permissions}} />
<Checkbox @value={{this.allSelected}} @onToggle={{this.selectAll}} @disabled={{or @disabled (not this.permissions)}} />
</div>
<div class="col-span-5 flex items-center">{{t "iam.common.permission"}}</div>
<div class="col-span-6 flex items-center">{{t "iam.common.description"}}</div>
Expand All @@ -42,9 +43,9 @@
</div>
{{/unless}}
{{#each this.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="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 {{if @disabled 'opacity-50'}}">
<div class="flex items-center">
<Checkbox @value={{permission.selected}} @onToggle={{fn this.selectPermission permission}} />
<Checkbox @value={{permission.selected}} @onToggle={{fn this.selectPermission permission}} @disabled={{@disabled}} />
</div>
<div class="col-span-5 flex items-center truncate">{{permission.name}}</div>
<div class="col-span-6 flex items-center truncate text-xs">{{permission.description}}</div>
Expand Down
2 changes: 1 addition & 1 deletion addon/components/permission-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { inject as service } from '@ember/service';
import { action, computed } from '@ember/object';
import { isArray } from '@ember/array';
import { isBlank } from '@ember/utils';
import { task } from 'ember-concurrency-decorators';
import { task } from 'ember-concurrency';

export default class PermissionPickerComponent extends Component {
/**
Expand Down
5 changes: 3 additions & 2 deletions addon/components/policy-attacher.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@
@renderInPlace={{true}}
@onChange={{this.selectPolicy}}
@query={{hash sort="name"}}
@disabled={{@disabled}}
as |model|
>
{{model.name}}
</ModelSelect>

{{#if this.selected}}
<div class="flex flex-row bg-white dark:bg-gray-900 border border-gray-200 dark:border-gray-700 rounded-md shadow-sm p-2 mt-4 space-x-2">
<div class="flex flex-row bg-white dark:bg-gray-900 border border-gray-200 dark:border-gray-700 rounded-md shadow-sm p-2 mt-4 space-x-2 {{if @disabled 'opacity-50'}}">
{{#each this.selected as |policy|}}
<Badge @hideStatusDot={{true}} @status="info" class="flex flex-row items-center">
<div class="mr-2">{{policy.name}}</div>
<Button @icon="trash" @size="xs" @type="link" @onClick={{fn this.removePolicy policy}} class="hover:opacity-50" />
<Button @icon="trash" @size="xs" @type="link" @onClick={{fn this.removePolicy policy}} @disabled={{@disabled}} class="hover:opacity-50" />
</Badge>
{{/each}}
</div>
Expand Down
2 changes: 1 addition & 1 deletion addon/components/table/cell/user-name.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="relative flex items-center">
<img src={{@row.avatar_url}} alt={{@row.name}} class="w-6 h-6 rounded-md {{if @column.hasOnline 'mx-2' 'mr-2'}}" />
<span class="relative block">
<a href="javascript:;" class="relative block" {{on "click" this.onClick}}>
<a href="javascript:;" class="relative block" {{on "click" this.onClick}} disabled={{and @column.permission (cannot @column.permission)}}>
{{#if (has-block)}}
{{yield}}
{{else}}
Expand Down
19 changes: 19 additions & 0 deletions addon/components/widget/iam-metrics.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<div class="iam-metrics" ...attributes>
<div class="flex flex-col">
<div class="flex flex-row items-center justify-between px-4 py-2 border dark:border-gray-700 border-gray-200 dark:bg-gray-800 bg-gray-50 rounded-lg shadow-sm">
<span class="text-base font-bold text-black dark:text-gray-100">{{t "iam.components.widget.metrics.title"}}</span>
</div>

<div class="mt-4">
{{#if this.getIamMetrics.isRunning}}
<Spinner />
{{else}}
<div class="grid grid-cols-2 lg:grid-cols-8 gap-4">
{{#each-in this.metrics as |title count|}}
<Widget::Count @title={{smart-humanize title}} @value={{count}} class="lg:col-span-2 h-full" />
{{/each-in}}
</div>
{{/if}}
</div>
</div>
</div>
49 changes: 49 additions & 0 deletions addon/components/widget/iam-metrics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { inject as service } from '@ember/service';
import { task } from 'ember-concurrency';

export default class WidgetIamMetricsComponent extends Component {
/**
* The widget ID to use for registering.
*
* @memberof WidgetIamMetricsComponent
*/
static widgetId = 'iam-metrics-widget';

/**
* Inject the fetch service.
*
* @memberof WidgetKeyMetricsComponent
*/
@service fetch;

/**
* Property for loading metrics to.
*
* @memberof WidgetKeyMetricsComponent
*/
@tracked metrics = {};

/**
* Creates an instance of WidgetKeyMetricsComponent.
* @memberof WidgetKeyMetricsComponent
*/
constructor() {
super(...arguments);
this.getIamMetrics.perform();
}

/**
* Task which fetches key metrics.
*
* @memberof WidgetKeyMetricsComponent
*/
@task *getIamMetrics() {
try {
this.metrics = yield this.fetch.get('metrics/iam');
} catch (error) {
this.notifications.serverError(error);
}
}
}
Loading

0 comments on commit 8c9a19d

Please sign in to comment.