Skip to content

Commit 422adae

Browse files
committed
settings/tokens: Display endpoint/crate scopes if they exist
1 parent 8399e56 commit 422adae

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-1
lines changed

app/components/settings/api-tokens.hbs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,38 @@
7171
{{token.name}}
7272
</h3>
7373

74+
{{#if (or token.endpoint_scopes token.crate_scopes)}}
75+
<div local-class="scopes">
76+
{{#if token.endpoint_scopes}}
77+
<div local-class="endpoint-scopes" data-test-endpoint-scopes>
78+
Scopes:
79+
80+
{{#each (this.listToParts token.endpoint_scopes) as |part|~}}
81+
{{#if (eq part.type "element")}}
82+
<strong>{{part.value}}<EmberTooltip @text={{this.scopeDescription part.value}} /></strong>
83+
{{~else~}}
84+
{{part.value}}
85+
{{/if}}
86+
{{~/each}}
87+
</div>
88+
{{/if}}
89+
90+
{{#if token.crate_scopes}}
91+
<div local-class="crate-scopes" data-test-crate-scopes>
92+
Crates:
93+
94+
{{#each (this.listToParts token.crate_scopes) as |part|~}}
95+
{{#if (eq part.type "element")}}
96+
<strong>{{part.value}}<EmberTooltip @text={{this.patternDescription part.value}} /></strong>
97+
{{~else~}}
98+
{{part.value}}
99+
{{/if}}
100+
{{~/each}}
101+
</div>
102+
{{/if}}
103+
</div>
104+
{{/if}}
105+
74106
<div local-class="metadata">
75107
<div title={{token.last_used_at}} local-class="last-used-at" data-test-last-used-at>
76108
{{#if token.last_used_at}}

app/components/settings/api-tokens.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,27 @@ import { tracked } from '@glimmer/tracking';
55

66
import { task } from 'ember-concurrency';
77

8+
import { patternDescription, scopeDescription } from '../../utils/token-scopes';
9+
810
export default class ApiTokens extends Component {
911
@service store;
1012
@service notifications;
1113
@service router;
1214

1315
@tracked newToken;
1416

17+
scopeDescription = scopeDescription;
18+
patternDescription = patternDescription;
19+
1520
get sortedTokens() {
1621
return this.args.tokens.filter(t => !t.isNew).sort((a, b) => (a.created_at < b.created_at ? 1 : -1));
1722
}
1823

24+
listToParts(list) {
25+
// We hardcode `en-US` here because the rest of the interface text is also currently displayed only in English.
26+
return new Intl.ListFormat('en-US').formatToParts(list);
27+
}
28+
1929
@action startNewToken(event) {
2030
if (event.altKey) {
2131
this.router.transitionTo('settings.tokens.new');

app/components/settings/api-tokens.module.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
font-weight: 500;
4040
}
4141

42+
.scopes,
4243
.metadata {
4344
composes: small from '../../styles/shared/typography.module.css';
4445

@@ -47,6 +48,10 @@
4748
}
4849
}
4950

51+
.scopes {
52+
margin-bottom: var(--space-xs);
53+
}
54+
5055
.new-token-form {
5156
padding: var(--space-m);
5257
border-radius: var(--space-3xs);
@@ -167,10 +172,15 @@
167172
display: grid;
168173
grid-template:
169174
"name actions" auto
175+
"scopes actions" auto
170176
"metadata actions" auto
171177
"details details" auto
172178
/ 1fr auto;
173179

180+
.scopes {
181+
grid-area: scopes;
182+
}
183+
174184
.metadata {
175185
grid-area: metadata;
176186
}

tests/routes/settings/tokens/new-test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ module('/settings/tokens/new', function (hooks) {
6666
assert.strictEqual(currentURL(), '/settings/tokens');
6767
assert.dom('[data-test-api-token="1"] [data-test-name]').hasText('token-name');
6868
assert.dom('[data-test-api-token="1"] [data-test-token]').hasText(token.token);
69+
assert.dom('[data-test-api-token="1"] [data-test-endpoint-scopes]').hasText('Scopes: publish-update');
70+
assert.dom('[data-test-api-token="1"] [data-test-crate-scopes]').doesNotExist();
6971
});
7072

7173
test('crate scopes', async function (assert) {
@@ -76,6 +78,7 @@ module('/settings/tokens/new', function (hooks) {
7678

7779
await fillIn('[data-test-name]', 'token-name');
7880
await click('[data-test-scope="publish-update"]');
81+
await click('[data-test-scope="yank"]');
7982

8083
assert.dom('[data-test-crates-unrestricted]').exists();
8184
assert.dom('[data-test-crate-pattern]').doesNotExist();
@@ -128,11 +131,13 @@ module('/settings/tokens/new', function (hooks) {
128131
assert.ok(Boolean(token), 'API token has been created in the backend database');
129132
assert.strictEqual(token.name, 'token-name');
130133
assert.deepEqual(token.crateScopes, ['serde-*', 'serde']);
131-
assert.deepEqual(token.endpointScopes, ['publish-update']);
134+
assert.deepEqual(token.endpointScopes, ['publish-update', 'yank']);
132135

133136
assert.strictEqual(currentURL(), '/settings/tokens');
134137
assert.dom('[data-test-api-token="1"] [data-test-name]').hasText('token-name');
135138
assert.dom('[data-test-api-token="1"] [data-test-token]').hasText(token.token);
139+
assert.dom('[data-test-api-token="1"] [data-test-endpoint-scopes]').hasText('Scopes: publish-update and yank');
140+
assert.dom('[data-test-api-token="1"] [data-test-crate-scopes]').hasText('Crates: serde-* and serde');
136141
});
137142

138143
test('loading and error state', async function (assert) {

0 commit comments

Comments
 (0)