domma-cms 1.61.0 → 1.61.2
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/CHANGELOG.md +22 -0
- package/CLAUDE.md +1 -1
- package/docs/DommaFeatures.md +3 -1
- package/docs/cache.md +24 -0
- package/docs/configuration.md +1 -1
- package/package.json +1 -1
- package/plugins/_lib/admin/mail/body-menu.js +1 -1
- package/plugins/_lib/admin/mail/cms-host.js +1 -1
- package/plugins/_lib/admin/mail/compose-window.js +1 -1
- package/plugins/_lib/admin/mail/contacts.js +1 -1
- package/plugins/_lib/admin/mail/diagnostics-section.js +1 -1
- package/plugins/_lib/admin/mail/drag-drop.js +1 -1
- package/plugins/_lib/admin/mail/folder-tree.js +1 -1
- package/plugins/_lib/admin/mail/font-controls.js +1 -1
- package/plugins/_lib/admin/mail/fonts.js +1 -1
- package/plugins/_lib/admin/mail/host-context.js +1 -1
- package/plugins/_lib/admin/mail/identity.js +1 -1
- package/plugins/_lib/admin/mail/image-senders-section.js +1 -1
- package/plugins/_lib/admin/mail/keyboard.js +1 -1
- package/plugins/_lib/admin/mail/mail.html +1 -1
- package/plugins/_lib/admin/mail/message-actions.js +1 -1
- package/plugins/_lib/admin/mail/oauth-panel.js +1 -1
- package/plugins/_lib/admin/mail/panes.js +1 -1
- package/plugins/_lib/admin/mail/reader-kit.js +1 -1
- package/plugins/_lib/admin/mail/reader-runtime.js +27 -1
- package/plugins/_lib/admin/mail/reader-view.js +1 -1
- package/plugins/_lib/admin/mail/resizable.js +1 -1
- package/plugins/_lib/admin/mail/restore-spam.js +1 -1
- package/plugins/_lib/admin/mail/rules.js +1 -1
- package/plugins/_lib/admin/mail/scheduling.js +1 -1
- package/plugins/_lib/admin/mail/section-kit.js +1 -1
- package/plugins/_lib/admin/mail/security-note.js +1 -1
- package/plugins/_lib/admin/mail/settings-section.js +1 -1
- package/plugins/_lib/admin/mail/templates.js +1 -1
- package/plugins/_lib/admin/mail/threads.js +1 -1
- package/plugins/_lib/admin/mail/vacation.js +1 -1
- package/plugins/_lib/admin/mail/when-closed.js +1 -1
- package/plugins/_lib/admin/ui/dates.js +1 -1
- package/plugins/_lib/admin/ui/resizable.js +1 -1
- package/plugins/_lib/domma-mail.lock.json +80 -80
- package/plugins/_lib/mail/accountFileStore.js +1 -1
- package/plugins/_lib/mail/accountRepository.js +1 -1
- package/plugins/_lib/mail/accountRoutes.js +1 -1
- package/plugins/_lib/mail/bodyTokenProvider.js +1 -1
- package/plugins/_lib/mail/bodyTokens.js +1 -1
- package/plugins/_lib/mail/compose.js +1 -1
- package/plugins/_lib/mail/defaults.js +1 -1
- package/plugins/_lib/mail/envelope.js +1 -1
- package/plugins/_lib/mail/folderActions.js +1 -1
- package/plugins/_lib/mail/folderRuntime.js +1 -1
- package/plugins/_lib/mail/folders.js +1 -1
- package/plugins/_lib/mail/imapPoolRuntime.js +1 -1
- package/plugins/_lib/mail/mbox.js +1 -1
- package/plugins/_lib/mail/message-action.js +1 -1
- package/plugins/_lib/mail/messageSecurity.js +1 -1
- package/plugins/_lib/mail/messageSecurityProvider.js +1 -1
- package/plugins/_lib/mail/networkAddresses.js +1 -1
- package/plugins/_lib/mail/networkPolicy.js +1 -1
- package/plugins/_lib/mail/oauthAccounts.js +1 -1
- package/plugins/_lib/mail/oauthRouteRuntime.js +1 -1
- package/plugins/_lib/mail/oauthRuntime.js +1 -1
- package/plugins/_lib/mail/pollSchedule.js +1 -1
- package/plugins/_lib/mail/poller.js +1 -1
- package/plugins/_lib/mail/pollerRuntime.js +1 -1
- package/plugins/_lib/mail/priority.js +1 -1
- package/plugins/_lib/mail/publicMailbox.js +1 -1
- package/plugins/_lib/mail/readRuntime.js +1 -1
- package/plugins/_lib/mail/render.js +1 -1
- package/plugins/_lib/mail/ruleRunner.js +1 -1
- package/plugins/_lib/mail/schedulerRuntime.js +1 -1
- package/plugins/_lib/mail/secretProvider.js +1 -1
- package/plugins/_lib/mail/secretbox.js +1 -1
- package/plugins/_lib/mail/senderAuth.js +1 -1
- package/plugins/_lib/mail/sieve.js +1 -1
- package/plugins/_lib/mail/smtpService.js +1 -1
- package/plugins/_lib/mail/snoozeRuntime.js +1 -1
- package/plugins/_lib/mail/store.js +1 -1
- package/plugins/_lib/mail/subscriptions.js +1 -1
- package/plugins/_lib/mail/syncPlan.js +1 -1
- package/plugins/_lib/mail/syncRuntime.js +1 -1
- package/plugins/_lib/mail/syncSelection.js +1 -1
- package/plugins/_lib/mail/unreadBadge.js +1 -1
- package/plugins/_lib/mail/unsubscribe.js +1 -1
- package/plugins/_lib/mail/vacationRuntime.js +1 -1
- package/plugins/_lib/mail/write.js +1 -1
- package/plugins/docs/CHANGELOG.md +5 -0
- package/plugins/docs/CLAUDE.md +30 -0
- package/plugins/docs/admin/views/docs.js +2 -1
- package/plugins/docs/admin/views/editor.js +5 -3
- package/plugins/docs/docs/guide.md +11 -0
- package/plugins/docs/lib/store.js +46 -2
- package/plugins/docs/plugin.js +70 -28
- package/plugins/docs/plugin.json +14 -1
- package/plugins/docs/tests/restricted.test.js +240 -0
- package/plugins/free-tier.lock.json +15 -13
- package/plugins/mail-reader/CLAUDE.md +6 -0
- package/plugins/mail-reader/plugin.js +9 -0
- package/plugins/mail-reader/plugin.json +1 -1
- package/public/js/effects.js +1 -1
- package/public/js/site.js +1 -1
- package/server/config.js +37 -0
- package/server/routes/api/chats.js +3 -1
- package/server/routes/api/components.js +2 -1
- package/server/routes/api/content-api.js +1 -1
- package/server/routes/api/content-public.js +2 -2
- package/server/routes/api/content-writes.js +1 -1
- package/server/routes/api/effects.js +4 -9
- package/server/routes/api/layouts.js +1 -1
- package/server/routes/api/pages.js +6 -5
- package/server/routes/api/search.js +3 -3
- package/server/routes/api/sidebar-counts.js +2 -0
- package/server/routes/api/theme.js +2 -1
- package/server/routes/api/views.js +2 -1
- package/server/routes/public.js +4 -4
- package/server/server.js +12 -6
- package/server/services/cache/adminChange.js +28 -0
- package/server/services/content.js +73 -10
- package/server/services/effectsSettings.js +25 -0
- package/server/services/health.js +2 -2
- package/server/services/htmlResponse.js +33 -4
- package/server/services/listTags.js +1 -1
- package/server/services/markdown.js +56 -22
- package/server/services/pluginGuides.js +2 -2
- package/server/services/plugins.js +25 -2
- package/server/services/projects.js +39 -4
- package/server/services/publicAssets.js +488 -0
- package/server/services/renderer.js +10 -8
- package/server/services/seo/index.js +3 -3
- package/server/services/sitemap.js +1 -1
- package/server/services/versions.js +2 -2
- package/server/services/wpImport/index.js +2 -2
- package/server/templates/page.html +3 -2
|
@@ -279,8 +279,9 @@ export const docsEditorView = {
|
|
|
279
279
|
inTrash: M.computed(() => Boolean(current.value.trashedAt)),
|
|
280
280
|
canRestore: M.computed(() => Boolean(current.value.trashedAt) && current.value.access === 'owner'),
|
|
281
281
|
// 2.11: no Share for access that comes only through an add-on (the Wiki's editors).
|
|
282
|
+
// 2.15: none for a restricted person (own and shared documents only - the server refuses anyone new).
|
|
282
283
|
canShare: M.computed(() => (current.value.access === 'owner' || current.value.access === 'editor') && !current.value.trashedAt
|
|
283
|
-
&& !(current.value.outwardRefusal && current.value.access !== 'owner')),
|
|
284
|
+
&& !(current.value.outwardRefusal && current.value.access !== 'owner') && !current.value.restrictedUser),
|
|
284
285
|
statsText: M.computed(() => {
|
|
285
286
|
if (current.value.format === 'pdf') return [pdfFacts(current.value.file), current.value.file?.name].filter(Boolean).join(' · ') || 'PDF';
|
|
286
287
|
const {words, chars} = stats.value;
|
|
@@ -769,7 +770,7 @@ export const docsEditorView = {
|
|
|
769
770
|
const updated = await replacePdf(d, {session, host: pageEl});
|
|
770
771
|
if (updated && !disposed) { const before = current.peek(); current.value = {...before, ...updated}; showContent({...updated, _before: before}); recount(); }
|
|
771
772
|
}});
|
|
772
|
-
if (rights && !d.outwardRefusal && site.allowSend !== false) {
|
|
773
|
+
if (rights && !d.outwardRefusal && !d.restrictedUser && site.allowSend !== false) {
|
|
773
774
|
items.push({label: 'Send to', icon: 'send', submenu: [{label: 'Email…', icon: 'mail', action: () => openSendEmail({doc: d, kit, life: panelLife, publicLinksAllowed: site.publicLinks !== false})}]});
|
|
774
775
|
}
|
|
775
776
|
if (editorRights()) items.push({label: 'Version history', icon: 'clock', action: showHistory});
|
|
@@ -796,7 +797,8 @@ export const docsEditorView = {
|
|
|
796
797
|
items.push({label: 'Download', icon: 'download', submenu: exportItems(snapshot)});
|
|
797
798
|
items.push({label: 'Print or save as PDF…', icon: 'printer', action: () => exportItems(snapshot).at(-1).action()});
|
|
798
799
|
// 2.11: nothing goes out of a document that may not leave Docs now (outwardRefusal).
|
|
799
|
-
|
|
800
|
+
// 2.15: a restricted person sends nothing out of Docs (email refused by the server; page and blog are not theirs).
|
|
801
|
+
if (editorRights && !d.trashedAt && !d.outwardRefusal && !d.restrictedUser) {
|
|
800
802
|
items.push({label: 'Send to', icon: 'send', submenu: [
|
|
801
803
|
...(site.allowSend === false ? [] : [{label: 'Email…', icon: 'mail', action: async () => { const d = await snapshot(); if (!disposed) openSendEmail({doc: d, kit, life: panelLife, publicLinksAllowed: site.publicLinks !== false}); }}]),
|
|
802
804
|
{label: 'A new page…', icon: 'file-text', action: async () => sendToPage(await snapshot())},
|
|
@@ -248,6 +248,17 @@ A PDF you add is a document in Docs that happens to be a file. Docs never change
|
|
|
248
248
|
|
|
249
249
|
With the **Wiki** switched on, a document can be a wiki page (the owner adds it from its menu). People who edit the wiki can then edit the page here too, and see its history - but they cannot share it, give it a public link or send it, because they reach it through the wiki. While a wiki is for members only, nobody - its owner included - can share its pages with anyone new, link them publicly or send them. A page protected or locked in the Wiki shows a **Protected** chip and opens read only, for its owner too; hover the chip to see why.
|
|
250
250
|
|
|
251
|
+
## Own documents only
|
|
252
|
+
|
|
253
|
+
A role can be limited to its own documents. Under **System > Roles**, the permission **Docs: own documents only** (with Docs' own permissions) gives its holders Docs for writing their own documents and working on ones shared with them - and nothing more:
|
|
254
|
+
|
|
255
|
+
- They see only their own documents and the ones shared with them, whatever **Who sees documents** says, and nothing through other tools (a Wiki).
|
|
256
|
+
- There is no list of people and no **Share** - they cannot share with anyone new. A Docs administrator can still share a document with them; other people do not see them in the list of people.
|
|
257
|
+
- No public links (not even the owner's link on a document shared with them), no **Send to** (email, page or blog).
|
|
258
|
+
- With **Docs Pro**: no Spaces, cloud copies, signing screens or protected links. Another tool may still send their own document for signing - the Job Board does, for offer letters and agreements.
|
|
259
|
+
|
|
260
|
+
It changes nothing for someone who also holds a role that gives Docs without it, nor for Super Admins. The Job Board gives it to its Company and Agent roles.
|
|
261
|
+
|
|
251
262
|
## Settings
|
|
252
263
|
|
|
253
264
|
The cog on the banner opens **Docs settings**. **For everyone on this site** needs an administrator:
|
|
@@ -420,6 +420,46 @@ export async function readVersion(id, num) {
|
|
|
420
420
|
|
|
421
421
|
// ------------------------------------------------------------------- access
|
|
422
422
|
|
|
423
|
+
/**
|
|
424
|
+
* Restricted people (2.15). A role holding the permission `docs-restricted` uses Docs for its own documents and
|
|
425
|
+
* the ones shared with it, and nothing else: no site-wide reading (`scope: 'all'`), no add-on access (a Wiki), no
|
|
426
|
+
* people list, no sharing with anyone new, no public links, no email from Docs, no publishing (Docs Pro). Decided
|
|
427
|
+
* from role DATA - the role editor shows it - never from role names.
|
|
428
|
+
*
|
|
429
|
+
* A person is restricted when one of their roles holds it and none of the roles that give them Docs lacks it (the
|
|
430
|
+
* CMS grants on the union of roles: a role that opens Docs fully opens it). A level-0 role is never restricted -
|
|
431
|
+
* it holds every permission, this one included.
|
|
432
|
+
*/
|
|
433
|
+
export const RESTRICTED_PERMISSION = 'docs-restricted';
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* The rule, pure: the lookups are passed in.
|
|
437
|
+
*
|
|
438
|
+
* @param {string[]} roles - every role the person holds
|
|
439
|
+
* @param {{isRoot: (r: string) => boolean, marked: (r: string) => boolean, givesDocs: (r: string) => boolean}} look
|
|
440
|
+
* @returns {boolean}
|
|
441
|
+
*/
|
|
442
|
+
export function restrictedByRoles(roles, {isRoot, marked, givesDocs}) {
|
|
443
|
+
const list = (Array.isArray(roles) ? roles : []).filter(r => typeof r === 'string' && r);
|
|
444
|
+
if (!list.length || list.some(isRoot)) return false;
|
|
445
|
+
if (!list.some(marked)) return false;
|
|
446
|
+
return !list.some(r => givesDocs(r) && !marked(r));
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/** Does a role's permission list hold the restriction (the resource, or any action of it)? */
|
|
450
|
+
export function holdsRestriction(perms) {
|
|
451
|
+
return (Array.isArray(perms) ? perms : []).some(p => p === RESTRICTED_PERMISSION || String(p).startsWith(`${RESTRICTED_PERMISSION}.`));
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
let restrictedCheck = () => false;
|
|
455
|
+
/** plugin.js sets the check (it has the role lookups) before any route is up. */
|
|
456
|
+
export function setRestrictedCheck(fn) { restrictedCheck = typeof fn === 'function' ? fn : () => false; }
|
|
457
|
+
/** Is this person restricted? A check that throws restricts (fail closed). */
|
|
458
|
+
export function isRestricted(user) {
|
|
459
|
+
if (!user) return false;
|
|
460
|
+
try { return Boolean(restrictedCheck(user)); } catch { return true; }
|
|
461
|
+
}
|
|
462
|
+
|
|
423
463
|
/**
|
|
424
464
|
* What this user may do with a document.
|
|
425
465
|
*
|
|
@@ -441,10 +481,14 @@ export function accessOf(doc, user, isAdmin = false) {
|
|
|
441
481
|
if (!doc || !user) return null;
|
|
442
482
|
if (doc.userId === user.id) return 'owner';
|
|
443
483
|
const share = (doc.shares || []).find(s => s.userId === user.id);
|
|
444
|
-
|
|
484
|
+
// 2.15: a restricted person has their own documents and those shared with them - never the site-wide
|
|
485
|
+
// setting's, an admin's or an add-on's (a Wiki's) access, whatever the site says.
|
|
486
|
+
const restricted = isRestricted(user);
|
|
487
|
+
const siteWide = runtime.config.scope === 'all' && !restricted;
|
|
445
488
|
if (siteWide && isAdmin) return 'owner';
|
|
446
489
|
const own = share ? (share.role === 'editor' ? 'editor' : share.role === 'suggester' ? 'suggester' : 'viewer')
|
|
447
490
|
: siteWide ? 'viewer' : null;
|
|
491
|
+
if (restricted) return own;
|
|
448
492
|
// An add-on may give more (2.11): the Wiki makes its editors editors of its pages.
|
|
449
493
|
if (own === 'editor') return own;
|
|
450
494
|
const extra = extensionAccess(doc, user);
|
|
@@ -484,7 +528,7 @@ export function extensionAccess(doc, user) {
|
|
|
484
528
|
* with them.
|
|
485
529
|
*/
|
|
486
530
|
export function onlyThroughExtension(doc, user) {
|
|
487
|
-
if (!doc || !user || doc.userId === user.id || runtime.config.scope === 'all') return false;
|
|
531
|
+
if (!doc || !user || doc.userId === user.id || runtime.config.scope === 'all' || isRestricted(user)) return false;
|
|
488
532
|
if ((doc.shares || []).some(s => s.userId === user.id)) return false;
|
|
489
533
|
return Boolean(extensionAccess(doc, user));
|
|
490
534
|
}
|
package/plugins/docs/plugin.js
CHANGED
|
@@ -11,7 +11,7 @@ import {createStore} from '../_lib/dataStore.js';
|
|
|
11
11
|
import {savePluginState} from '../../server/services/plugins.js';
|
|
12
12
|
import {getEffectiveLevel, getEffectiveRoles} from '../../server/services/userRoles.js';
|
|
13
13
|
import {listUsers} from '../../server/services/users.js';
|
|
14
|
-
import {getPermissionsFor, getRoleLevel} from '../../server/services/roles.js';
|
|
14
|
+
import {getPermissionsFor, getPermissionsForRole, getRoleLevel} from '../../server/services/roles.js';
|
|
15
15
|
import {getConfig} from '../../server/config.js';
|
|
16
16
|
import {originOf, trustedOrigin} from '../../server/services/passwordReset.js';
|
|
17
17
|
import {createTransport, sendEmail} from '../../server/services/email.js';
|
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
runtime, sanitizeDoc, withoutSuggestions, allowMarkup, readDoc, writeDoc, mutateDoc, removeDoc, listDocs, newDoc, cleanTitle, shouldSnapshot,
|
|
25
25
|
snapshotVersion, listVersions, readVersion, accessOf, canEdit, stateFor, setStar, touchRecent, forgetDoc,
|
|
26
26
|
lockOf, acquireLock, releaseLock, publicLock, newLinkToken, selectRows, placeCounts, purgeTrash, validId, DATA_DIR,
|
|
27
|
-
outwardRefusal, onlyThroughExtension, frozenFor,
|
|
27
|
+
outwardRefusal, onlyThroughExtension, frozenFor, isRestricted, setRestrictedCheck, restrictedByRoles, holdsRestriction,
|
|
28
28
|
kindOf, readFileBytes, writeFileBytes, copyFileBytes, restoreVersionFile, readVersionFile, fileRecord
|
|
29
29
|
} from './lib/store.js';
|
|
30
30
|
import {importFile, kindOf as importKind} from './lib/importer.js';
|
|
@@ -138,7 +138,19 @@ export default async function docsPlugin(fastify, options) {
|
|
|
138
138
|
const make = [authenticate, need('create')];
|
|
139
139
|
const edit = [authenticate, need('update')];
|
|
140
140
|
const drop = [authenticate, need('delete')];
|
|
141
|
-
|
|
141
|
+
// 2.15: restricted people (lib/store.js) - own and shared documents only, whatever the site's settings.
|
|
142
|
+
// Tests pass `options.isRestricted`; the CMS's role data decides otherwise.
|
|
143
|
+
setRestrictedCheck(typeof options.isRestricted === 'function' ? options.isRestricted : (user) => restrictedByRoles(getEffectiveRoles(user), {
|
|
144
|
+
isRoot: (r) => getRoleLevel(r) === 0,
|
|
145
|
+
marked: (r) => holdsRestriction(getPermissionsForRole(r)),
|
|
146
|
+
givesDocs: (r) => (getPermissionsFor('docs', 'read') || []).includes(r)
|
|
147
|
+
}));
|
|
148
|
+
/** An administrator for Docs: level 0 or 1, and not restricted (a restricted person is never one). */
|
|
149
|
+
const adminUser = (user) => { try { return !isRestricted(user) && getEffectiveLevel(user) <= 1; } catch { return false; } };
|
|
150
|
+
const isAdmin = (req) => adminUser(req.user);
|
|
151
|
+
const NO_SHARING = 'Your role keeps documents to you and the people already sharing them - it cannot share with anyone new.';
|
|
152
|
+
const NO_LINKS = 'Your role cannot make public links.';
|
|
153
|
+
const NO_SEND = 'Your role cannot email documents from Docs.';
|
|
142
154
|
|
|
143
155
|
/** Names by user id, for owners and share lists. Cached briefly - listUsers reads every user file. */
|
|
144
156
|
let names = null;
|
|
@@ -180,7 +192,7 @@ export default async function docsPlugin(fastify, options) {
|
|
|
180
192
|
async function usableFolder(req, folderId) {
|
|
181
193
|
if (!folderId) return true;
|
|
182
194
|
const f = (await foldersStore.readArray()).find(x => x.id === folderId);
|
|
183
|
-
return Boolean(f && (f.userId === req.user.id || config.scope === 'all'));
|
|
195
|
+
return Boolean(f && (f.userId === req.user.id || (config.scope === 'all' && !isRestricted(req.user))));
|
|
184
196
|
}
|
|
185
197
|
|
|
186
198
|
/** The whole document as the editor sees it: body, access, lock, star, people. */
|
|
@@ -207,7 +219,9 @@ export default async function docsPlugin(fastify, options) {
|
|
|
207
219
|
// 2.12: why this person may not change it now (a protected wiki page) - the editor opens read only.
|
|
208
220
|
frozen: frozenFor(doc, req.user),
|
|
209
221
|
// 2.13: a PDF's viewer address for this person, good for twenty minutes (refreshed with every poll).
|
|
210
|
-
...(kindOf(doc) === 'pdf' ? {fileTicket: viewTicket(doc, req)} : {})
|
|
222
|
+
...(kindOf(doc) === 'pdf' ? {fileTicket: viewTicket(doc, req)} : {}),
|
|
223
|
+
// 2.15: a restricted person makes and passes on no public link - not even the owner's.
|
|
224
|
+
...(isRestricted(req.user) ? {restrictedUser: true, publicLink: null, publicLinksAllowed: false} : {})
|
|
211
225
|
};
|
|
212
226
|
}
|
|
213
227
|
|
|
@@ -215,7 +229,10 @@ export default async function docsPlugin(fastify, options) {
|
|
|
215
229
|
registry.services = {
|
|
216
230
|
// 2.12: why this person may not share, link, send - or publish - this document ('' = they may).
|
|
217
231
|
outwardRefusal: (doc, user) => outwardRefusal(doc, user),
|
|
218
|
-
readDoc, writeDoc, listDocs, accessOf: (doc, user) => accessOf(doc, user, (
|
|
232
|
+
readDoc, writeDoc, listDocs, accessOf: (doc, user) => accessOf(doc, user, adminUser(user)),
|
|
233
|
+
// 2.15: is this person restricted (own and shared documents only; nothing published, linked or sent)?
|
|
234
|
+
// Docs Pro refuses them Spaces, cloud copies, its signing screens and link settings.
|
|
235
|
+
restrictedUser: (user) => isRestricted(user),
|
|
219
236
|
sanitizeDoc, allowMarkup, siteBase, linkBase, people, config: () => ({...config}), htmlToText,
|
|
220
237
|
// Folders (2.1) - Docs Pro's Spaces are folders.
|
|
221
238
|
listFolders: () => foldersStore.readArray(),
|
|
@@ -234,7 +251,7 @@ export default async function docsPlugin(fastify, options) {
|
|
|
234
251
|
await touchRecent(user.id, doc.id);
|
|
235
252
|
return doc;
|
|
236
253
|
},
|
|
237
|
-
isAdmin: (user) =>
|
|
254
|
+
isAdmin: (user) => adminUser(user),
|
|
238
255
|
// 2.11 (the Wiki): change a document inside its write chain, as every Docs route does; a body as the
|
|
239
256
|
// public sees it (sanitised, pending suggestions not made, add-ons' filters); who is editing it now.
|
|
240
257
|
mutateDoc: (id, fn) => mutateDoc(id, fn),
|
|
@@ -368,21 +385,26 @@ export default async function docsPlugin(fastify, options) {
|
|
|
368
385
|
* whitelisted, never spread, so a secret added to the settings object is
|
|
369
386
|
* not handed to the browser.
|
|
370
387
|
*/
|
|
371
|
-
fastify.get('/settings', {preHandler: read}, async (req) =>
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
388
|
+
fastify.get('/settings', {preHandler: read}, async (req) => {
|
|
389
|
+
// 2.15: a restricted person's screens offer no public links, no email and no sharing, and see only their own.
|
|
390
|
+
const restricted = isRestricted(req.user);
|
|
391
|
+
return {
|
|
392
|
+
autoSaveInterval: Number(config.autoSaveInterval) || 0,
|
|
393
|
+
maxVersions: Number(config.maxVersions) || 50,
|
|
394
|
+
publicLinks: config.publicLinks !== false && !restricted,
|
|
395
|
+
allowSend: config.allowSend !== false && !restricted,
|
|
396
|
+
trashDays: Number(config.trashDays) || 30,
|
|
397
|
+
// Shown, never edited here: flipping 'user' to 'all' would hand every
|
|
398
|
+
// user everybody else's documents - a decision for config.
|
|
399
|
+
scope: config.scope === 'all' && !restricted ? 'all' : 'user',
|
|
400
|
+
canEdit: isAdmin(req),
|
|
401
|
+
extensions: registry.adminModules(),
|
|
402
|
+
suggestions: registry.hasSuggest(),
|
|
403
|
+
// 2.13: PDF documents - uploads always; the text inside them is searchable when pdfjs-dist is on this server.
|
|
404
|
+
pdf: {maxBytes: MAX_PDF_BYTES, search: extractCapability().available, reason: extractCapability().reason},
|
|
405
|
+
...(restricted ? {restrictedUser: true} : {})
|
|
406
|
+
};
|
|
407
|
+
});
|
|
386
408
|
|
|
387
409
|
fastify.put('/settings', {preHandler: [authenticate, requireAdmin]}, async (req, reply) => {
|
|
388
410
|
const body = req.body || {};
|
|
@@ -420,6 +442,8 @@ export default async function docsPlugin(fastify, options) {
|
|
|
420
442
|
* name; an admin also sees the email, to tell two Sams apart.
|
|
421
443
|
*/
|
|
422
444
|
fastify.get('/people', {preHandler: read}, async (req) => {
|
|
445
|
+
// 2.15: no directory for a restricted person - they share with nobody new (PUT .../shares).
|
|
446
|
+
if (isRestricted(req.user)) return [];
|
|
423
447
|
const {users} = await people();
|
|
424
448
|
let roles = null;
|
|
425
449
|
try { roles = new Set(getPermissionsFor('docs', 'read')); } catch { roles = null; }
|
|
@@ -430,6 +454,9 @@ export default async function docsPlugin(fastify, options) {
|
|
|
430
454
|
return users
|
|
431
455
|
.filter(u => u.id !== req.user.id && u.disabled !== true && u.isActive !== false && u.active !== false)
|
|
432
456
|
.filter(u => !roles || !roles.size || getEffectiveRoles(u).some(r => roles.has(r)))
|
|
457
|
+
// 2.15: restricted people (a Job Board's companies) are listed to Docs administrators only - nobody else
|
|
458
|
+
// may find them here or share with them (PUT .../shares).
|
|
459
|
+
.filter(u => admin || !isRestricted(u))
|
|
433
460
|
.map(u => ({id: u.id, name: String(u.name || '').trim() || 'Unnamed', ...(admin ? {email: u.email || ''} : {})}));
|
|
434
461
|
});
|
|
435
462
|
|
|
@@ -570,7 +597,8 @@ export default async function docsPlugin(fastify, options) {
|
|
|
570
597
|
if (Array.isArray(allowed) && allowed.length && !getEffectiveRoles(viewer).some(r => allowed.includes(r) || (() => { try { return getRoleLevel(r) === 0; } catch { return false; } })())) return reply.code(403).send({error: 'This viewer link no longer works.'});
|
|
571
598
|
} catch { /* an older core without the permission: the ticket stands */ }
|
|
572
599
|
const doc = await readDoc(req.params.id);
|
|
573
|
-
|
|
600
|
+
// The person as they are now (2.15: their roles decide whether they are restricted).
|
|
601
|
+
const access = accessOf(doc, {...viewer, id: claims.userId}, claims.admin && adminUser(viewer));
|
|
574
602
|
if (!doc || !access || (doc.trashedAt && doc.userId !== claims.userId) || kindOf(doc) !== 'pdf') return reply.code(404).send({error: 'Document not found'});
|
|
575
603
|
const buf = await readFileBytes(doc.id);
|
|
576
604
|
if (!buf) return reply.code(404).send({error: 'The file is missing.'});
|
|
@@ -805,9 +833,19 @@ export default async function docsPlugin(fastify, options) {
|
|
|
805
833
|
if (doc.trashedAt) return reply.code(409).send({error: 'This document is in Trash.'});
|
|
806
834
|
// Only add-on access (2.11): editing, not passing it on. A restricted document takes nobody new (below).
|
|
807
835
|
if (onlyThroughExtension(doc, req.user)) return reply.code(403).send({error: outwardRefusal(doc, req.user)});
|
|
808
|
-
const {users} = await people();
|
|
809
|
-
const known = new Map(users.map(u => [u.id, u]));
|
|
810
836
|
const incoming = Array.isArray(req.body?.shares) ? req.body.shares : [];
|
|
837
|
+
const had = new Set((doc.shares || []).map(x => x.userId));
|
|
838
|
+
// 2.15: a restricted person names nobody new at all - refused before any id is looked up, so the answer
|
|
839
|
+
// never says whether an id is an account.
|
|
840
|
+
const closed = isRestricted(req.user);
|
|
841
|
+
if (closed && incoming.slice(0, 200).some(x => { const u = String(x?.userId || ''); return u && u !== doc.userId && !had.has(u); })) {
|
|
842
|
+
return reply.code(403).send({error: NO_SHARING});
|
|
843
|
+
}
|
|
844
|
+
const {users} = await people();
|
|
845
|
+
const admin = isAdmin(req);
|
|
846
|
+
// 2.15: only a Docs administrator gives a restricted person a new share (as /people lists them to admins only);
|
|
847
|
+
// for anyone else they are as unknown as an id that is no account.
|
|
848
|
+
const known = new Map(users.filter(u => admin || had.has(u.id) || !isRestricted(u)).map(u => [u.id, u]));
|
|
811
849
|
const seen = new Set();
|
|
812
850
|
const shares = [];
|
|
813
851
|
for (const s of incoming.slice(0, 200)) {
|
|
@@ -830,14 +868,16 @@ export default async function docsPlugin(fastify, options) {
|
|
|
830
868
|
}
|
|
831
869
|
// A restricted document (a members-only wiki page, 2.11) takes nobody new - owner included.
|
|
832
870
|
const restricted = registry.restrictionOf?.(doc) || '';
|
|
871
|
+
// 2.15: a restricted person shares with nobody new either (checked again against the list as it is now).
|
|
833
872
|
let added = [];
|
|
834
873
|
const updated = await mutateDoc(doc.id, (cur) => {
|
|
835
874
|
// Against the list as it is now, not as it was read above.
|
|
836
875
|
added = shares.filter(s => !(cur.shares || []).some(p => p.userId === s.userId));
|
|
837
|
-
if (restricted && added.length) return null;
|
|
876
|
+
if ((restricted || closed) && added.length) return null;
|
|
838
877
|
return {...cur, shares};
|
|
839
878
|
});
|
|
840
879
|
if (restricted && added.length) return reply.code(403).send({error: `${restricted} No one new can be given access.`});
|
|
880
|
+
if (closed && added.length) return reply.code(403).send({error: NO_SHARING});
|
|
841
881
|
|
|
842
882
|
let notified = 0;
|
|
843
883
|
if (req.body?.notify && added.length) {
|
|
@@ -875,6 +915,7 @@ export default async function docsPlugin(fastify, options) {
|
|
|
875
915
|
/** POST /documents/:id/link - turn the public link on (idempotent). */
|
|
876
916
|
fastify.post('/documents/:id/link', {preHandler: edit}, async (req, reply) => {
|
|
877
917
|
if (config.publicLinks === false) return reply.code(403).send({error: 'Public links are switched off on this site.'});
|
|
918
|
+
if (isRestricted(req.user)) return reply.code(403).send({error: NO_LINKS});
|
|
878
919
|
const hit = await load(req, reply, 'edit');
|
|
879
920
|
if (!hit) return;
|
|
880
921
|
const {doc, access} = hit;
|
|
@@ -903,6 +944,7 @@ export default async function docsPlugin(fastify, options) {
|
|
|
903
944
|
*/
|
|
904
945
|
fastify.post('/documents/:id/send', {preHandler: edit, config: {rateLimit: {max: 10, timeWindow: '10 minutes'}}}, async (req, reply) => {
|
|
905
946
|
if (config.allowSend === false) return reply.code(403).send({error: 'Sending documents by email is switched off on this site.'});
|
|
947
|
+
if (isRestricted(req.user)) return reply.code(403).send({error: NO_SEND});
|
|
906
948
|
const hit = await load(req, reply, 'edit');
|
|
907
949
|
if (!hit) return;
|
|
908
950
|
let {doc} = hit;
|
|
@@ -1039,7 +1081,7 @@ export default async function docsPlugin(fastify, options) {
|
|
|
1039
1081
|
|
|
1040
1082
|
fastify.get('/folders', {preHandler: read}, async (req) => {
|
|
1041
1083
|
const folders = await foldersStore.readArray();
|
|
1042
|
-
return config.scope === 'user' ? folders.filter(f => f.userId === req.user.id) : folders;
|
|
1084
|
+
return config.scope === 'user' || isRestricted(req.user) ? folders.filter(f => f.userId === req.user.id) : folders;
|
|
1043
1085
|
});
|
|
1044
1086
|
|
|
1045
1087
|
fastify.post('/folders', {preHandler: make}, async (req, reply) => {
|
|
@@ -1080,7 +1122,7 @@ export default async function docsPlugin(fastify, options) {
|
|
|
1080
1122
|
|
|
1081
1123
|
fastify.get('/templates', {preHandler: read}, async (req) => {
|
|
1082
1124
|
const templates = await templatesStore.readArray();
|
|
1083
|
-
const own = config.scope === 'user' ? templates.filter(t => t.userId === req.user.id) : templates;
|
|
1125
|
+
const own = config.scope === 'user' || isRestricted(req.user) ? templates.filter(t => t.userId === req.user.id) : templates;
|
|
1084
1126
|
// Add-ons' ready-made templates (2.6), after the user's own: read only, sanitised like any body.
|
|
1085
1127
|
const builtIn = registry.builtInTemplates().map(t => ({
|
|
1086
1128
|
id: `x-${t.owner}-${t.id}`, name: String(t.name || 'Template').slice(0, 120), description: String(t.description || '').slice(0, 300),
|
package/plugins/docs/plugin.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "docs",
|
|
3
3
|
"displayName": "Docs",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.15.0",
|
|
5
5
|
"tier": "free",
|
|
6
6
|
"description": "A document editor: sharing, public links, import and export, send to a page, blog or email, version history and templates. PDF documents: add a PDF and it is kept as it is - filed, shared, linked, emailed and versioned like any document, shown in the browser's own viewer.",
|
|
7
7
|
"author": "Darryl Waterhouse",
|
|
@@ -81,6 +81,19 @@
|
|
|
81
81
|
"admin",
|
|
82
82
|
"user"
|
|
83
83
|
]
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"key": "docs-restricted",
|
|
87
|
+
"label": "Docs: own documents only",
|
|
88
|
+
"group": "Plugins",
|
|
89
|
+
"description": "A role with this uses Docs for its own documents and the ones shared with it, and nothing more: no list of people, no sharing with anyone new, no public links, no emailing documents, nothing published (Domma Spaces, cloud copies) - whatever the site's Docs settings say. It changes nothing for a person who also holds a role that gives Docs without it, and nothing for the top (level-0) role.",
|
|
90
|
+
"actions": [
|
|
91
|
+
{
|
|
92
|
+
"key": "on",
|
|
93
|
+
"label": "Restricted",
|
|
94
|
+
"description": "Own and shared documents only"
|
|
95
|
+
}
|
|
96
|
+
]
|
|
84
97
|
}
|
|
85
98
|
],
|
|
86
99
|
"uses": {
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import {DATA} from './_env.js';
|
|
2
|
+
import {after, before, test} from 'node:test';
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import Fastify from 'fastify';
|
|
5
|
+
import fs from 'fs/promises';
|
|
6
|
+
import docsPlugin from '../plugin.js';
|
|
7
|
+
import {restrictedByRoles, holdsRestriction, RESTRICTED_PERMISSION, runtime} from '../lib/store.js';
|
|
8
|
+
import {docsRegistry} from '../lib/extensions.js';
|
|
9
|
+
import {load as loadRoles} from '../../../cms/server/services/roles.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Docs 2.15 - restricted people: their own documents and the ones shared with them, and nothing else -
|
|
13
|
+
* under BOTH site scopes ('user' and 'all'). No people list, no sharing with anyone new, no public links,
|
|
14
|
+
* no email. Everything else is as it was for everyone else (the last test runs the real role check with
|
|
15
|
+
* no restricted role on the site).
|
|
16
|
+
*
|
|
17
|
+
* Who is restricted is injected here (`isRestricted`); the rule itself (`restrictedByRoles`) is tested pure,
|
|
18
|
+
* and the real role data path is driven by the Job Board's tests (plugins/job-board/tests/docs-access.test.js).
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
before(async () => { await loadRoles(); }); // super-admin is level 0 (a Docs administrator)
|
|
22
|
+
after(async () => { await fs.rm(DATA, {recursive: true, force: true}); });
|
|
23
|
+
|
|
24
|
+
const PEOPLE = [
|
|
25
|
+
{id: 'r-alice', name: 'Alice Staff', email: 'alice@site.test', role: 'user'},
|
|
26
|
+
{id: 'r-ada', name: 'Ada Admin', email: 'ada@site.test', role: 'super-admin'},
|
|
27
|
+
{id: 'r-rita', name: 'Rita Company', email: 'rita@acme.test', role: 'jb-company'},
|
|
28
|
+
{id: 'r-rex', name: 'Rex Other', email: 'rex@bolt.test', role: 'jb-company'},
|
|
29
|
+
// A level-1 account that a role also restricts: never an administrator to Docs.
|
|
30
|
+
{id: 'r-root', name: 'Rhoda Restricted Admin', email: 'rhoda@site.test', role: 'admin', restricted: true}
|
|
31
|
+
];
|
|
32
|
+
const RESTRICTED = new Set(['r-rita', 'r-rex', 'r-root']);
|
|
33
|
+
const isRestricted = (user) => RESTRICTED.has(user?.id);
|
|
34
|
+
|
|
35
|
+
const outbox = [];
|
|
36
|
+
/** Every document Rita owns or had shared with her, across both scopes' runs. */
|
|
37
|
+
const ritaMay = new Set();
|
|
38
|
+
const mailer = {createTransport: async () => ({}), sendEmail: async (t, m) => { outbox.push(m); return {ok: true}; }};
|
|
39
|
+
|
|
40
|
+
async function appFor(id, settings) {
|
|
41
|
+
const person = PEOPLE.find(p => p.id === id);
|
|
42
|
+
const app = Fastify();
|
|
43
|
+
const authenticate = async (req) => { req.user = {id: person.id, name: person.name, email: person.email, role: person.role}; };
|
|
44
|
+
await app.register(docsPlugin, {prefix: '/api/plugins/docs', settings: {...settings},
|
|
45
|
+
auth: {authenticate, requireAdmin: async () => {}, requirePermission: () => async () => {}},
|
|
46
|
+
listUsers: async () => PEOPLE, mailer, isRestricted});
|
|
47
|
+
await app.ready();
|
|
48
|
+
return app;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function call(app, method, url, payload) {
|
|
52
|
+
const res = await app.inject({method, url: `/api/plugins/docs${url}`, payload});
|
|
53
|
+
let body = null;
|
|
54
|
+
try { body = JSON.parse(res.body); } catch { body = res.body; }
|
|
55
|
+
return {status: res.statusCode, body};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
test('the rule: restricted when a role holds it and no Docs-giving role lacks it; never level 0', () => {
|
|
59
|
+
const perms = {
|
|
60
|
+
'jb-company': ['job-board.read', 'docs.read', 'docs.create', RESTRICTED_PERMISSION],
|
|
61
|
+
'jb-agent': ['docs', `${RESTRICTED_PERMISSION}.on`],
|
|
62
|
+
'jb-candidate': ['job-board.read'],
|
|
63
|
+
user: ['docs'],
|
|
64
|
+
'super-admin': [RESTRICTED_PERMISSION]
|
|
65
|
+
};
|
|
66
|
+
const look = {
|
|
67
|
+
isRoot: (r) => r === 'super-admin',
|
|
68
|
+
marked: (r) => holdsRestriction(perms[r]),
|
|
69
|
+
givesDocs: (r) => (perms[r] || []).some(p => p === 'docs' || p.startsWith('docs.'))
|
|
70
|
+
};
|
|
71
|
+
assert.equal(restrictedByRoles(['jb-company'], look), true);
|
|
72
|
+
assert.equal(restrictedByRoles(['jb-agent'], look), true, 'an action of the resource counts');
|
|
73
|
+
assert.equal(restrictedByRoles(['jb-candidate'], look), false, 'no mark, no restriction (and no Docs)');
|
|
74
|
+
assert.equal(restrictedByRoles(['user'], look), false);
|
|
75
|
+
assert.equal(restrictedByRoles(['jb-company', 'user'], look), false, 'a role that opens Docs fully opens it');
|
|
76
|
+
assert.equal(restrictedByRoles(['jb-company', 'jb-candidate'], look), true, 'a role without Docs changes nothing');
|
|
77
|
+
assert.equal(restrictedByRoles(['super-admin'], look), false, 'level 0 is never restricted');
|
|
78
|
+
assert.equal(restrictedByRoles(['jb-company', 'super-admin'], look), false);
|
|
79
|
+
assert.equal(restrictedByRoles([], look), false);
|
|
80
|
+
assert.equal(holdsRestriction(['docs-restrictedish']), false, 'a lookalike resource is not it');
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
for (const scope of ['user', 'all']) {
|
|
84
|
+
test(`scope '${scope}': a restricted person sees their own and shared documents only, and passes nothing on`, async () => {
|
|
85
|
+
outbox.length = 0;
|
|
86
|
+
const s = {scope};
|
|
87
|
+
const alice = await appFor('r-alice', s);
|
|
88
|
+
const ada = await appFor('r-ada', s);
|
|
89
|
+
const rita = await appFor('r-rita', s);
|
|
90
|
+
const rex = await appFor('r-rex', s);
|
|
91
|
+
const rhoda = await appFor('r-root', s);
|
|
92
|
+
assert.equal(runtime.config.scope, scope);
|
|
93
|
+
|
|
94
|
+
const mk = async (app, title) => { const r = await call(app, 'POST', '/documents', {title, content: `<p>${title} body</p>`}); assert.equal(r.status, 201); return r.body; };
|
|
95
|
+
const staffDoc = await mk(alice, `Staff notes ${scope}`);
|
|
96
|
+
const adminDoc = await mk(ada, `Admin plans ${scope}`);
|
|
97
|
+
// A Docs administrator shares with a restricted person; anyone else cannot (as if the id were no account).
|
|
98
|
+
const shared = await mk(ada, `Shared draft ${scope}`);
|
|
99
|
+
assert.equal((await call(ada, 'PUT', `/documents/${shared.id}/shares`, {shares: [{userId: 'r-rita', role: 'editor'}]})).status, 200);
|
|
100
|
+
assert.equal((await call(ada, 'POST', `/documents/${shared.id}/link`)).status, 200);
|
|
101
|
+
const aliceTries = await call(alice, 'PUT', `/documents/${staffDoc.id}/shares`, {shares: [{userId: 'r-rita', role: 'viewer'}]});
|
|
102
|
+
assert.equal(aliceTries.status, 200);
|
|
103
|
+
assert.deepEqual(aliceTries.body.shares, [], 'not added');
|
|
104
|
+
const letter = await mk(rita, `Offer letter ${scope}`);
|
|
105
|
+
const folder = (await call(alice, 'POST', '/folders', {name: `Staff folder ${scope}`})).body;
|
|
106
|
+
const template = (await call(alice, 'POST', '/templates', {name: `Staff template ${scope}`, content: '<p>t</p>'})).body;
|
|
107
|
+
|
|
108
|
+
// Other people's documents: 404, under either scope - the restricted admin included.
|
|
109
|
+
for (const app of [rita, rhoda]) {
|
|
110
|
+
for (const d of [staffDoc, adminDoc]) {
|
|
111
|
+
assert.equal((await call(app, 'GET', `/documents/${d.id}`)).status, 404, `${d.title} is not theirs`);
|
|
112
|
+
assert.equal((await call(app, 'PUT', `/documents/${d.id}`, {content: '<p>x</p>'})).status, 404);
|
|
113
|
+
assert.equal((await call(app, 'GET', `/documents/${d.id}/versions`)).status, 404);
|
|
114
|
+
assert.equal((await call(app, 'POST', `/documents/${d.id}/duplicate`)).status, 404);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
assert.equal((await call(rex, 'GET', `/documents/${letter.id}`)).status, 404, "another company's letter");
|
|
118
|
+
assert.equal((await call(rex, 'GET', `/documents/${shared.id}`)).status, 404);
|
|
119
|
+
|
|
120
|
+
// Lists and counts hold only their own and what was shared with them.
|
|
121
|
+
for (const view of ['all', 'recent', 'mine', 'shared']) {
|
|
122
|
+
const ids = (await call(rita, 'GET', `/documents?view=${view}`)).body.map(r => r.id);
|
|
123
|
+
assert.ok(!ids.includes(staffDoc.id) && !ids.includes(adminDoc.id), `${view}: no one else's documents`);
|
|
124
|
+
}
|
|
125
|
+
ritaMay.add(letter.id).add(shared.id);
|
|
126
|
+
const all = (await call(rita, 'GET', '/documents?view=all')).body.map(r => r.id);
|
|
127
|
+
assert.ok(all.includes(letter.id) && all.includes(shared.id));
|
|
128
|
+
assert.ok(all.every(id => ritaMay.has(id)), 'nothing but hers and what was shared with her');
|
|
129
|
+
assert.deepEqual((await call(rex, 'GET', '/documents?view=all')).body, []);
|
|
130
|
+
assert.equal((await call(rex, 'GET', '/count')).body.places.shared, 0);
|
|
131
|
+
|
|
132
|
+
// Their own and the shared one work as before.
|
|
133
|
+
assert.equal((await call(rita, 'PUT', `/documents/${letter.id}`, {content: '<p>Dear candidate</p>'})).status, 200);
|
|
134
|
+
const sharedSeen = await call(rita, 'GET', `/documents/${shared.id}`);
|
|
135
|
+
assert.equal(sharedSeen.status, 200);
|
|
136
|
+
assert.equal(sharedSeen.body.access, 'editor');
|
|
137
|
+
// ...but the owner's public link is not handed to them.
|
|
138
|
+
assert.equal(sharedSeen.body.publicLink, null);
|
|
139
|
+
assert.equal(sharedSeen.body.restrictedUser, true);
|
|
140
|
+
assert.equal((await call(rita, 'PUT', `/documents/${shared.id}`, {content: '<p>edited by Rita</p>'})).status, 200);
|
|
141
|
+
|
|
142
|
+
// No directory.
|
|
143
|
+
assert.deepEqual((await call(rita, 'GET', '/people')).body, []);
|
|
144
|
+
assert.ok(!(await call(alice, 'GET', '/people')).body.some(p => p.id === 'r-rita'), 'not listed to other users');
|
|
145
|
+
assert.ok((await call(ada, 'GET', '/people')).body.some(p => p.id === 'r-rita'), 'listed to Docs administrators');
|
|
146
|
+
// No oracle: an id that is no account is refused exactly as a real one.
|
|
147
|
+
const ghost = await call(rita, 'PUT', `/documents/${letter.id}/shares`, {shares: [{userId: 'no-such-person', role: 'viewer'}]});
|
|
148
|
+
assert.equal(ghost.status, 403);
|
|
149
|
+
|
|
150
|
+
// No one new: not by id, not on their own document, not on the shared one.
|
|
151
|
+
const share = await call(rita, 'PUT', `/documents/${letter.id}/shares`, {shares: [{userId: 'r-alice', role: 'viewer'}]});
|
|
152
|
+
assert.equal(share.status, 403);
|
|
153
|
+
assert.deepEqual((await call(rita, 'GET', `/documents/${letter.id}`)).body.shares, []);
|
|
154
|
+
const reshare = await call(rita, 'PUT', `/documents/${shared.id}/shares`, {shares: [{userId: 'r-rita', role: 'editor'}, {userId: 'r-rex', role: 'viewer'}]});
|
|
155
|
+
assert.equal(reshare.status, 403);
|
|
156
|
+
// Keeping the list as it is is not adding anyone.
|
|
157
|
+
assert.equal((await call(rita, 'PUT', `/documents/${shared.id}/shares`, {shares: [{userId: 'r-rita', role: 'editor'}]})).status, 200);
|
|
158
|
+
|
|
159
|
+
// No public links, no email - their own document either.
|
|
160
|
+
assert.equal((await call(rita, 'POST', `/documents/${letter.id}/link`)).status, 403);
|
|
161
|
+
assert.equal((await call(rita, 'GET', `/documents/${letter.id}`)).body.publicLink, null);
|
|
162
|
+
for (const mode of ['inline', 'link']) {
|
|
163
|
+
assert.equal((await call(rita, 'POST', `/documents/${letter.id}/send`, {to: 'someone@else.test', mode})).status, 403);
|
|
164
|
+
}
|
|
165
|
+
assert.equal(outbox.length, 0, 'nothing was emailed');
|
|
166
|
+
|
|
167
|
+
// Settings say so; folders and templates are their own.
|
|
168
|
+
const set = (await call(rita, 'GET', '/settings')).body;
|
|
169
|
+
assert.equal(set.restrictedUser, true);
|
|
170
|
+
assert.equal(set.publicLinks, false);
|
|
171
|
+
assert.equal(set.allowSend, false);
|
|
172
|
+
assert.equal(set.scope, 'user');
|
|
173
|
+
assert.equal(set.canEdit, false);
|
|
174
|
+
assert.equal((await call(rhoda, 'GET', '/settings')).body.canEdit, false, 'a restricted admin is no Docs admin');
|
|
175
|
+
assert.ok(!(await call(rita, 'GET', '/folders')).body.some(f => f.id === folder.id));
|
|
176
|
+
assert.equal((await call(rita, 'POST', '/documents', {title: 'In their folder', folderId: folder.id})).status, 400);
|
|
177
|
+
assert.ok(!(await call(rita, 'GET', '/templates')).body.some(t => t.id === template.id));
|
|
178
|
+
assert.equal((await call(rhoda, 'DELETE', `/templates/${template.id}`)).status, 404);
|
|
179
|
+
assert.equal((await call(rhoda, 'PUT', `/folders/${folder.id}`, {name: 'Mine now'})).status, 404);
|
|
180
|
+
|
|
181
|
+
// An add-on that gives everyone edit access (a Wiki) gives them nothing.
|
|
182
|
+
docsRegistry().register('restrict-test', {access: () => 'editor'});
|
|
183
|
+
try {
|
|
184
|
+
assert.equal((await call(rita, 'GET', `/documents/${staffDoc.id}`)).status, 404);
|
|
185
|
+
assert.equal((await call(alice, 'GET', `/documents/${adminDoc.id}`)).status, 200, 'everyone else still gets it');
|
|
186
|
+
} finally { docsRegistry().unregister('restrict-test'); }
|
|
187
|
+
|
|
188
|
+
// Services (Docs Pro, the Job Board) answer the same.
|
|
189
|
+
const svc = docsRegistry().services;
|
|
190
|
+
assert.equal(svc.restrictedUser({id: 'r-rita', role: 'jb-company'}), true);
|
|
191
|
+
assert.equal(svc.accessOf(staffDoc, {id: 'r-rita', role: 'jb-company'}), null);
|
|
192
|
+
assert.equal(svc.accessOf(letter, {id: 'r-rita', role: 'jb-company'}), 'owner');
|
|
193
|
+
assert.equal(svc.isAdmin({id: 'r-root', role: 'admin'}), false);
|
|
194
|
+
|
|
195
|
+
// Everyone else, unchanged.
|
|
196
|
+
assert.equal((await call(alice, 'GET', `/documents/${adminDoc.id}`)).status, scope === 'all' ? 200 : 404);
|
|
197
|
+
assert.equal((await call(ada, 'GET', `/documents/${letter.id}`)).status, scope === 'all' ? 200 : 404);
|
|
198
|
+
|
|
199
|
+
for (const a of [alice, ada, rita, rex, rhoda]) await a.close();
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
test('with no restricted role on the site (the real role check), every route answers as before', async () => {
|
|
204
|
+
await loadRoles();
|
|
205
|
+
outbox.length = 0;
|
|
206
|
+
const build = async (id) => {
|
|
207
|
+
const person = PEOPLE.find(p => p.id === id);
|
|
208
|
+
const app = Fastify();
|
|
209
|
+
const authenticate = async (req) => { req.user = {id: person.id, name: person.name, email: person.email, role: person.role}; };
|
|
210
|
+
// No isRestricted: the CMS's role data decides - and no role there holds docs-restricted.
|
|
211
|
+
await app.register(docsPlugin, {prefix: '/api/plugins/docs', settings: {scope: 'all'},
|
|
212
|
+
auth: {authenticate, requireAdmin: async () => {}, requirePermission: () => async () => {}}, listUsers: async () => PEOPLE, mailer});
|
|
213
|
+
await app.ready();
|
|
214
|
+
return app;
|
|
215
|
+
};
|
|
216
|
+
const alice = await build('r-alice');
|
|
217
|
+
const ada = await build('r-ada');
|
|
218
|
+
const set = (await call(alice, 'GET', '/settings')).body;
|
|
219
|
+
assert.equal(set.restrictedUser, undefined);
|
|
220
|
+
assert.equal(set.publicLinks, true);
|
|
221
|
+
assert.equal(set.allowSend, true);
|
|
222
|
+
assert.equal(set.scope, 'all');
|
|
223
|
+
assert.equal((await call(ada, 'GET', '/settings')).body.canEdit, true);
|
|
224
|
+
const doc = (await call(alice, 'POST', '/documents', {title: 'Plain', content: '<p>plain</p>'})).body;
|
|
225
|
+
const people = (await call(alice, 'GET', '/people')).body;
|
|
226
|
+
assert.ok(people.length >= 3, 'the share list as before');
|
|
227
|
+
assert.equal((await call(alice, 'PUT', `/documents/${doc.id}/shares`, {shares: [{userId: 'r-ada', role: 'viewer'}]})).status, 200);
|
|
228
|
+
const link = await call(alice, 'POST', `/documents/${doc.id}/link`);
|
|
229
|
+
assert.equal(link.status, 200);
|
|
230
|
+
assert.ok(link.body.publicLink.token);
|
|
231
|
+
assert.equal((await call(alice, 'POST', `/documents/${doc.id}/send`, {to: 'x@y.test'})).status, 200);
|
|
232
|
+
assert.equal(outbox.length, 1);
|
|
233
|
+
const seen = (await call(alice, 'GET', `/documents/${doc.id}`)).body;
|
|
234
|
+
assert.equal(seen.restrictedUser, undefined);
|
|
235
|
+
// Site-wide: the admin is an owner of it, as before.
|
|
236
|
+
assert.equal((await call(ada, 'GET', `/documents/${doc.id}`)).body.access, 'owner');
|
|
237
|
+
assert.equal(docsRegistry().services.restrictedUser({id: 'r-alice', role: 'user'}), false);
|
|
238
|
+
await alice.close();
|
|
239
|
+
await ada.close();
|
|
240
|
+
});
|