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
35 changes: 22 additions & 13 deletions addon/components/modals/group-form.hbs
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
<Modal::Default @modalIsOpened={{@modalIsOpened}} @options={{@options}} @confirm={{@onConfirm}} @decline={{@onDecline}}>
<div class="modal-body-container">
<div class="text-xs dark:text-gray-100">
<div class="input-group">
<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"}} />
</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"}} />
</div>
<InputGroup
@name={{t "iam.components.modals.group-form.group-name"}}
@value={{@options.group.name}}
@placeholder={{t "iam.components.modals.group-form.group-name"}}
@disabled={{cannot @options.formPermission}}
/>
<InputGroup @name={{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}}
/>
</InputGroup>

<div class="input-group">
<div class="mb-4">
Expand All @@ -32,6 +35,7 @@
@infiniteScroll={{false}}
@renderInPlace={{true}}
@onChange={{@options.addUser}}
@disabled={{cannot @options.formPermission}}
as |model|
>
{{model.name}}
Expand All @@ -46,7 +50,12 @@
{{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
33 changes: 15 additions & 18 deletions addon/components/modals/policy-form.hbs
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
<Modal::Default @modalIsOpened={{@modalIsOpened}} @options={{@options}} @confirm={{@onConfirm}} @decline={{@onDecline}}>
<div class="modal-body-container" ...attributes>
<div class="input-group">
<label>
{{t "iam.components.modals.policy-form.policy-name"}}
</label>
<Input @value={{@options.policy.name}} @type="text" class="w-full form-input" placeholder={{t "iam.components.modals.policy-form.enter-name-your-policy"}} />
</div>
<div class="input-group">
<label>
{{t "iam.components.modals.policy-form.policy-description"}}
</label>
<Input @value={{@options.policy.description}} @type="text" class="w-full form-input" placeholder={{t "iam.components.modals.policy-form.enter-description-your-policy"}} />
</div>
<div class="input-group">
<label>
{{t "iam.components.modals.policy-form.select-permissions"}}
</label>
<PermissionPicker @selected={{@options.policy.permissions}} @onChange={{fn (mut @options.policy.permissions)}} />
</div>
<InputGroup
@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)}} @disabled={{cannot @options.formPermission}} />
</InputGroup>
</div>
</Modal::Default>
31 changes: 13 additions & 18 deletions addon/components/modals/role-form.hbs
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
<Modal::Default @modalIsOpened={{@modalIsOpened}} @options={{@options}} @confirm={{@onConfirm}} @decline={{@onDecline}}>
<div class="modal-body-container" ...attributes>
<div class="input-group">
<label>
{{t "iam.components.modals.role-form.role-name"}}
</label>
<Input @value={{@options.role.name}} @type="text" class="w-full form-input" placeholder={{t "iam.components.modals.role-form.enter-name-for-this-role"}} />
</div>
<div class="input-group">
<label>
{{t "iam.components.modals.role-form.role-description"}}
</label>
<Input @value={{@options.role.description}} @type="text" class="w-full form-input" placeholder={{t "iam.components.modals.role-form.enter-description-your-role"}} />
</div>
<div class="input-group">
<label>
{{t "iam.components.modals.role-form.select-permission"}}
</label>
<PermissionPicker @selected={{@options.role.permissionsArray}} @onChange={{@options.setPermissions}} />
</div>
<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}} @disabled={{cannot @options.formPermission}} />
</InputGroup>
<InputGroup @name={{t "iam.components.modals.role-form.select-permission"}}>
<PermissionPicker @selected={{@options.role.permissionsArray}} @onChange={{@options.setPermissions}} @disabled={{cannot @options.formPermission}} />
</InputGroup>
</div>
</Modal::Default>
61 changes: 33 additions & 28 deletions addon/components/modals/user-form.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,48 @@
<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-3 text-xs dark:text-gray-100">
<div class="input-group">
<label>
{{t "iam.common.name"}}
</label>
<Input @value={{@options.user.name}} @type="text" class="w-full form-input" placeholder={{t "iam.common.name"}} />
</div>

<div class="input-group">
<label>
{{t "iam.common.email"}}
</label>
<Input @value={{@options.user.email}} @type="text" class="w-full form-input" placeholder={{t "iam.common.email"}} />
</div>

<div class="input-group">
<label>
{{t "iam.common.phone"}}
</label>
<PhoneInput @value={{@options.user.phone}} @onInput={{fn (mut @options.user.phone)}} class="form-input w-full" />
</div>

<div class="input-group">
<label>
{{t "iam.common.country"}}
</label>
<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}} @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)}} 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"}}
/>
</div>
</InputGroup>
<InputGroup @name={{t "iam.common.role"}}>
<ModelSelect
@modelName="role"
@selectedModel={{@options.user.role}}
@placeholder={{t "iam.common.role"}}
@triggerClass="form-select form-input truncate max-w-300px"
@infiniteScroll={{false}}
@renderInPlace={{true}}
@onChange={{fn (mut @options.user.role)}}
@disabled={{cannot @options.formPermission}}
as |model|
>
{{model.name}}
</ModelSelect>
</InputGroup>
</div>
{{#if (can @options.formPermission)}}
<InputGroup @name={{t "iam.common.attach-policies"}}>
<PolicyAttacher @onChange={{fn (mut @options.user.policies)}} @value={{@options.user.policies}} @disabled={{cannot @options.formPermission}} />
</InputGroup>
<InputGroup @name={{t "iam.common.select-permissions"}}>
<PermissionPicker @selected={{@options.user.permissions}} @onChange={{fn (mut @options.user.permissions)}} />
</InputGroup>
{{/if}}
</div>
</div>
</div>
Expand Down
20 changes: 20 additions & 0 deletions addon/components/modals/view-policy-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.policy.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-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>
16 changes: 12 additions & 4 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 @@ -16,8 +17,11 @@
</div>
{{/if}}
</div>
<div>
<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 All @@ -26,7 +30,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 +46,13 @@
</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'}}
{{if (and this.showSelectedOnly (not permission.selected)) 'hidden'}}"
>
<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
Loading
Loading