Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion addon/components/api-key/tabs/overview.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<dt>{{t "developers.api-keys.panel.secret"}}</dt>
<dd class="dev-muted">{{t "developers.api-keys.panel.secret-hidden-prefix"}} <a href="javascript:;" {{on "click" this.roll}}>{{t "developers.api-keys.panel.secret-roll-link"}}</a> {{t "developers.api-keys.panel.secret-hidden-suffix"}}</dd>
<dt>{{t "developers.api-keys.drawer.scope"}}</dt>
<dd><Badge @status="gray" @text={{t "developers.api-keys.drawer.full-access"}} @size="xs" @hideStatusDot={{true}} @disableHumanize={{true}} /></dd>
<dd><Badge @status="gray" @text={{if this.apiKey.profile (t "developers.api-keys.drawer.rider-access") (t "developers.api-keys.drawer.full-access")}} @size="xs" @hideStatusDot={{true}} @disableHumanize={{true}} /></dd>
<dt>{{t "developers.component.modals.api-key-form.allowed-browser-label"}}</dt>
<dd>
{{#if this.origins.length}}
Expand Down
4 changes: 2 additions & 2 deletions addon/components/modals/api-key-form.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
<span class="dev-help">{{if options.isNew (t "developers.api-keys.form.expiration-help") (t "developers.api-keys.form.expiration-current" value=(or options.apiKey.expiresAt (t "developers.common.never")))}}</span>
</div>
<div class="dev-ig">
<label>{{t "developers.api-keys.drawer.scope"}} <Badge @status="warning" @text="v1.1" @size="xxs" @hideStatusDot={{true}} @disableHumanize={{true}} /></label>
<Select @options={{array (hash label=(t "developers.api-keys.drawer.full-access") value="full")}} @optionLabel="label" @optionValue="value" @value="full" @disabled={{true}} class="w-full form-input dev-input" />
<label>{{t "developers.api-keys.drawer.scope"}}</label>
<Select @options={{options.scopeChoices}} @optionLabel="label" @optionValue="value" @value={{or options.apiKey.profile "full"}} @onSelect={{options.setScope}} @disabled={{options.readOnly}} class="w-full form-input dev-input" />
<span class="dev-help">{{t "developers.api-keys.form.scope-help"}}</span>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions addon/models/api-credential.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default class ApiCredentialModel extends Model {
@attr('string') secret;
@attr('boolean', { defaultValue: false }) test_mode;
@attr('string') api;
@attr('string') profile;
@attr('raw') browser_origins;

/** @dates */
Expand Down
15 changes: 15 additions & 0 deletions addon/services/api-key-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ export default class ApiKeyActionsService extends ResourceActionService {
/**
* The expiration options with translated labels for a Select.
*/
get scopeChoices() {
return [
{ label: this.intl.t('developers.api-keys.drawer.full-access'), value: 'full' },
{ label: this.intl.t('developers.api-keys.drawer.rider-access'), value: 'rider' },
];
}

get expirationChoices() {
return this.expirationOptions.map((value) => ({ value, label: this.intl.t(`developers.api-keys.expiration.${value.replace(/\s+/g, '-')}`) }));
}
Expand Down Expand Up @@ -152,6 +159,10 @@ export default class ApiKeyActionsService extends ResourceActionService {
formPermission,
apiKey,
...this.originOptions(apiKey),
scopeChoices: this.scopeChoices,
setScope: (value) => {
apiKey.profile = value === 'full' ? null : value;
},
setExpiration: (value) => {
apiKey.expires_at = value || null;
},
Expand Down Expand Up @@ -225,6 +236,10 @@ export default class ApiKeyActionsService extends ResourceActionService {
formPermission,
apiKey,
...this.originOptions(apiKey),
scopeChoices: this.scopeChoices,
setScope: (value) => {
apiKey.profile = value === 'full' ? null : value;
},
setExpiration: (value) => {
apiKey.expires_at = value || null;
},
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/services/api-key-actions-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ module('Unit | Service | api-key-actions', function (hooks) {
this.owner.register('service:host-router', EmptyServiceStub);
});

test('it offers full and rider access for a key', function (assert) {
const service = this.owner.lookup('service:api-key-actions');

assert.deepEqual(
service.scopeChoices.map((choice) => choice.value),
['full', 'rider']
);
});

test('it keeps the shared dialog and transition API', function (assert) {
const service = this.owner.lookup('service:api-key-actions');

Expand Down
3 changes: 2 additions & 1 deletion translations/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ developers:
name-placeholder: What will use this key, e.g. Production backend
environment-fixed: Cannot change after creation. Create a test key for the sandbox.
expiration-help: Never · 1 hour · 24 hours · 3 days · 7 days
scope-help: Full access until scopes ship in v1.1
scope-help: Use rider access for a key inside a published rider app. It only reaches rider routes.
origins-placeholder: Add origin, e.g. https://app.example.com
environment-help: Follows the environment switch in the header.
environment-live: Live keys start with flb_live_ and read and write production data.
Expand Down Expand Up @@ -328,6 +328,7 @@ developers:
bars-label: Requests per hour over the last {days} days
scope: Scope
full-access: Full access
rider-access: Rider access
from: from
watch: Watch
channel: Channel
Expand Down