Skip to content

Commit

Permalink
more permission control implemented in ux
Browse files Browse the repository at this point in the history
  • Loading branch information
roncodes committed Aug 18, 2024
1 parent 5abd1fa commit 9202ce1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
22 changes: 9 additions & 13 deletions addon/components/modals/api-key-form.hbs
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
<Modal::Default @modalIsOpened={{@modalIsOpened}} @options={{@options}} @confirm={{@onConfirm}} @decline={{@onDecline}} as |options|>
<div class="modal-body-container">
<div class="input-group">
<label>
{{t "developers.common.name"}}
</label>
<Input
@value={{options.apiKey.name}}
@type="text"
aria-label={{t "developers.component.modals.api-key-form.api-name-aria-label"}}
class="w-full form-input"
placeholder={{t "developers.component.modals.api-key-form.name-placeholder"}}
/>
</div>
<InputGroup
@name={{t "developers.common.name"}}
@value={{options.apiKey.name}}
@placeholder={{t "developers.component.modals.api-key-form.name-placeholder"}}
@disabled={{cannot @options.formPermission}}
aria-label={{t "developers.component.modals.api-key-form.api-name-aria-label"}}
class="w-full form-input"
/>
<div class="input-group">
<InputLabel @labelText={{t "developers.component.modals.api-key-form.expiration-label"}} @helpText={{t "developers.component.modals.api-key-form.expiration-help-text"}} />

<select class="w-full mb-1 form-select" aria-label={{t "developers.component.modals.api-key-form.api-expiration-aria-label"}} {{on "change" @options.setExpiration}}>
<select class="w-full mb-1 form-select" disabled={{cannot @options.formPermission}} aria-label={{t "developers.component.modals.api-key-form.api-expiration-aria-label"}} {{on "change" @options.setExpiration}}>
<option selected disabled>
{{t "developers.component.modals.api-key-form.select-expiration-date"}}
</option>
Expand Down
1 change: 1 addition & 0 deletions addon/components/modals/rename-api-key-form.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
aria-label={{t "developers.component.modals.rename-api-key-form.api-key-label"}}
class="w-full form-input"
placeholder={{t "developers.component.modals.rename-api-key-form.api-key-placeholder"}}
disabled={{cannot @options.formPermission}}
/>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions addon/components/modals/roll-api-key-form.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<select
class="w-full mb-2 form-select form-input-sm"
aria-label={{t "developers.component.modals.roll-api-key-form.api-key-expiration-label"}}
disabled={{cannot @options.formPermission}}
{{on "change" @options.setExpiration}}
>
<option selected disabled>
Expand Down Expand Up @@ -89,6 +90,7 @@
aria-label={{t "developers.component.modals.roll-api-key-form.user-password"}}
placeholder={{t "developers.component.modals.roll-api-key-form.user-password-placeholder"}}
class="w-full form-input"
disabled={{cannot @options.formPermission}}
/>
</div>
</div>
Expand Down
6 changes: 6 additions & 0 deletions addon/controllers/api-keys/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ export default class ApiKeysIndexController extends Controller {
this.modalsManager.show('modals/rename-api-key-form', {
title: this.intl.t('developers.api-keys.index.rename-api-key-title', { apiKeyName }),
acceptButtonDisabled: this.abilities.cannot(formPermission),
acceptButtonHelpText: this.abilities.cannot(formPermission) ? this.intl.t('common.unauthorized') : null,
apiKey,
formPermission,
confirm: async modal => {
Expand Down Expand Up @@ -411,19 +413,23 @@ export default class ApiKeysIndexController extends Controller {
* @void
*/
@action rollApiKey (apiKey) {
const formPermission = 'developers roll api-key';
const apiKeyName = getWithDefault(apiKey, 'name', this.intl.t('developers.api-keys.index.untitled'));
this.modalsManager.show('modals/roll-api-key-form', {
title: this.intl.t('developers.api-keys.index.roll-api-key', { apiKeyName }),
modalClass: 'roll-key-modal',
acceptButtonText: this.intl.t('developers.api-keys.index.roll-api-key-button-text'),
acceptButtonDisabled: this.abilities.cannot(formPermission),
acceptButtonHelpText: this.abilities.cannot(formPermission) ? this.intl.t('common.unauthorized') : null,
user: this.currentUser.user,
expirationOptions: this.expirationOptions,
setExpiration: ({ target }) => {
apiKey.expires_at = target.value || null;
},
viewRequestLogs: this.viewRequestLogs,
password: null,
formPermission,
apiKey,
confirm: async modal => {
modal.startLoading();
Expand Down

0 comments on commit 9202ce1

Please sign in to comment.