emailengine-app 2.79.9 → 2.80.1
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/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +73 -0
- package/README.md +6 -0
- package/config/default.toml +5 -1
- package/data/google-crawlers.json +1 -1
- package/encrypt.js +43 -0
- package/lib/account/account-state.js +62 -0
- package/lib/account.js +34 -2
- package/lib/api-routes/account-routes.js +101 -1
- package/lib/api-routes/blocklist-routes.js +24 -0
- package/lib/api-routes/delivery-test-routes.js +6 -0
- package/lib/api-routes/gateway-routes.js +30 -0
- package/lib/api-routes/index.js +1 -1
- package/lib/api-routes/license-routes.js +10 -0
- package/lib/api-routes/mcp-oauth-routes.js +3 -3
- package/lib/api-routes/mcp-routes.js +39 -21
- package/lib/api-routes/oauth2-app-routes.js +38 -1
- package/lib/api-routes/outbox-routes.js +6 -0
- package/lib/api-routes/permission-map.js +208 -43
- package/lib/api-routes/pubsub-routes.js +8 -0
- package/lib/api-routes/route-helpers.js +58 -11
- package/lib/api-routes/settings-routes.js +67 -6
- package/lib/api-routes/stats-routes.js +6 -0
- package/lib/api-routes/template-routes.js +21 -0
- package/lib/api-routes/token-routes.js +34 -2
- package/lib/api-routes/webhook-route-routes.js +13 -0
- package/lib/autodetect-imap-settings.js +349 -47
- package/lib/cert-handler.js +62 -0
- package/lib/consts.js +50 -6
- package/lib/db.js +12 -0
- package/lib/egress-fetch.js +21 -9
- package/lib/email-client/base-client.js +238 -67
- package/lib/email-client/credential-errors.js +122 -0
- package/lib/email-client/gmail/gmail-api.js +2 -1
- package/lib/email-client/gmail-client.js +70 -64
- package/lib/email-client/imap/connection-errors.js +52 -0
- package/lib/email-client/imap/listing-diff.js +47 -6
- package/lib/email-client/imap/login-failure.js +52 -0
- package/lib/email-client/imap/mailbox.js +457 -379
- package/lib/email-client/imap/subconnection.js +17 -12
- package/lib/email-client/imap/sync-operations.js +46 -59
- package/lib/email-client/imap-client.js +139 -101
- package/lib/email-client/message-builder.js +11 -11
- package/lib/email-client/outlook/graph-api.js +2 -1
- package/lib/email-client/outlook-client.js +219 -106
- package/lib/enum-descriptions.js +12 -2
- package/lib/imap-proxy-auth.js +58 -3
- package/lib/imapproxy/imap-server.js +53 -62
- package/lib/lua/h-del-if-equals.lua +39 -0
- package/lib/lua/h-set-if-equals.lua +39 -0
- package/lib/mcp/oauth.js +46 -8
- package/lib/mcp/protocol.js +78 -35
- package/lib/mcp/tools.js +53 -17
- package/lib/privileged-settings.js +147 -0
- package/lib/routes-ui.js +4 -34
- package/lib/schemas.js +92 -16
- package/lib/security-headers.js +15 -0
- package/lib/settings.js +13 -0
- package/lib/tls/catalog.js +428 -0
- package/lib/tls/context.js +302 -0
- package/lib/tls/der.js +223 -0
- package/lib/tls/listeners.js +62 -0
- package/lib/tls/provision.js +555 -0
- package/lib/tls/self-signed.js +282 -0
- package/lib/tls/status.js +480 -0
- package/lib/tls/store.js +667 -0
- package/lib/token-permission-view.js +252 -102
- package/lib/token-permissions.js +176 -26
- package/lib/tokens.js +7 -6
- package/lib/tools.js +73 -27
- package/lib/ui-routes/account-routes.js +43 -30
- package/lib/ui-routes/admin-config-routes.js +63 -22
- package/lib/ui-routes/admin-entities-routes.js +23 -13
- package/lib/ui-routes/auth-routes.js +16 -1
- package/lib/ui-routes/internals-routes.js +3 -5
- package/lib/ui-routes/mcp-consent-routes.js +72 -31
- package/lib/ui-routes/network-config-routes.js +54 -45
- package/lib/ui-routes/tls-config-routes.js +628 -0
- package/lib/utils/mailbox-path.js +51 -0
- package/lib/utils/severity.js +31 -0
- package/package.json +12 -12
- package/sbom.json +1 -1
- package/server.js +23 -1
- package/static/css/flyonui.css +1 -1
- package/static/css/src/app.tailwind.css +11 -0
- package/static/js/app.js +34 -0
- package/static/js/public.js +6 -2
- package/static/js/ui.js +97 -61
- package/static/licenses.html +341 -1252
- package/translations/messages.pot +62 -56
- package/views/account/login-redirect.hbs +22 -0
- package/views/account/passkeys.hbs +2 -2
- package/views/accounts/account.hbs +2 -2
- package/views/accounts/browse.hbs +1 -1
- package/views/accounts/edit.hbs +1 -1
- package/views/accounts/register/imap-server.hbs +1 -1
- package/views/config/ai.hbs +1 -1
- package/views/config/branding.hbs +2 -2
- package/views/config/document-store/chat.hbs +1 -1
- package/views/config/document-store/index.hbs +1 -1
- package/views/config/imap-proxy.hbs +1 -4
- package/views/config/license.hbs +1 -1
- package/views/config/mcp.hbs +88 -52
- package/views/config/network.hbs +1 -1
- package/views/config/oauth/app.hbs +2 -2
- package/views/config/service.hbs +1 -1
- package/views/config/smtp.hbs +1 -4
- package/views/config/tls-upload.hbs +81 -0
- package/views/config/tls.hbs +593 -0
- package/views/config/webhooks.hbs +2 -2
- package/views/internals/index.hbs +1 -1
- package/views/layout/app.hbs +6 -6
- package/views/layout/login.hbs +5 -5
- package/views/layout/main.hbs +2 -2
- package/views/layout/prompt.hbs +3 -3
- package/views/layout/public.hbs +1 -1
- package/views/mcp/authorize.hbs +47 -45
- package/views/partials/ace_assets.hbs +1 -1
- package/views/partials/add_account_modal.hbs +1 -1
- package/views/partials/filter_editor_js.hbs +2 -2
- package/views/partials/gateway_js.hbs +1 -1
- package/views/partials/mcp_access_levels.hbs +16 -9
- package/views/partials/mcp_tool_count.hbs +15 -14
- package/views/partials/oauth_form.hbs +1 -1
- package/views/partials/public_theme_init.hbs +1 -1
- package/views/partials/side_menu.hbs +1 -0
- package/views/partials/template_form.hbs +1 -1
- package/views/partials/theme_init.hbs +1 -1
- package/views/partials/tls_security_card.hbs +25 -53
- package/views/partials/ui/alert-banner.hbs +3 -2
- package/views/partials/ui/badge.hbs +6 -2
- package/views/partials/ui/btn.hbs +5 -2
- package/views/partials/webhooks_editor_functions.hbs +1 -1
- package/views/reference/index.hbs +1 -1
- package/views/reference/redirect.hbs +1 -1
- package/views/reference/tag.hbs +1 -1
- package/views/reference/token.hbs +1 -1
- package/views/templates/template.hbs +1 -1
- package/views/tokens/new.hbs +175 -74
- package/views/unsubscribe.hbs +1 -1
- package/views/webhooks/webhook.hbs +1 -1
- package/workers/api.js +102 -142
- package/workers/imap-proxy.js +4 -1
- package/workers/smtp.js +51 -44
- package/views/partials/tls_security_js.hbs +0 -64
- package/views/partials/tls_security_modal.hbs +0 -22
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
// label here would render as a blank checkbox, and one removed would leave a control that posts a
|
|
9
9
|
// value the API refuses.
|
|
10
10
|
|
|
11
|
-
const { ACTION, GROUP, GRANTABLE_GROUPS, SURFACE_GRANTS, PER_REQUEST_SURFACES } = require('./api-routes/permission-map');
|
|
11
|
+
const { ACTION, GROUP, GRANTABLE_GROUPS, IMPLICIT_GROUPS, SURFACE_GRANTS, PER_REQUEST_SURFACES, MCP_SCOPES } = require('./api-routes/permission-map');
|
|
12
12
|
const tokenPermissions = require('./token-permissions');
|
|
13
13
|
const { ENUM_DESCRIPTIONS } = require('./enum-descriptions');
|
|
14
14
|
|
|
15
15
|
// Sentence-case labels for the checkbox rows. The slug itself is shown beside each one, so this only
|
|
16
16
|
// has to read well - it is not the identifier. The same labels are also lowercased into running
|
|
17
|
-
// prose (
|
|
17
|
+
// prose (the grant wording of the MCP access levels below), so each one has to work as a sentence fragment too.
|
|
18
18
|
const ACTION_LABELS = {
|
|
19
19
|
[ACTION.READ]: 'Read',
|
|
20
20
|
[ACTION.WRITE]: 'Create and modify',
|
|
@@ -35,27 +35,47 @@ const GROUP_LABELS = {
|
|
|
35
35
|
[GROUP.GATEWAY]: 'SMTP gateways',
|
|
36
36
|
[GROUP.EVENTS]: 'Change stream',
|
|
37
37
|
[GROUP.DIAGNOSTICS]: 'Statistics and status',
|
|
38
|
-
[GROUP.LOGS]: 'Connection logs'
|
|
38
|
+
[GROUP.LOGS]: 'Connection logs',
|
|
39
|
+
[GROUP.SETTINGS]: 'Instance settings',
|
|
40
|
+
[GROUP.OAUTH2]: 'OAuth2 applications',
|
|
41
|
+
[GROUP.LICENSE]: 'License',
|
|
42
|
+
[GROUP.TOKEN]: 'Access tokens',
|
|
43
|
+
[GROUP.PROVISIONING]: 'Account and gateway setup'
|
|
39
44
|
};
|
|
40
45
|
|
|
41
46
|
// The one spelling of the slug-to-label lookup. Object.hasOwn rather than a bare lookup: a slug
|
|
42
47
|
// of `constructor` would otherwise render an Object.prototype member.
|
|
43
48
|
const mapLabels = (values, labels) => values.map(value => (Object.hasOwn(labels, value) ? labels[value] : value));
|
|
44
49
|
|
|
50
|
+
// The `action:group` spelling of a pair, for keyed lookups and the browser-side lists
|
|
51
|
+
const grantKey = grant => `${grant.action}:${grant.group}`;
|
|
52
|
+
|
|
45
53
|
// The same vocabulary as a sentence fragment: lowercased and joined as an English list, for
|
|
46
54
|
// prose like the consent screen's grant sentences ("read, create and modify, and send email").
|
|
47
55
|
const GRANT_LIST_FORMAT = new Intl.ListFormat('en', { style: 'long', type: 'conjunction' });
|
|
48
56
|
const humanGrantList = (values, labels) => GRANT_LIST_FORMAT.format(mapLabels(values, labels).map(word => word.toLowerCase()));
|
|
49
57
|
|
|
50
|
-
// Clusters for the section list.
|
|
51
|
-
// and the split is the one a reader already has: the mail itself, the things that act on it,
|
|
52
|
-
// things that only watch.
|
|
58
|
+
// Clusters for the section list. Eighteen rows at identical weight is a scan rather than a choice,
|
|
59
|
+
// and the split is the one a reader already has: the mail itself, the things that act on it, the
|
|
60
|
+
// things that only watch, and the instance underneath all of it.
|
|
53
61
|
const GROUP_CLUSTERS = [
|
|
54
62
|
{ label: 'Mail', groups: [GROUP.ACCOUNT, GROUP.MAILBOX, GROUP.MESSAGE, GROUP.SUBMIT, GROUP.OUTBOX, GROUP.EXPORT] },
|
|
55
63
|
{ label: 'Configuration', groups: [GROUP.TEMPLATE, GROUP.BLOCKLIST, GROUP.WEBHOOK, GROUP.GATEWAY] },
|
|
56
|
-
{ label: 'Monitoring', groups: [GROUP.EVENTS, GROUP.DIAGNOSTICS, GROUP.LOGS] }
|
|
64
|
+
{ label: 'Monitoring', groups: [GROUP.EVENTS, GROUP.DIAGNOSTICS, GROUP.LOGS] },
|
|
65
|
+
{ label: 'Instance', groups: [GROUP.SETTINGS, GROUP.PROVISIONING, GROUP.OAUTH2, GROUP.TOKEN, GROUP.LICENSE] }
|
|
57
66
|
];
|
|
58
67
|
|
|
68
|
+
// How the token list names the sections an absent `groups` axis reaches (IMPLICIT_GROUPS): by
|
|
69
|
+
// what it leaves out, because that is the interesting part. The difference is rendered as the
|
|
70
|
+
// cluster heading the token form shows when it is exactly one cluster, and as the section labels
|
|
71
|
+
// otherwise, so a section added outside the implicit set changes the wording rather than hiding
|
|
72
|
+
// behind a heading that no longer covers it.
|
|
73
|
+
const IMPLICIT_GROUPS_LABEL = (() => {
|
|
74
|
+
const left = GRANTABLE_GROUPS.filter(group => !IMPLICIT_GROUPS.includes(group));
|
|
75
|
+
const cluster = GROUP_CLUSTERS.find(entry => entry.groups.length === left.length && entry.groups.every(group => left.includes(group)));
|
|
76
|
+
return `every section except ${cluster ? cluster.label : GRANT_LIST_FORMAT.format(mapLabels(left, GROUP_LABELS))}`;
|
|
77
|
+
})();
|
|
78
|
+
|
|
59
79
|
// Starting points, because a fourteen-row matrix is not how anyone begins. Each is a real shape
|
|
60
80
|
// somebody asks for rather than an illustration of the axes.
|
|
61
81
|
const PRESETS = [
|
|
@@ -87,7 +107,7 @@ const PRESETS = [
|
|
|
87
107
|
},
|
|
88
108
|
{
|
|
89
109
|
label: 'Everything allowed',
|
|
90
|
-
title: 'Every action on every section that can be granted. Still cannot
|
|
110
|
+
title: 'Every action on every section that can be granted. Still cannot create tokens or read stored credentials',
|
|
91
111
|
actions: Object.values(ACTION),
|
|
92
112
|
groups: GRANTABLE_GROUPS
|
|
93
113
|
}
|
|
@@ -99,78 +119,171 @@ const SURFACE_LABELS = {
|
|
|
99
119
|
smtp: 'send over SMTP',
|
|
100
120
|
'imap-proxy': 'connect through the IMAP proxy',
|
|
101
121
|
metrics: 'read the metrics endpoint',
|
|
102
|
-
mcp: 'call MCP tools'
|
|
122
|
+
'mcp-manage': 'call the MCP management tools',
|
|
123
|
+
mcp: 'call the MCP mail tools'
|
|
103
124
|
};
|
|
104
125
|
|
|
105
|
-
// The
|
|
106
|
-
//
|
|
107
|
-
//
|
|
108
|
-
//
|
|
109
|
-
//
|
|
126
|
+
// The MCP access levels: what the OAuth consent prompt, the MCP config page's generator and the
|
|
127
|
+
// token form offer, and what each choice mints. Two sections, because the endpoint has two tool
|
|
128
|
+
// sets behind two scopes and a person approving an agent decides about them separately -
|
|
129
|
+
// managing the instance is the default question, mailbox contents the opt-in one. Each level is
|
|
130
|
+
// a pair list rather than a two-axis record: one token can hold a management level and a mail
|
|
131
|
+
// level at once, and the cross product of two axes cannot keep "operate the instance" from
|
|
132
|
+
// leaking write access onto the messages. Derived once at load from the surface tables the
|
|
133
|
+
// enforcement reads, nothing else; lives here because this module owns how permission records
|
|
134
|
+
// are presented, and a second derivation had already drifted once.
|
|
110
135
|
//
|
|
111
|
-
//
|
|
112
|
-
//
|
|
113
|
-
//
|
|
114
|
-
//
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
};
|
|
136
|
+
// A section is declined with the `none` level, which every section has and which mints nothing:
|
|
137
|
+
// one value per section, so no page has to carry "is this section on" beside the level. The
|
|
138
|
+
// consent prompt and the generator offer it as a radio; the token form declines a section by
|
|
139
|
+
// leaving its scope unticked and offers the other levels only.
|
|
140
|
+
//
|
|
141
|
+
// A minted token always carries the pair list of the levels approved, never an absent record:
|
|
142
|
+
// a consent given for the tools of today must not grow to include a tool shipped next release.
|
|
143
|
+
const pairsOf = (scope, predicate) => SURFACE_GRANTS[scope].filter(predicate).map(grant => ({ action: grant.action, group: grant.group }));
|
|
119
144
|
|
|
120
|
-
//
|
|
121
|
-
//
|
|
122
|
-
//
|
|
123
|
-
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
145
|
+
// Everything a level carries: `caveat` is the sentence the consent prompt shows under the derived
|
|
146
|
+
// grant list - what the level still cannot do, and what it can that a reader might not expect -
|
|
147
|
+
// and `lead` on the section opens that sentence. The wording of the pairs themselves, and the
|
|
148
|
+
// alert severity, are computed onto each level below.
|
|
149
|
+
const MCP_SECTIONS = {
|
|
150
|
+
manage: {
|
|
151
|
+
scope: MCP_SCOPES.manage,
|
|
152
|
+
label: 'Instance management',
|
|
153
|
+
lead: 'Through the management tools the client will be able to',
|
|
154
|
+
defaultLevel: 'observe',
|
|
155
|
+
none: { label: 'No management access', hint: 'The client gets only what is granted below.' },
|
|
156
|
+
levels: [
|
|
157
|
+
{
|
|
158
|
+
value: 'observe',
|
|
159
|
+
label: 'Observe',
|
|
160
|
+
hint: 'Recommended. Read accounts, settings, queues, OAuth2 applications, gateways, tokens and logs. Cannot change anything.',
|
|
161
|
+
caveat: 'It cannot change anything, create tokens or read stored credentials. Connection logs name folders and subjects, and the token audit log records who read which account.',
|
|
162
|
+
// Less read/provisioning, which is only POST /v1/verifyAccount: a connection to a
|
|
163
|
+
// host the caller names, authenticated with credentials the caller supplies. The
|
|
164
|
+
// other reads that leave the instance (autodiscovery, the OAuth2 application
|
|
165
|
+
// check) go where the caller's own domain or a stored record points; this one is
|
|
166
|
+
// a port and password probe for whatever network the instance sits on, which a
|
|
167
|
+
// level sold as unable to change anything must not be. test/mcp-tools-test.js
|
|
168
|
+
// pins the pair to that one route, so the group is the whole of the exclusion.
|
|
169
|
+
pairs: pairsOf(MCP_SCOPES.manage, grant => grant.action === ACTION.READ && grant.group !== GROUP.PROVISIONING)
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
value: 'operate',
|
|
173
|
+
label: 'Operate',
|
|
174
|
+
hint: 'Also reconnect, add and test accounts, change settings, and manage OAuth2 applications, gateways and templates.',
|
|
175
|
+
caveat: 'Settings changes take effect at once, and moving the webhook target sends future message notifications, message text included, elsewhere. Reconfiguring an account or gateway can send its stored credential to a new host, and reconfiguring an OAuth2 application can redirect where future sign-ins deliver their authorization codes. It cannot delete anything, create tokens or read stored credentials.',
|
|
176
|
+
pairs: pairsOf(MCP_SCOPES.manage, grant => grant.action !== ACTION.DESTRUCTIVE)
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
value: 'administer',
|
|
180
|
+
label: 'Administer',
|
|
181
|
+
hint: 'Also delete accounts, applications, gateways and templates, revoke tokens and flush accounts.',
|
|
182
|
+
caveat: 'Everything Operate allows, plus deletion. It still cannot create tokens or read stored credentials.',
|
|
183
|
+
pairs: pairsOf(MCP_SCOPES.manage, () => true)
|
|
184
|
+
}
|
|
185
|
+
]
|
|
186
|
+
},
|
|
187
|
+
mail: {
|
|
188
|
+
scope: MCP_SCOPES.mail,
|
|
189
|
+
label: 'Email access',
|
|
190
|
+
lead: 'Through the mail tools the client will be able to',
|
|
191
|
+
defaultLevel: 'none',
|
|
192
|
+
none: {
|
|
193
|
+
label: 'No mail access',
|
|
194
|
+
hint: 'Recommended unless the client should read mail. Email content then flows into whatever model the connected client runs.'
|
|
195
|
+
},
|
|
196
|
+
levels: [
|
|
197
|
+
{
|
|
198
|
+
value: 'read',
|
|
199
|
+
label: 'Read-only',
|
|
200
|
+
hint: 'List, search and read mail - cannot send, delete or change anything.',
|
|
201
|
+
caveat: 'It cannot send email, delete anything or change anything in the mailboxes.',
|
|
202
|
+
pairs: pairsOf(MCP_SCOPES.mail, grant => grant.action === ACTION.READ)
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
value: 'mail',
|
|
206
|
+
label: 'Mail agent',
|
|
207
|
+
hint: 'Read, organize, draft and send mail - everything except the delete tool.',
|
|
208
|
+
caveat: 'Everything except the delete tool. Instructions inside received mail are a real prompt-injection risk once sending is granted.',
|
|
209
|
+
pairs: pairsOf(MCP_SCOPES.mail, grant => grant.action !== ACTION.DESTRUCTIVE)
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
value: 'full',
|
|
213
|
+
label: 'Full access',
|
|
214
|
+
hint: 'Every mail tool, including deleting messages.',
|
|
215
|
+
caveat: 'Instructions inside received mail are a real prompt-injection risk once sending is granted.',
|
|
216
|
+
pairs: pairsOf(MCP_SCOPES.mail, () => true)
|
|
217
|
+
}
|
|
218
|
+
]
|
|
219
|
+
}
|
|
127
220
|
};
|
|
128
221
|
|
|
129
|
-
// What each
|
|
130
|
-
// level
|
|
131
|
-
//
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
222
|
+
// What each level's grants mean in plain words, and how the consent prompt colours it: the
|
|
223
|
+
// narrowest level of a section is information, every wider one a warning. Computed once at load
|
|
224
|
+
// onto the level itself, so a level cannot be offered without wording.
|
|
225
|
+
for (const section of Object.values(MCP_SECTIONS)) {
|
|
226
|
+
section.levels.forEach((level, index) => {
|
|
227
|
+
level.actions = humanGrantList([...new Set(level.pairs.map(grant => grant.action))], ACTION_LABELS);
|
|
228
|
+
level.groups = humanGrantList([...new Set(level.pairs.map(grant => grant.group))], GROUP_LABELS);
|
|
229
|
+
level.variant = index ? 'warning' : 'info';
|
|
230
|
+
});
|
|
231
|
+
}
|
|
137
232
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
);
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
{
|
|
164
|
-
value
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
233
|
+
/**
|
|
234
|
+
* The level record a section offers under a name, or null for `none` and for a name it does not
|
|
235
|
+
* have. Callers that need to tell those two apart check the name first; declining is not a level.
|
|
236
|
+
*/
|
|
237
|
+
function mcpLevel(section, value) {
|
|
238
|
+
return section.levels.find(level => level.value === value) || null;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* What a choice of levels mints: the scopes of the sections that were not declined, management
|
|
243
|
+
* first, and the union of their pair lists as a permissions record.
|
|
244
|
+
*
|
|
245
|
+
* The single spelling for the three pages that mint an MCP token, so the same choice means the
|
|
246
|
+
* same credential on all of them. An unknown level throws rather than minting something narrower
|
|
247
|
+
* or wider than asked - the routes validate the level names against MCP_SECTIONS before calling
|
|
248
|
+
* this, so a throw here is a page posting a vocabulary this table does not have.
|
|
249
|
+
*
|
|
250
|
+
* @param {Object} choice - a level per section key (`manage`, `mail`); absent or 'none' declines it
|
|
251
|
+
* @returns {{scopes: Array<String>, permissions: {grants: Array}}} empty scopes when everything was declined
|
|
252
|
+
*/
|
|
253
|
+
function mcpGrantsFor(choice) {
|
|
254
|
+
const scopes = [];
|
|
255
|
+
const grants = [];
|
|
256
|
+
const seen = new Set();
|
|
257
|
+
|
|
258
|
+
for (const [key, section] of Object.entries(MCP_SECTIONS)) {
|
|
259
|
+
const value = choice && choice[key];
|
|
260
|
+
if (!value || value === 'none') {
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
const level = mcpLevel(section, value);
|
|
264
|
+
if (!level) {
|
|
265
|
+
throw new Error(`Unknown ${key} access level: ${value}`);
|
|
266
|
+
}
|
|
267
|
+
scopes.push(section.scope);
|
|
268
|
+
for (const grant of level.pairs) {
|
|
269
|
+
const pairKey = grantKey(grant);
|
|
270
|
+
if (!seen.has(pairKey)) {
|
|
271
|
+
seen.add(pairKey);
|
|
272
|
+
grants.push({ action: grant.action, group: grant.group });
|
|
273
|
+
}
|
|
274
|
+
}
|
|
172
275
|
}
|
|
173
|
-
|
|
276
|
+
|
|
277
|
+
return { scopes, permissions: { grants } };
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* The level names a section's form control may post: its levels plus `none`. The one spelling
|
|
282
|
+
* of the vocabulary the consent route validates against.
|
|
283
|
+
*/
|
|
284
|
+
function mcpLevelNames(section) {
|
|
285
|
+
return ['none'].concat(section.levels.map(level => level.value));
|
|
286
|
+
}
|
|
174
287
|
|
|
175
288
|
/**
|
|
176
289
|
* View model for the permission controls on the token form.
|
|
@@ -213,7 +326,7 @@ function formModel() {
|
|
|
213
326
|
mode: PER_REQUEST_SURFACES.has(scope) ? 'any' : 'all',
|
|
214
327
|
actionList: [...new Set(SURFACE_GRANTS[scope].map(grant => grant.action))].join(','),
|
|
215
328
|
groupList: [...new Set(SURFACE_GRANTS[scope].map(grant => grant.group))].join(','),
|
|
216
|
-
grantList: SURFACE_GRANTS[scope].map(
|
|
329
|
+
grantList: SURFACE_GRANTS[scope].map(grantKey).join(',')
|
|
217
330
|
})),
|
|
218
331
|
|
|
219
332
|
// data-actions/data-groups are read by the preset buttons in views/tokens/new.hbs
|
|
@@ -226,9 +339,10 @@ function formModel() {
|
|
|
226
339
|
};
|
|
227
340
|
}
|
|
228
341
|
|
|
229
|
-
// Phrases the two axes as something a person reads rather than as two labelled fields. An
|
|
230
|
-
//
|
|
231
|
-
// would imply a grant the record does not make.
|
|
342
|
+
// Phrases the two axes as something a person reads rather than as two labelled fields. An absent
|
|
343
|
+
// actions axis is not a restriction, so it is left out of the sentence entirely - saying "every
|
|
344
|
+
// action" would imply a grant the record does not make. (An absent groups axis IS one, and arrives
|
|
345
|
+
// here already labelled by what it leaves out.)
|
|
232
346
|
//
|
|
233
347
|
// An axis that names everything is collapsed rather than enumerated. Spelling out all thirteen
|
|
234
348
|
// sections produced a line long enough to push the table sideways, and it read as a detailed
|
|
@@ -244,7 +358,7 @@ function sentenceFor(actions, groups, coversAllActions, coversAllGroups) {
|
|
|
244
358
|
const where = coversAllGroups ? 'every section' : groups;
|
|
245
359
|
|
|
246
360
|
if (verb && where) {
|
|
247
|
-
return coversAllActions && coversAllGroups ? 'Full access, except
|
|
361
|
+
return coversAllActions && coversAllGroups ? 'Full access, except creating tokens and reading credentials' : `${verb} in ${where}`;
|
|
248
362
|
}
|
|
249
363
|
if (verb) {
|
|
250
364
|
return coversAllActions ? 'Full access' : `${verb} only`;
|
|
@@ -255,11 +369,25 @@ function sentenceFor(actions, groups, coversAllActions, coversAllGroups) {
|
|
|
255
369
|
return 'Restricted';
|
|
256
370
|
}
|
|
257
371
|
|
|
372
|
+
// An axis as labels: null for an absent axis (not a restriction), 'none' for an empty allowlist
|
|
373
|
+
// (which allows nothing, the opposite of absent), otherwise the labels in the record's order
|
|
374
|
+
const labelAxis = (values, labels) => {
|
|
375
|
+
if (!Array.isArray(values)) {
|
|
376
|
+
return null;
|
|
377
|
+
}
|
|
378
|
+
if (!values.length) {
|
|
379
|
+
return 'none';
|
|
380
|
+
}
|
|
381
|
+
return mapLabels(values, labels).join(', ');
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
const coversAll = (values, whole) => Array.isArray(values) && values.length === whole.length && whole.every(entry => values.includes(entry));
|
|
385
|
+
|
|
258
386
|
/**
|
|
259
387
|
* One-line description of what a stored `permissions` record allows, for the token list.
|
|
260
388
|
*
|
|
261
389
|
* @param {*} permissions - the record's `permissions` field
|
|
262
|
-
* @returns {Object|null} { actions, groups, unreadable } or null when the token is not narrowed
|
|
390
|
+
* @returns {Object|null} { actions, groups, sentence, unreadable } or null when the token is not narrowed
|
|
263
391
|
*/
|
|
264
392
|
function summarize(permissions) {
|
|
265
393
|
// Asked of the module that enforces it rather than re-derived here. `{}`, an unknown axis and a
|
|
@@ -276,30 +404,53 @@ function summarize(permissions) {
|
|
|
276
404
|
return { actions: null, groups: null, unreadable: true };
|
|
277
405
|
}
|
|
278
406
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
return 'none';
|
|
286
|
-
}
|
|
287
|
-
return mapLabels(values, labels).join(', ');
|
|
288
|
-
};
|
|
407
|
+
if (!Array.isArray(permissions.grants)) {
|
|
408
|
+
// The two-axis form, read out as written rather than through effectiveGrants(): an absent
|
|
409
|
+
// actions axis is not a restriction and stays out of the sentence, and an absent groups
|
|
410
|
+
// axis is what the enforcement makes of it, named by what it leaves out
|
|
411
|
+
const actions = labelAxis(permissions.actions, ACTION_LABELS);
|
|
412
|
+
const groups = labelAxis(permissions.groups, GROUP_LABELS) ?? IMPLICIT_GROUPS_LABEL;
|
|
289
413
|
|
|
290
|
-
|
|
291
|
-
|
|
414
|
+
return {
|
|
415
|
+
actions,
|
|
416
|
+
groups,
|
|
417
|
+
// One line a person can read, rather than two labelled fragments. "Can: Read / In:
|
|
418
|
+
// Messages" is the record read out loud; this is what the record means.
|
|
419
|
+
sentence: sentenceFor(actions, groups, coversAll(permissions.actions, Object.values(ACTION)), coversAll(permissions.groups, GRANTABLE_GROUPS)),
|
|
420
|
+
unreadable: false
|
|
421
|
+
};
|
|
422
|
+
}
|
|
292
423
|
|
|
293
|
-
|
|
424
|
+
// The pair-list form, through the reader the enforcement shares. A list that happens to be a
|
|
425
|
+
// full cross product is the two-axis record in another spelling and gets that record's
|
|
426
|
+
// sentence; anything else is described section by section, in declaration order rather than
|
|
427
|
+
// list order so two records granting the same pairs read the same however they were written,
|
|
428
|
+
// because "read on Messages, write on Templates" is the shape the form exists for and it has
|
|
429
|
+
// no two-axis sentence.
|
|
430
|
+
const grants = tokenPermissions.effectiveGrants(permissions);
|
|
431
|
+
const actionOrder = Object.values(ACTION);
|
|
432
|
+
const actions = actionOrder.filter(action => grants.some(grant => grant.action === action));
|
|
433
|
+
const groups = Object.values(GROUP).filter(group => grants.some(grant => grant.group === group));
|
|
294
434
|
|
|
295
|
-
|
|
296
|
-
actions,
|
|
297
|
-
groups,
|
|
298
|
-
// One line a person can read, rather than two labelled fragments. "Can: Read / In: Messages"
|
|
299
|
-
// is the record read out loud; this is what the record means.
|
|
300
|
-
sentence: sentenceFor(actions, groups, covers(permissions.actions, Object.values(ACTION)), covers(permissions.groups, GRANTABLE_GROUPS)),
|
|
435
|
+
const summary = {
|
|
436
|
+
actions: labelAxis(actions, ACTION_LABELS),
|
|
437
|
+
groups: labelAxis(groups, GROUP_LABELS),
|
|
301
438
|
unreadable: false
|
|
302
439
|
};
|
|
440
|
+
|
|
441
|
+
if (!grants.length || grants.length === actions.length * groups.length) {
|
|
442
|
+
summary.sentence = sentenceFor(summary.actions, summary.groups, coversAll(actions, actionOrder), coversAll(groups, GRANTABLE_GROUPS));
|
|
443
|
+
return summary;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
summary.sentence = groups
|
|
447
|
+
.map(group => {
|
|
448
|
+
const granted = actions.filter(action => grants.some(grant => grant.action === action && grant.group === group));
|
|
449
|
+
return `${mapLabels([group], GROUP_LABELS)[0]}: ${humanGrantList(granted, ACTION_LABELS)}`;
|
|
450
|
+
})
|
|
451
|
+
.join('; ');
|
|
452
|
+
|
|
453
|
+
return summary;
|
|
303
454
|
}
|
|
304
455
|
|
|
305
456
|
module.exports = {
|
|
@@ -307,9 +458,8 @@ module.exports = {
|
|
|
307
458
|
summarize,
|
|
308
459
|
ACTION_LABELS,
|
|
309
460
|
GROUP_LABELS,
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
MCP_GRANT_WORDING
|
|
461
|
+
MCP_SECTIONS,
|
|
462
|
+
mcpLevel,
|
|
463
|
+
mcpLevelNames,
|
|
464
|
+
mcpGrantsFor
|
|
315
465
|
};
|