emailengine-app 2.78.0 → 2.79.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.ncurc.js +23 -13
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +29 -0
- package/config/e2e.toml +2 -1
- package/config/test.toml +2 -1
- package/data/google-crawlers.json +1 -1
- package/lib/account.js +70 -35
- package/lib/api-reference/format.js +91 -4
- package/lib/api-reference/model.js +144 -19
- package/lib/api-reference/schema-tree.js +282 -28
- package/lib/api-routes/account-routes.js +80 -34
- package/lib/api-routes/blocklist-routes.js +21 -47
- package/lib/api-routes/chat-routes.js +10 -12
- package/lib/api-routes/delivery-test-routes.js +6 -26
- package/lib/api-routes/export-routes.js +2 -0
- package/lib/api-routes/gateway-routes.js +52 -11
- package/lib/api-routes/license-routes.js +2 -0
- package/lib/api-routes/mailbox-routes.js +29 -26
- package/lib/api-routes/message-routes.js +27 -21
- package/lib/api-routes/oauth2-app-routes.js +11 -29
- package/lib/api-routes/operation-impact.js +80 -0
- package/lib/api-routes/outbox-routes.js +15 -5
- package/lib/api-routes/permission-map.js +397 -0
- package/lib/api-routes/route-helpers.js +223 -9
- package/lib/api-routes/route-metadata.js +28 -0
- package/lib/api-routes/settings-routes.js +30 -25
- package/lib/api-routes/stats-routes.js +2 -2
- package/lib/api-routes/submit-routes.js +53 -31
- package/lib/api-routes/template-routes.js +3 -0
- package/lib/api-routes/token-routes.js +319 -33
- package/lib/api-routes/webhook-route-routes.js +14 -4
- package/lib/auth-token.js +80 -8
- package/lib/consts.js +10 -0
- package/lib/db.js +20 -2
- package/lib/delivery-error.js +30 -1
- package/lib/email-client/base-client.js +27 -41
- package/lib/email-client/gmail-client.js +19 -10
- package/lib/email-client/imap/mailbox.js +23 -24
- package/lib/email-client/imap/subconnection.js +10 -7
- package/lib/email-client/imap/sync-operations.js +46 -46
- package/lib/email-client/imap-client.js +36 -26
- package/lib/email-client/message-builder.js +3 -3
- package/lib/email-client/notification-handler.js +1 -1
- package/lib/email-client/outlook/graph-api.js +10 -4
- package/lib/email-client/outlook-client.js +53 -54
- package/lib/email-client/smtp-pool-manager.js +1 -1
- package/lib/enum-descriptions.js +92 -2
- package/lib/export.js +1 -1
- package/lib/field-usage.js +133 -0
- package/lib/gateway.js +1 -1
- package/lib/imapproxy/imap-core/lib/commands/authenticate-plain.js +3 -3
- package/lib/imapproxy/imap-core/lib/commands/id.js +2 -13
- package/lib/imapproxy/imap-core/lib/commands/starttls.js +1 -1
- package/lib/imapproxy/imap-core/lib/imap-command.js +21 -5
- package/lib/imapproxy/imap-core/lib/imap-connection.js +15 -5
- package/lib/imapproxy/imap-server.js +27 -7
- package/lib/license-beacon.js +4 -9
- package/lib/lists.js +49 -1
- package/lib/llm-pre-process.js +5 -5
- package/lib/logger.js +5 -1
- package/lib/metrics-collector.js +2 -2
- package/lib/oauth/gmail.js +9 -12
- package/lib/oauth/mail-ru.js +5 -7
- package/lib/oauth/outlook.js +9 -9
- package/lib/oauth/pubsub/google.js +25 -10
- package/lib/oauth/scope-checker.js +1 -1
- package/lib/oauth2-apps.js +223 -294
- package/lib/openapi/build-document.js +15 -7
- package/lib/openapi/joi-schema.js +20 -0
- package/lib/outbox.js +85 -17
- package/lib/pre-process.js +8 -8
- package/lib/queue-stats.js +49 -0
- package/lib/read-env-value.js +1 -1
- package/lib/reconnection-manager.js +2 -2
- package/lib/rewrite-text-nodes.js +4 -3
- package/lib/routes-ui.js +4 -0
- package/lib/schemas.js +216 -160
- package/lib/settings.js +84 -5
- package/lib/sub-script.js +2 -1
- package/lib/swagger-options.js +2 -1
- package/lib/templates.js +4 -4
- package/lib/threads.js +2 -2
- package/lib/token-audit-log.js +208 -0
- package/lib/token-permission-view.js +219 -0
- package/lib/token-permissions.js +172 -0
- package/lib/tokens.js +99 -15
- package/lib/tools.js +142 -37
- package/lib/ui-routes/account-routes.js +31 -11
- package/lib/ui-routes/admin-config-routes.js +18 -10
- package/lib/ui-routes/admin-entities-routes.js +66 -22
- package/lib/ui-routes/auth-routes.js +30 -24
- package/lib/ui-routes/export-routes.js +10 -4
- package/lib/ui-routes/oauth-config-routes.js +5 -5
- package/lib/ui-routes/reference-routes.js +3 -3
- package/lib/ui-routes/route-helpers.js +51 -2
- package/lib/ui-routes/settings-page.js +1 -1
- package/lib/ui-routes/smtp-test-routes.js +1 -1
- package/lib/ui-routes/suppression-list-routes.js +294 -0
- package/lib/ui-routes/unsubscribe-routes.js +19 -29
- package/lib/utils/network.js +2 -2
- package/lib/web-safe-html.js +1 -1
- package/lib/webhook-routing.js +80 -0
- package/lib/webhooks.js +20 -14
- package/package.json +11 -10
- package/sbom.json +1 -1
- package/server.js +80 -41
- package/static/css/flyonui.css +1 -1
- package/static/css/src/app.tailwind.css +136 -9
- package/static/js/reference.js +456 -10
- package/static/js/ui.js +43 -0
- package/static/licenses.html +51 -41
- package/translations/messages.pot +59 -59
- package/views/accounts/account.hbs +69 -7
- package/views/accounts/browse.hbs +18 -35
- package/views/config/logging.hbs +6 -0
- package/views/config/oauth/app.hbs +0 -2
- package/views/config/security.hbs +13 -0
- package/views/partials/oauth_form.hbs +0 -15
- package/views/partials/reference/disclosure.hbs +8 -2
- package/views/partials/reference/operation.hbs +47 -13
- package/views/partials/reference/params.hbs +17 -1
- package/views/partials/reference/schema-node.hbs +110 -52
- package/views/partials/reference/schema-tools.hbs +25 -0
- package/views/partials/reference/try-it.hbs +84 -11
- package/views/partials/side_menu.hbs +1 -0
- package/views/partials/ui/checkbox.hbs +2 -2
- package/views/partials/ui/tabs.hbs +7 -1
- package/views/reference/token.hbs +4 -0
- package/views/suppression-lists/index.hbs +85 -0
- package/views/suppression-lists/list.hbs +87 -0
- package/views/templates/index.hbs +8 -2
- package/views/tokens/index.hbs +31 -4
- package/views/tokens/new.hbs +324 -2
- package/workers/api.js +146 -57
- package/workers/documents.js +46 -26
- package/workers/export.js +20 -8
- package/workers/imap-proxy.js +2 -2
- package/workers/imap.js +12 -6
- package/workers/smtp.js +13 -7
- package/workers/submit.js +40 -30
- package/workers/webhooks.js +59 -25
- package/lib/feature-flags.js +0 -48
package/views/tokens/new.hbs
CHANGED
|
@@ -3,6 +3,22 @@
|
|
|
3
3
|
{{!-- the account level renders only for account-scoped tokens (ui/breadcrumb skips empty levels) --}}
|
|
4
4
|
{{> ui/breadcrumb parentHref="/admin/tokens" parentLabel="Access Tokens" midHref=(when account accountTokensLink) midLabel=account.name current="New" class="mt-6 mb-6"}}
|
|
5
5
|
|
|
6
|
+
{{!-- A token is never invalidated once minted, so one handed to a caller that reached this page
|
|
7
|
+
without authenticating would keep working - POST /admin/tokens/new refuses for that reason. The
|
|
8
|
+
form used to render anyway, so the only way to discover it was to fill it in and lose the work to
|
|
9
|
+
a 403. Same condition as the gate, so the two cannot disagree. --}}
|
|
10
|
+
{{#unless canProvision}}
|
|
11
|
+
{{#> ui/stat-card variant="error" title="Set an admin password first" icon="icon-[tabler--shield-lock]" class="mb-6"}}
|
|
12
|
+
|
|
13
|
+
<p class="mb-4">Access tokens do not expire on their own, so EmailEngine only issues one to a request
|
|
14
|
+
that carries an admin session. This instance has no admin password set, so there is no session to
|
|
15
|
+
carry - set one and the form appears here.</p>
|
|
16
|
+
<div>
|
|
17
|
+
{{> ui/btn href="/admin/account/password" variant="primary" icon="icon-[tabler--arrow-right]" label="Enable authentication"}}
|
|
18
|
+
</div>
|
|
19
|
+
|
|
20
|
+
{{/ui/stat-card}}
|
|
21
|
+
{{else}}
|
|
6
22
|
<form method="post" id="token-form" action="/admin/tokens/new">
|
|
7
23
|
<input type="hidden" name="crumb" value="{{crumb}}" />
|
|
8
24
|
<input type="hidden" id="account" name="account" value="{{values.account}}" />
|
|
@@ -32,6 +48,99 @@
|
|
|
32
48
|
<div class="text-base-content/60 code-link">["api"]</div>
|
|
33
49
|
</li>
|
|
34
50
|
|
|
51
|
+
{{!-- Nested inside the API row, not stacked in a card of its own. As two sibling
|
|
52
|
+
cards the relationship had to be asserted in prose: a reader saw "Allowed
|
|
53
|
+
scopes" and "Permissions" and had no reason to think the second was a
|
|
54
|
+
subset of one row of the first. Here the indent says it. --}}
|
|
55
|
+
<li id="permissionRow" class="p-4 hidden">
|
|
56
|
+
<div class="border-s-2 border-base-content/10 ps-4 space-y-4">
|
|
57
|
+
<div>
|
|
58
|
+
<h6 class="mb-1 font-bold">Limit what the API token can do</h6>
|
|
59
|
+
<p class="text-base-content/60 text-sm mb-3">
|
|
60
|
+
By default this token can use the whole API. Restrict it to hand out a
|
|
61
|
+
credential for a single job: an agent that reads mail but cannot delete
|
|
62
|
+
it, or a service that can only send.
|
|
63
|
+
</p>
|
|
64
|
+
|
|
65
|
+
<div id="permissionToggle">
|
|
66
|
+
{{> ui/checkbox id="permissionsEnabled" label="Restrict what this token can do" checked=values.permissionsEnabled error=errors.permissions noName=true}}
|
|
67
|
+
</div>
|
|
68
|
+
</div>
|
|
69
|
+
|
|
70
|
+
<div id="permissionSection" class="space-y-5{{#unless values.permissionsEnabled}} hidden{{/unless}}">
|
|
71
|
+
|
|
72
|
+
<div>
|
|
73
|
+
<h6 class="mb-1 font-bold">Pick a preset</h6>
|
|
74
|
+
<p class="text-base-content/60 text-sm mb-2">
|
|
75
|
+
These cover the usual shapes. Adjust the details below if you need something else.
|
|
76
|
+
</p>
|
|
77
|
+
<div class="flex flex-wrap gap-2">
|
|
78
|
+
{{#each permissionPresets}}
|
|
79
|
+
<button type="button" class="btn btn-sm btn-soft permission-preset" data-actions="{{actionList}}"
|
|
80
|
+
data-groups="{{groupList}}" title="{{title}}">{{label}}</button>
|
|
81
|
+
{{/each}}
|
|
82
|
+
</div>
|
|
83
|
+
</div>
|
|
84
|
+
|
|
85
|
+
{{!-- The whole point of the two axes is what they produce together, and a reader should
|
|
86
|
+
not have to multiply four boxes by thirteen to find out. Saying what the token
|
|
87
|
+
CANNOT do matters as much: that is the reassurance someone wants when handing out
|
|
88
|
+
a restricted credential. --}}
|
|
89
|
+
<div id="permissionOutcome" class="rounded-box border border-base-content/10 bg-base-200/40 p-4 text-sm space-y-1"></div>
|
|
90
|
+
|
|
91
|
+
{{!-- Filled in by the script below whenever a scope or an axis changes. Holding a
|
|
92
|
+
scope the permissions make unusable is legitimate, so this warns rather than
|
|
93
|
+
refuses - but it should never be a surprise. What each surface requires is
|
|
94
|
+
handed over as data, derived from the tables that enforce it, so this cannot
|
|
95
|
+
describe rules that have since changed. --}}
|
|
96
|
+
<div id="permissionScopeWarning" class="alert alert-soft alert-warning text-sm hidden"
|
|
97
|
+
data-surfaces="{{permissionSurfacesJson}}"></div>
|
|
98
|
+
|
|
99
|
+
<div>
|
|
100
|
+
<h6 class="mb-2 font-bold">What it can do</h6>
|
|
101
|
+
<ul class="divide-y divide-base-content/10 rounded-box border border-base-content/10">
|
|
102
|
+
{{#each permissionActions}}
|
|
103
|
+
<li class="flex items-center gap-2 p-4">
|
|
104
|
+
{{> ui/checkbox id=inputId label=label checked=checked noName=true dataValue=value class="permission-axis permission-action"}}
|
|
105
|
+
<div class="text-base-content/60 code-link ms-auto self-start">["{{value}}"]</div>
|
|
106
|
+
</li>
|
|
107
|
+
{{/each}}
|
|
108
|
+
</ul>
|
|
109
|
+
</div>
|
|
110
|
+
|
|
111
|
+
<div>
|
|
112
|
+
<h6 class="mb-2 font-bold">What it can reach</h6>
|
|
113
|
+
<div class="space-y-3">
|
|
114
|
+
{{#each permissionGroupClusters}}
|
|
115
|
+
<div>
|
|
116
|
+
<div class="text-base-content/60 text-xs uppercase tracking-wide mb-1">{{label}}</div>
|
|
117
|
+
<ul class="divide-y divide-base-content/10 rounded-box border border-base-content/10">
|
|
118
|
+
{{#each groups}}
|
|
119
|
+
<li class="flex items-center gap-2 p-4">
|
|
120
|
+
{{> ui/checkbox id=inputId label=label checked=checked hint=description noName=true dataValue=value class="permission-axis permission-group"}}
|
|
121
|
+
<div class="text-base-content/60 code-link ms-auto self-start">["{{value}}"]</div>
|
|
122
|
+
</li>
|
|
123
|
+
{{/each}}
|
|
124
|
+
</ul>
|
|
125
|
+
</div>
|
|
126
|
+
{{/each}}
|
|
127
|
+
</div>
|
|
128
|
+
|
|
129
|
+
{{!-- Rendered as a visibly refused option rather than omitted: leaving it out
|
|
130
|
+
entirely reads as an oversight, and the reason is the point. --}}
|
|
131
|
+
<div class="mt-3 alert alert-soft alert-warning text-sm">
|
|
132
|
+
<span class="icon-[tabler--lock] size-5 shrink-0"></span>
|
|
133
|
+
<span>
|
|
134
|
+
Some endpoints are never available to a restricted token, whatever you select here:
|
|
135
|
+
settings, OAuth2 applications, licensing, access tokens and stored account
|
|
136
|
+
credentials. A token that could reach those could grant itself more.
|
|
137
|
+
</span>
|
|
138
|
+
</div>
|
|
139
|
+
</div>
|
|
140
|
+
</div>
|
|
141
|
+
</div>
|
|
142
|
+
</li>
|
|
143
|
+
|
|
35
144
|
<li class="flex items-center gap-2 p-4">
|
|
36
145
|
<input type="checkbox" class="checkbox checkbox-sm scope-entry scope-list" id="scopesSMTP"
|
|
37
146
|
name="scopesSMTP" data-scope="smtp" {{#if values.scopesSMTP}}checked{{/if}} />
|
|
@@ -63,7 +172,9 @@
|
|
|
63
172
|
</div>
|
|
64
173
|
</form>
|
|
65
174
|
|
|
66
|
-
{{
|
|
175
|
+
{{!-- Wider than the default: the token is 64 characters and this is the only time it is shown, so
|
|
176
|
+
it has to be readable in full rather than scrolled through a 32-character window. --}}
|
|
177
|
+
{{#> ui/modal id="showToken" title="Access tokens" static=true dialogClass="max-w-2xl"}}
|
|
67
178
|
<div class="modal-body">
|
|
68
179
|
<div id="showTokenLoader" class="py-2 text-center">
|
|
69
180
|
<span class="loading loading-spinner loading-sm align-middle"></span> Generating token…
|
|
@@ -71,7 +182,11 @@
|
|
|
71
182
|
<div id="showTokenContent" class="hidden">
|
|
72
183
|
|
|
73
184
|
<div class="mb-2">Access token:</div>
|
|
74
|
-
{{
|
|
185
|
+
{{!-- w-full because ui/copy-field's join wrapper is inline-flex, so the `grow` on the input
|
|
186
|
+
has nothing to grow inside and the field kept its intrinsic width. text-sm so all 64
|
|
187
|
+
characters fit: this is the only time the value is ever shown, and a token truncated at
|
|
188
|
+
32 characters cannot be checked against what was copied. --}}
|
|
189
|
+
{{> ui/copy-field id="showTokenValue" ariaLabel="Access token" join=true class="w-full" inputClass="font-mono text-sm bg-base-200 border-0 autoselect"}}
|
|
75
190
|
|
|
76
191
|
</div>
|
|
77
192
|
<div id="showTokenError" class="hidden alert alert-soft alert-error whitespace-pre-line"></div>
|
|
@@ -86,12 +201,193 @@
|
|
|
86
201
|
|
|
87
202
|
let showTokenValueElm = document.getElementById('showTokenValue');
|
|
88
203
|
|
|
204
|
+
// The permission axes only mean anything while the restriction is on, so the whole block is
|
|
205
|
+
// hidden until then rather than shown greyed out - an axis you can read but not use invites
|
|
206
|
+
// the reading that it applies.
|
|
207
|
+
let permissionsEnabledElm = document.getElementById('permissionsEnabled');
|
|
208
|
+
let permissionSectionElm = document.getElementById('permissionSection');
|
|
209
|
+
let permissionRowElm = document.getElementById('permissionRow');
|
|
210
|
+
|
|
211
|
+
// Permissions are resolved per endpoint on the REST API. Without API access there is no
|
|
212
|
+
// setting here that helps: the remaining scopes are checked once against everything their
|
|
213
|
+
// surface can do, so any restriction either changes nothing or leaves the token unable to do
|
|
214
|
+
// the one thing it was issued for. Scopes are fixed once the token exists, so the row is
|
|
215
|
+
// absent rather than disabled - and its absence needs no caption, because a section that
|
|
216
|
+
// only appears under API is self-evidently about API.
|
|
217
|
+
//
|
|
218
|
+
// "All scopes" only disables the individual boxes, it does not tick them, so the API row can
|
|
219
|
+
// be greyed while this is open. That reads correctly: API access is granted by "All", and
|
|
220
|
+
// this is how to narrow it.
|
|
221
|
+
let hasApiScope = () =>
|
|
222
|
+
Array.from(document.querySelectorAll('.scope-entry')).some(
|
|
223
|
+
elm => elm.checked && !elm.disabled && (elm.dataset.scope === '*' || elm.dataset.scope === 'api')
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
let syncPermissionSection = () => {
|
|
227
|
+
let apiScope = hasApiScope();
|
|
228
|
+
|
|
229
|
+
permissionRowElm.classList.toggle('hidden', !apiScope);
|
|
230
|
+
permissionSectionElm.classList.toggle('hidden', !apiScope || !permissionsEnabledElm.checked);
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
permissionsEnabledElm.addEventListener('change', () => {
|
|
234
|
+
// Enabling with nothing ticked would post two empty allowlists, which grant nothing. Start
|
|
235
|
+
// from everything selected so the first state is "no narrowing yet" and each untick is a
|
|
236
|
+
// deliberate subtraction.
|
|
237
|
+
if (permissionsEnabledElm.checked && !document.querySelector('.permission-axis:checked')) {
|
|
238
|
+
for (let elm of document.querySelectorAll('.permission-axis')) {
|
|
239
|
+
elm.checked = true;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
syncPermissionSection();
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
syncPermissionSection();
|
|
246
|
+
|
|
247
|
+
let permissionWarningElm = document.getElementById('permissionScopeWarning');
|
|
248
|
+
|
|
249
|
+
// Derived server-side from SCOPE_OPERATIONS and the route map rather than restated here, so a
|
|
250
|
+
// change to what a surface requires cannot leave this warning describing the old rules.
|
|
251
|
+
let surfaceRequirements = {};
|
|
252
|
+
for (let entry of JSON.parse(permissionWarningElm.dataset.surfaces || '[]')) {
|
|
253
|
+
surfaceRequirements[entry.scope] = {
|
|
254
|
+
label: entry.label,
|
|
255
|
+
actions: entry.actionList.split(',').filter(value => value),
|
|
256
|
+
groups: entry.groupList.split(',').filter(value => value)
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
let permissionOutcomeElm = document.getElementById('permissionOutcome');
|
|
260
|
+
|
|
261
|
+
let tickedLabels = selector =>
|
|
262
|
+
Array.from(document.querySelectorAll(selector))
|
|
263
|
+
.filter(elm => elm.checked)
|
|
264
|
+
.map(elm => document.querySelector('label[for="' + elm.id + '"]').textContent.trim());
|
|
265
|
+
|
|
266
|
+
let untickedLabels = selector =>
|
|
267
|
+
Array.from(document.querySelectorAll(selector))
|
|
268
|
+
.filter(elm => !elm.checked)
|
|
269
|
+
.map(elm => document.querySelector('label[for="' + elm.id + '"]').textContent.trim());
|
|
270
|
+
|
|
271
|
+
let asList = values => (values.length > 1 ? values.slice(0, -1).join(', ') + ' and ' + values[values.length - 1] : values[0] || '');
|
|
272
|
+
|
|
273
|
+
// Says what the two axes produce together. Without it a reader has to cross four boxes with
|
|
274
|
+
// thirteen to work out what they just built - and the half that reassures, what the token
|
|
275
|
+
// CANNOT do, is not visible anywhere at all.
|
|
276
|
+
let syncPermissionOutcome = () => {
|
|
277
|
+
let actions = tickedLabels('.permission-action');
|
|
278
|
+
let groups = tickedLabels('.permission-group');
|
|
279
|
+
let deniedActions = untickedLabels('.permission-action');
|
|
280
|
+
|
|
281
|
+
permissionOutcomeElm.replaceChildren();
|
|
282
|
+
|
|
283
|
+
if (!actions.length || !groups.length) {
|
|
284
|
+
let line = document.createElement('div');
|
|
285
|
+
line.className = 'text-warning';
|
|
286
|
+
line.textContent = 'Nothing is selected yet, so this token would not be able to do anything.';
|
|
287
|
+
permissionOutcomeElm.append(line);
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
let can = document.createElement('div');
|
|
292
|
+
let canLabel = document.createElement('strong');
|
|
293
|
+
canLabel.textContent = 'This token can ';
|
|
294
|
+
can.append(canLabel, document.createTextNode(asList(actions).toLowerCase() + ' in ' + asList(groups) + '.'));
|
|
295
|
+
permissionOutcomeElm.append(can);
|
|
296
|
+
|
|
297
|
+
if (deniedActions.length) {
|
|
298
|
+
let cannot = document.createElement('div');
|
|
299
|
+
cannot.className = 'text-base-content/60';
|
|
300
|
+
cannot.textContent = 'It cannot ' + asList(deniedActions).toLowerCase() + ', anywhere.';
|
|
301
|
+
permissionOutcomeElm.append(cannot);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
let rest = document.createElement('div');
|
|
305
|
+
rest.className = 'text-base-content/60';
|
|
306
|
+
rest.textContent = 'It cannot reach anything else, or read credentials and settings.';
|
|
307
|
+
permissionOutcomeElm.append(rest);
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
let syncPermissionWarning = () => {
|
|
311
|
+
if (!permissionsEnabledElm.checked || !hasApiScope()) {
|
|
312
|
+
permissionWarningElm.classList.add('hidden');
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
let selectedScopes = Array.from(document.querySelectorAll('.scope-entry'))
|
|
317
|
+
.filter(elm => elm.checked && !elm.disabled)
|
|
318
|
+
.map(elm => elm.dataset.scope);
|
|
319
|
+
|
|
320
|
+
// "All scopes" carries every surface with it
|
|
321
|
+
if (selectedScopes.includes('*')) {
|
|
322
|
+
selectedScopes = Object.keys(surfaceRequirements);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
let ticked = selector => Array.from(document.querySelectorAll(selector)).filter(elm => elm.checked).map(elm => elm.dataset.value);
|
|
326
|
+
let actions = ticked('.permission-action');
|
|
327
|
+
let groups = ticked('.permission-group');
|
|
328
|
+
|
|
329
|
+
let blocked = selectedScopes
|
|
330
|
+
.filter(scope => surfaceRequirements[scope])
|
|
331
|
+
.filter(scope => {
|
|
332
|
+
let need = surfaceRequirements[scope];
|
|
333
|
+
return !need.actions.every(value => actions.includes(value)) || !need.groups.every(value => groups.includes(value));
|
|
334
|
+
})
|
|
335
|
+
.map(scope => surfaceRequirements[scope].label);
|
|
336
|
+
|
|
337
|
+
if (!blocked.length) {
|
|
338
|
+
permissionWarningElm.classList.add('hidden');
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
permissionWarningElm.textContent =
|
|
343
|
+
'These permissions stop the token doing something its scopes allow: it will not be able to ' +
|
|
344
|
+
blocked.join(', or ') +
|
|
345
|
+
'. Untick that scope, or allow what it needs.';
|
|
346
|
+
permissionWarningElm.classList.remove('hidden');
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
for (let elm of document.querySelectorAll('.permission-axis, .scope-entry')) {
|
|
350
|
+
elm.addEventListener('change', () => {
|
|
351
|
+
syncPermissionSection();
|
|
352
|
+
syncPermissionWarning();
|
|
353
|
+
syncPermissionOutcome();
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
permissionsEnabledElm.addEventListener('change', () => {
|
|
357
|
+
syncPermissionWarning();
|
|
358
|
+
syncPermissionOutcome();
|
|
359
|
+
});
|
|
360
|
+
syncPermissionWarning();
|
|
361
|
+
syncPermissionOutcome();
|
|
362
|
+
|
|
363
|
+
for (let button of document.querySelectorAll('.permission-preset')) {
|
|
364
|
+
button.addEventListener('click', () => {
|
|
365
|
+
let actions = (button.dataset.actions || '').split(',').filter(value => value);
|
|
366
|
+
let groups = (button.dataset.groups || '').split(',').filter(value => value);
|
|
367
|
+
|
|
368
|
+
for (let elm of document.querySelectorAll('.permission-action')) {
|
|
369
|
+
elm.checked = actions.includes(elm.dataset.value);
|
|
370
|
+
}
|
|
371
|
+
for (let elm of document.querySelectorAll('.permission-group')) {
|
|
372
|
+
elm.checked = groups.includes(elm.dataset.value);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
syncPermissionWarning();
|
|
376
|
+
syncPermissionOutcome();
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
|
|
89
380
|
document.getElementById('token-form').addEventListener('submit', e => {
|
|
90
381
|
e.preventDefault()
|
|
91
382
|
|
|
92
383
|
let description = document.getElementById('description').value.trim();
|
|
93
384
|
document.getElementById('description').value = description
|
|
94
385
|
|
|
386
|
+
let collectAxis = selector =>
|
|
387
|
+
Array.from(document.querySelectorAll(selector))
|
|
388
|
+
.filter(elm => elm.checked)
|
|
389
|
+
.map(elm => elm.dataset.value);
|
|
390
|
+
|
|
95
391
|
let scopes = [];
|
|
96
392
|
let scopeElms = document.querySelectorAll('.scope-entry');
|
|
97
393
|
for (let elm of scopeElms) {
|
|
@@ -123,9 +419,34 @@
|
|
|
123
419
|
document.getElementById('showTokenError').classList.add('hidden');
|
|
124
420
|
uiModal.open('#showToken');
|
|
125
421
|
|
|
422
|
+
// Sent only when the restriction is on. Omitting the field is what "not narrowed" means on
|
|
423
|
+
// the record, so an unchecked box must not post an empty object - that is a different
|
|
424
|
+
// answer, and the API refuses it.
|
|
425
|
+
let permissions = permissionsEnabledElm.checked && hasApiScope()
|
|
426
|
+
? {
|
|
427
|
+
actions: collectAxis('.permission-action'),
|
|
428
|
+
groups: collectAxis('.permission-group')
|
|
429
|
+
}
|
|
430
|
+
: null;
|
|
431
|
+
|
|
432
|
+
// Said here rather than left to the schema. tokenPermissionsSchema refuses an empty axis
|
|
433
|
+
// too, but a joi rejection reaches this page as a bare "HTTP error! status: 400", which
|
|
434
|
+
// tells the reader nothing about the box they left unticked.
|
|
435
|
+
if (permissions && (!permissions.actions.length || !permissions.groups.length)) {
|
|
436
|
+
let missing = !permissions.actions.length ? 'action' : 'section';
|
|
437
|
+
document.getElementById('showTokenLoader').classList.add('hidden');
|
|
438
|
+
document.getElementById('showTokenContent').classList.add('hidden');
|
|
439
|
+
document.getElementById('showTokenError').classList.remove('hidden');
|
|
440
|
+
document.getElementById('showTokenError').textContent =
|
|
441
|
+
`Select at least one ${missing}. A restriction that allows nothing would create a token that cannot make any request.`;
|
|
442
|
+
uiModal.open('#showToken');
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
|
|
126
446
|
uiPostJson('/admin/tokens/new', {
|
|
127
447
|
description,
|
|
128
448
|
scopes,
|
|
449
|
+
permissions,
|
|
129
450
|
account: document.getElementById('account').value || ''
|
|
130
451
|
}).then(data => {
|
|
131
452
|
|
|
@@ -149,3 +470,4 @@
|
|
|
149
470
|
});
|
|
150
471
|
})
|
|
151
472
|
</script>
|
|
473
|
+
{{/unless}}
|