domma-cms 1.66.6 → 1.66.8

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.
Files changed (101) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/admin/js/app.js +2 -2
  3. package/admin/js/lib/chat-toast.js +2 -2
  4. package/admin/js/lib/collection-editor-arrange.js +2 -2
  5. package/admin/js/lib/notifications-arrange.js +1 -1
  6. package/admin/js/templates/collection-editor.html +4 -0
  7. package/admin/js/templates/contacts.html +1 -1
  8. package/admin/js/templates/docs/usage-collections.html +5 -0
  9. package/docs/DommaFeatures.md +3 -1
  10. package/docs/markdown-shortcodes.md +6 -0
  11. package/package.json +1 -1
  12. package/plugins/_lib/admin/mail/body-menu.js +1 -1
  13. package/plugins/_lib/admin/mail/cms-host.js +1 -1
  14. package/plugins/_lib/admin/mail/compose-window.js +1 -1
  15. package/plugins/_lib/admin/mail/contacts.js +1 -1
  16. package/plugins/_lib/admin/mail/diagnostics-section.js +1 -1
  17. package/plugins/_lib/admin/mail/drag-drop.js +1 -1
  18. package/plugins/_lib/admin/mail/folder-tree.js +1 -1
  19. package/plugins/_lib/admin/mail/font-controls.js +1 -1
  20. package/plugins/_lib/admin/mail/fonts.js +1 -1
  21. package/plugins/_lib/admin/mail/host-context.js +1 -1
  22. package/plugins/_lib/admin/mail/identity.js +1 -1
  23. package/plugins/_lib/admin/mail/image-senders-section.js +1 -1
  24. package/plugins/_lib/admin/mail/keyboard.js +1 -1
  25. package/plugins/_lib/admin/mail/mail.html +1 -1
  26. package/plugins/_lib/admin/mail/message-actions.js +1 -1
  27. package/plugins/_lib/admin/mail/oauth-panel.js +1 -1
  28. package/plugins/_lib/admin/mail/panes.js +1 -1
  29. package/plugins/_lib/admin/mail/reader-kit.js +1 -1
  30. package/plugins/_lib/admin/mail/reader-runtime.js +1 -34
  31. package/plugins/_lib/admin/mail/reader-view.js +1 -1
  32. package/plugins/_lib/admin/mail/resizable.js +1 -1
  33. package/plugins/_lib/admin/mail/restore-spam.js +1 -1
  34. package/plugins/_lib/admin/mail/rules.js +1 -1
  35. package/plugins/_lib/admin/mail/scheduling.js +1 -1
  36. package/plugins/_lib/admin/mail/section-kit.js +1 -1
  37. package/plugins/_lib/admin/mail/security-note.js +1 -1
  38. package/plugins/_lib/admin/mail/settings-section.js +1 -1
  39. package/plugins/_lib/admin/mail/templates.js +1 -1
  40. package/plugins/_lib/admin/mail/threads.js +1 -1
  41. package/plugins/_lib/admin/mail/vacation.js +1 -1
  42. package/plugins/_lib/admin/mail/when-closed.js +1 -1
  43. package/plugins/_lib/admin/ui/dates.js +1 -1
  44. package/plugins/_lib/admin/ui/resizable.js +1 -1
  45. package/plugins/_lib/contacts/mailContact.js +1 -1
  46. package/plugins/_lib/contacts/model.js +1 -1
  47. package/plugins/_lib/domma-mail-contacts.lock.json +18 -18
  48. package/plugins/_lib/domma-mail.lock.json +80 -80
  49. package/plugins/_lib/mail/accountFileStore.js +1 -1
  50. package/plugins/_lib/mail/accountRepository.js +1 -1
  51. package/plugins/_lib/mail/accountRoutes.js +1 -1
  52. package/plugins/_lib/mail/bodyTokenProvider.js +1 -1
  53. package/plugins/_lib/mail/bodyTokens.js +1 -1
  54. package/plugins/_lib/mail/compose.js +1 -1
  55. package/plugins/_lib/mail/defaults.js +1 -1
  56. package/plugins/_lib/mail/envelope.js +1 -1
  57. package/plugins/_lib/mail/folderActions.js +1 -1
  58. package/plugins/_lib/mail/folderRuntime.js +1 -1
  59. package/plugins/_lib/mail/folders.js +1 -1
  60. package/plugins/_lib/mail/imapPoolRuntime.js +1 -1
  61. package/plugins/_lib/mail/mbox.js +1 -1
  62. package/plugins/_lib/mail/message-action.js +1 -1
  63. package/plugins/_lib/mail/messageSecurity.js +1 -1
  64. package/plugins/_lib/mail/messageSecurityProvider.js +1 -1
  65. package/plugins/_lib/mail/networkAddresses.js +1 -1
  66. package/plugins/_lib/mail/networkPolicy.js +1 -1
  67. package/plugins/_lib/mail/oauthAccounts.js +1 -1
  68. package/plugins/_lib/mail/oauthRouteRuntime.js +1 -1
  69. package/plugins/_lib/mail/oauthRuntime.js +1 -1
  70. package/plugins/_lib/mail/pollSchedule.js +1 -1
  71. package/plugins/_lib/mail/poller.js +1 -1
  72. package/plugins/_lib/mail/pollerRuntime.js +1 -1
  73. package/plugins/_lib/mail/priority.js +1 -1
  74. package/plugins/_lib/mail/publicMailbox.js +1 -1
  75. package/plugins/_lib/mail/readRuntime.js +1 -1
  76. package/plugins/_lib/mail/render.js +1 -1
  77. package/plugins/_lib/mail/ruleRunner.js +1 -1
  78. package/plugins/_lib/mail/schedulerRuntime.js +1 -1
  79. package/plugins/_lib/mail/secretProvider.js +1 -1
  80. package/plugins/_lib/mail/secretbox.js +1 -1
  81. package/plugins/_lib/mail/senderAuth.js +1 -1
  82. package/plugins/_lib/mail/sieve.js +1 -1
  83. package/plugins/_lib/mail/smtpService.js +1 -1
  84. package/plugins/_lib/mail/snoozeRuntime.js +1 -1
  85. package/plugins/_lib/mail/store.js +1 -1
  86. package/plugins/_lib/mail/subscriptions.js +1 -1
  87. package/plugins/_lib/mail/syncPlan.js +1 -1
  88. package/plugins/_lib/mail/syncRuntime.js +1 -1
  89. package/plugins/_lib/mail/syncSelection.js +1 -1
  90. package/plugins/_lib/mail/unreadBadge.js +1 -1
  91. package/plugins/_lib/mail/unsubscribe.js +1 -1
  92. package/plugins/_lib/mail/vacationRuntime.js +1 -1
  93. package/plugins/_lib/mail/write.js +1 -1
  94. package/server/routes/api/collections.js +4 -3
  95. package/server/routes/api/pages.js +2 -1
  96. package/server/routes/outreach-public.js +3 -1
  97. package/server/server.js +5 -0
  98. package/server/services/collectionAccess.js +29 -1
  99. package/server/services/collections.js +58 -6
  100. package/server/services/markdown.js +18 -2
  101. package/server/services/presetCollections.js +26 -5
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.29.0, packages/core/src/mail/sieve.js.
1
+ // Source: @domma-mail/core 0.29.1, packages/core/src/mail/sieve.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /** ManageSieve (RFC 5804). One bounded, TLS-verified session per operation. */
4
4
  import net from 'node:net';
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.29.0, packages/core/src/mail/smtpService.js.
1
+ // Source: @domma-mail/core 0.29.1, packages/core/src/mail/smtpService.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /**
4
4
  * Sending, and keeping a copy where the rest of your clients will find it.
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.29.0, packages/core/src/mail/snoozeRuntime.js.
1
+ // Source: @domma-mail/core 0.29.1, packages/core/src/mail/snoozeRuntime.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  import {safeWritePool, moveMessage} from './write.js';
4
4
 
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.29.0, packages/core/src/mail/store.js.
1
+ // Source: @domma-mail/core 0.29.1, packages/core/src/mail/store.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /**
4
4
  * The synchronised message store.
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.29.0, packages/core/src/mail/subscriptions.js.
1
+ // Source: @domma-mail/core 0.29.1, packages/core/src/mail/subscriptions.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  export function resolveSubscriptions(boxes) {
4
4
  const list = boxes ?? [];
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.29.0, packages/core/src/mail/syncPlan.js.
1
+ // Source: @domma-mail/core 0.29.1, packages/core/src/mail/syncPlan.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /**
4
4
  * Deciding what a folder sync needs to do.
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.29.0, packages/core/src/mail/syncRuntime.js.
1
+ // Source: @domma-mail/core 0.29.1, packages/core/src/mail/syncRuntime.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  import {missingUids, planFolderSync} from './syncPlan.js';
4
4
  import {resolveSyncFolders} from './syncSelection.js';
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.29.0, packages/core/src/mail/syncSelection.js.
1
+ // Source: @domma-mail/core 0.29.1, packages/core/src/mail/syncSelection.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /**
4
4
  * Which folders a mailbox keeps mirrored.
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.29.0, packages/core/src/mail/unreadBadge.js.
1
+ // Source: @domma-mail/core 0.29.1, packages/core/src/mail/unreadBadge.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /**
4
4
  * The free reader's sidebar badge - unread mail in each mailbox's INBOX.
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.29.0, packages/core/src/mail/unsubscribe.js.
1
+ // Source: @domma-mail/core 0.29.1, packages/core/src/mail/unsubscribe.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /**
4
4
  * Getting off a mailing list.
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.29.0, packages/core/src/mail/vacationRuntime.js.
1
+ // Source: @domma-mail/core 0.29.1, packages/core/src/mail/vacationRuntime.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  import {randomUUID} from 'node:crypto';
4
4
  import {autoReplyHeaders, isActive, normaliseVacation, replySubject, shouldAutoReply, replyHistory} from '../admin/mail/vacation.js';
@@ -1,4 +1,4 @@
1
- // Source: @domma-mail/core 0.29.0, packages/core/src/mail/write.js.
1
+ // Source: @domma-mail/core 0.29.1, packages/core/src/mail/write.js.
2
2
  // Update with domma-mail/scripts/sync-cms.mjs; edit the shared source.
3
3
  /**
4
4
  * Changing mail, rather than reading it.
@@ -59,7 +59,7 @@ import {getRoleLevel, invalidate as invalidateRoles, isBaseRole} from '../../ser
59
59
  import {getEffectiveLevel} from '../../services/userRoles.js';
60
60
  import {getConfig, saveConfig} from '../../config.js';
61
61
  import {riskyConnectionOptions, signedOnly} from '../../services/codePolicy.js';
62
- import {PRESET_COLLECTION_SLUGS, USER_DATA_PRESET_SLUGS} from '../../services/presetCollections.js';
62
+ import {BUILT_IN_SLUGS, USER_DATA_PRESET_SLUGS} from '../../services/presetCollections.js';
63
63
  import {ensureFormForCollection} from '../../services/forms.js';
64
64
  import {hooks} from '../../services/hooks.js';
65
65
  import {DRAFT_STATUS, authenticateApiToken, draftsOnlyDecision, scopeAllows} from '../../services/apiTokens.js';
@@ -136,7 +136,7 @@ import {
136
136
  pluginDenial
137
137
  } from '../../services/collectionAccess.js';
138
138
 
139
- const ALL_PRESET_SLUGS = new Set(['roles', 'user-profiles', ...PRESET_COLLECTION_SLUGS]);
139
+ const ALL_PRESET_SLUGS = BUILT_IN_SLUGS;
140
140
 
141
141
  /** Built-in collections the public surface never writes: every preset bar the user-data ones, and anything systemManaged. */
142
142
  function isSystemCollection(schema) {
@@ -532,7 +532,8 @@ export async function collectionsRoutes(fastify) {
532
532
  if (!canSeeArtefact(request.user, schema)) {
533
533
  return reply.status(403).send({ error: 'Access denied for this project' });
534
534
  }
535
- return schema;
535
+ // builtIn: the editor's "Show on pages" starts off for a built-in (pagesAllowed).
536
+ return {...schema, ...(ALL_PRESET_SLUGS.has(schema.slug) && {builtIn: true})};
536
537
  });
537
538
 
538
539
  fastify.put('/collections/:slug', canUpdate, async (request, reply) => {
@@ -114,7 +114,8 @@ export async function pagesRoutes(fastify) {
114
114
  fastify.post('/pages/preview', {...canRead, config: {keepsCache: true}}, async (request, reply) => {
115
115
  const {markdown} = request.body;
116
116
  if (typeof markdown !== 'string') return reply.status(400).send({error: 'markdown must be a string'});
117
- const {html} = await parseMarkdown(`---\ntitle: preview\n---\n${markdown}`, {user: request.user || null});
117
+ // writerNotes: a tag that draws nothing for a visitor says why here (a [collection] not set to show on pages).
118
+ const {html} = await parseMarkdown(`---\ntitle: preview\n---\n${markdown}`, {user: request.user || null, writerNotes: true});
118
119
  return {html};
119
120
  });
120
121
 
@@ -57,7 +57,9 @@ async function ensureList() {
57
57
  {name: 'email', label: 'Email', type: 'text', required: true},
58
58
  {name: 'at', label: 'At', type: 'text', required: false},
59
59
  {name: 'source', label: 'Source', type: 'text', required: false}
60
- ]
60
+ ],
61
+ // People's addresses: never through the public collections API.
62
+ api: {read: {enabled: false, access: 'admin'}}
61
63
  }).catch(() => {});
62
64
  }
63
65
  }
package/server/server.js CHANGED
@@ -25,6 +25,7 @@ import {notifierFor} from './services/notify.js';
25
25
  import {grantAdminToolDefaults, grantPermissionOnce, load as loadRoles, seed as seedRoles} from './services/roles.js';
26
26
  import {ensureAllProfiles, seed as seedUserProfiles} from './services/userProfiles.js';
27
27
  import {seedAll as seedPresetCollections} from './services/presetCollections.js';
28
+ import {closeToolCollections} from './services/collections.js';
28
29
  import {seedCoreProject, seedDocsProject} from './services/projects.js';
29
30
  import {seedDefaultBlocks} from './services/blocks.js';
30
31
  import {seedDefaultComponents} from './services/components.js';
@@ -263,6 +264,10 @@ await grantAdminToolDefaults().catch(() => {});
263
264
  await seedUserProfiles();
264
265
  await ensureAllProfiles();
265
266
  await seedPresetCollections();
267
+ // Tools' collections created under the old default were readable by anyone: closed once, here.
268
+ await closeToolCollections()
269
+ .then(closed => { if (closed.length) console.warn(`[collections] public read closed on ${closed.length} Tool collection(s): ${closed.join(', ')}`); })
270
+ .catch(() => {});
266
271
  await seedCoreProject();
267
272
  await seedDocsProject(); // built-in Domma Docs project - seeded disabled by default
268
273
  await seedDefaultBlocks();
@@ -30,7 +30,7 @@
30
30
  *
31
31
  * A level-0 user keeps everything - the same bypass rowAccess.js gives them.
32
32
  */
33
- import {USER_DATA_PRESET_SLUGS} from './presetCollections.js';
33
+ import {BUILT_IN_SLUGS, SHARED_TOOL_SLUGS, USER_DATA_PRESET_SLUGS} from './presetCollections.js';
34
34
  import {getPermissionsFor} from './roles.js';
35
35
  import {getEffectiveLevel, getEffectiveRoles} from './userRoles.js';
36
36
  import fs from 'node:fs';
@@ -243,6 +243,34 @@ export function mineAllowed(schema) {
243
243
  return mine === undefined || mine === true;
244
244
  }
245
245
 
246
+ /**
247
+ * May `[collection slug="…"]` show this collection's rows on a page?
248
+ *
249
+ * The tag reads rows with no viewer check: whoever can write page text (a
250
+ * page, a blog post, a survey's intro, a product description, a preview)
251
+ * decides what the public sees. So the collection says whether it may be
252
+ * shown at all - `api.pages`:
253
+ *
254
+ * - `true` / `false`: the site's choice (Collections > API & Export).
255
+ * - absent: yes for a collection somebody made to hold content; no for one
256
+ * that belongs to a Tool (`plugin`), is a built-in (BUILT_IN_SLUGS,
257
+ * `systemManaged`) or holds a form's submissions
258
+ * (`meta.generatedFromForm`) - those hold other people's data.
259
+ *
260
+ * Anything but `true` or absent refuses: a typo narrows rather than opens.
261
+ * `scope="mine"` is not judged here (a viewer's own rows; see mineAllowed).
262
+ *
263
+ * @param {object|null} schema
264
+ * @returns {boolean}
265
+ */
266
+ export function pagesAllowed(schema) {
267
+ if (!schema) return false;
268
+ const pages = schema.api?.pages;
269
+ if (pages !== undefined) return pages === true;
270
+ if (SHARED_TOOL_SLUGS.has(schema.slug) || BUILT_IN_SLUGS.has(schema.slug)) return false;
271
+ return !(schema.plugin || schema.preset || schema.systemManaged || schema.meta?.generatedFromForm);
272
+ }
273
+
246
274
  /**
247
275
  * The list filter that keeps a user-data preset to the caller's own rows, or
248
276
  * null when no filter applies (not a user-data preset, root, or a preset whose
@@ -15,6 +15,7 @@ import * as cache from './cache/index.js';
15
15
  import {typedEntryData} from './entryValues.js';
16
16
  import {toCsv} from '../../public/js/collection-export.mjs';
17
17
  import {fileIn} from './safePath.js';
18
+ import {SHARED_TOOL_SLUGS} from './presetCollections.js';
18
19
 
19
20
  const COLLECTIONS_DIR = path.resolve(config.content.collectionsDir);
20
21
  const TOOL_TRASH_SLUGS = new Set(['notes-notes', 'todo-items', 'contacts-contacts']);
@@ -58,15 +59,62 @@ async function writeSchema(schema) {
58
59
  *
59
60
  * @returns {object}
60
61
  */
61
- function defaultApiAccess() {
62
+ function defaultApiAccess({owned = false} = {}) {
62
63
  return {
63
64
  create: { enabled: false, access: 'admin' },
64
- read: { enabled: true, access: 'public' },
65
+ // A Tool's collection holds the Tool's data (invitations, orders,
66
+ // contacts): nobody reads it through the public API unless the Tool's
67
+ // own schema says so. Open-by-default leaked exactly those rows.
68
+ read: owned ? { enabled: false, access: 'admin' } : { enabled: true, access: 'public' },
65
69
  update: { enabled: false, access: 'admin' },
66
70
  delete: { enabled: false, access: 'admin' }
67
71
  };
68
72
  }
69
73
 
74
+ /** The mark on a Tool's collection whose public read has been through closeToolCollections(). */
75
+ const API_DEFAULT_CLOSED = 'closed';
76
+
77
+ /**
78
+ * Close the public read of every Tool-owned collection that still has the old
79
+ * default (read on, for anyone) - once per collection.
80
+ *
81
+ * Until this rule a collection created with no `api` block was readable by
82
+ * anyone at /api/collections/:slug/public, and several Tools shipped schemas
83
+ * without one. Whether an existing collection is open on purpose or by that
84
+ * default cannot be told from the file, and no Tool relies on it, so it is
85
+ * closed; `apiDefault: 'closed'` records that it was looked at, and a site
86
+ * that then opens it in Collections > API & Export keeps its choice.
87
+ *
88
+ * @returns {Promise<string[]>} the slugs that were closed
89
+ */
90
+ export async function closeToolCollections() {
91
+ await ensureDir();
92
+ let names;
93
+ try {
94
+ names = (await fs.readdir(COLLECTIONS_DIR, {withFileTypes: true})).filter(e => e.isDirectory()).map(e => e.name);
95
+ } catch {
96
+ return [];
97
+ }
98
+ const closed = [];
99
+ for (const name of names) {
100
+ let schema;
101
+ try { schema = await readSchema(name); } catch { continue; }
102
+ if (!(schema?.plugin || SHARED_TOOL_SLUGS.has(schema?.slug)) || schema.apiDefault === API_DEFAULT_CLOSED) continue;
103
+ const read = schema.api?.read;
104
+ const open = read?.enabled === true && read?.access === 'public';
105
+ const next = {...schema, apiDefault: API_DEFAULT_CLOSED};
106
+ if (open) next.api = {...schema.api, read: {...read, enabled: false, access: 'admin'}};
107
+ try {
108
+ await writeSchema(next);
109
+ if (open) {
110
+ closed.push(schema.slug);
111
+ await cache.invalidateTags([`collection:${schema.slug}`]);
112
+ }
113
+ } catch { /* a read-only content directory: the next boot tries again */ }
114
+ }
115
+ return closed;
116
+ }
117
+
70
118
  // ---------------------------------------------------------------------------
71
119
  // Schema (collection) operations - always file-based
72
120
  // ---------------------------------------------------------------------------
@@ -157,10 +205,10 @@ export async function createCollection({title, slug, description = '', fields =
157
205
  title: title.trim(),
158
206
  description: description.trim(),
159
207
  fields,
160
- api: { ...defaultApiAccess(), ...api },
208
+ api: { ...defaultApiAccess({owned: Boolean(plugin)}), ...api },
161
209
  storage: storage || {adapter: 'file'},
162
210
  ...(bundled ? {bundled: true} : {}),
163
- ...(plugin ? {plugin} : {}),
211
+ ...(plugin ? {plugin, apiDefault: API_DEFAULT_CLOSED} : {}),
164
212
  ...(meta != null && {meta}),
165
213
  createdAt: now,
166
214
  updatedAt: now
@@ -196,8 +244,12 @@ export async function updateCollection(slug, updates) {
196
244
  // `api.mine` (see mineAllowed in collectionAccess.js) is kept when an
197
245
  // update's api block does not mention it: clients that rebuild `api` from
198
246
  // the four verbs would otherwise switch a collection's opt-out back on.
199
- if (rest.api && typeof rest.api === 'object' && !('mine' in rest.api) && schema.api && 'mine' in schema.api) {
200
- updated.api = {...rest.api, mine: schema.api.mine};
247
+ // `api.pages` (pagesAllowed, same file) likewise: a choice about showing
248
+ // the rows on pages must not be lost to a client that never heard of it.
249
+ if (rest.api && typeof rest.api === 'object' && schema.api) {
250
+ for (const kept of ['mine', 'pages']) {
251
+ if (!(kept in rest.api) && kept in schema.api) updated.api = {...updated.api, [kept]: schema.api[kept]};
252
+ }
201
253
  }
202
254
 
203
255
  // Preserve the original plugin field (never overwrite)
@@ -17,6 +17,7 @@ import {fileURLToPath} from 'url';
17
17
  import {applyTransforms, getSanitizeExtensions, getShortcodeProcessors} from './hooks.js';
18
18
  import {getConfig} from '../config.js';
19
19
  import {getCollection, listEntries} from './collections.js';
20
+ import {pagesAllowed} from './collectionAccess.js';
20
21
  import {getMenu, navbarOverrideFromAttrs, resolveLocation, resolveMenuDecorations} from './menus.js';
21
22
  import {contentsOverrideFromAttrs} from './pageContents.js';
22
23
  import {buildMenuNav} from './menuRender.js';
@@ -1338,7 +1339,7 @@ async function processViewBlocks(markdown, tagSet, user = null, flags = {}) {
1338
1339
  * @param {string} markdown
1339
1340
  * @returns {Promise<string>}
1340
1341
  */
1341
- async function processCollectionBlocks(markdown, tagSet) {
1342
+ async function processCollectionBlocks(markdown, tagSet, opts = {}) {
1342
1343
  const {scrubbed, restore} = scrubCodeRegions(markdown);
1343
1344
  // Find all [collection ...] shortcodes
1344
1345
  const pattern = /\[collection([^\]]*?)\/\]/gi;
@@ -1357,6 +1358,21 @@ async function processCollectionBlocks(markdown, tagSet) {
1357
1358
  }
1358
1359
  tagSet?.add(`collection:${slug}`);
1359
1360
 
1361
+ // The tag reads rows for whoever wrote the text, with no viewer check,
1362
+ // so the collection itself says whether it may be shown on a page
1363
+ // (pagesAllowed: a Tool's, a built-in's or a form's rows are not,
1364
+ // unless the site switched that on). scope="mine" is a viewer's own
1365
+ // rows, decided later by api.mine.
1366
+ const asked = attrs.scope === 'mine' ? null : await getCollection(slug).catch(() => null);
1367
+ if (asked && !pagesAllowed(asked)) {
1368
+ // The writer is told why, in a preview; a visitor gets nothing.
1369
+ const note = (opts.expiry?.preview || opts.writerNotes)
1370
+ ? `<div class="dm-collection-display dm-collection-empty"><p>${escapeHtmlText(`The collection "${slug}" is not set to be shown on pages. Switch on "Show on pages" in Collections, under API & Export.`)}</p></div>`
1371
+ : '';
1372
+ result = result.replace(fullMatch, () => inertShortcodes(note));
1373
+ continue;
1374
+ }
1375
+
1360
1376
  // scope="mine" can't share the per-role page cache (data is per-user),
1361
1377
  // so emit a hydration placeholder. The public site JS POSTs the raw
1362
1378
  // attrs to /api/collections/render-scope, which re-runs renderCollectionFragment
@@ -5505,7 +5521,7 @@ export async function parseMarkdown(raw, opts = {}) {
5505
5521
  const slots = await processSlottedBlocks(preprocessed, opts, tagSet, flags, slotComponents);
5506
5522
  const {output: withComponents, used: usedComponents} = collectAndRewriteComponents(slots.output);
5507
5523
  for (const component of slotComponents) usedComponents.add(component);
5508
- const withCollection = await processCollectionBlocks(withComponents, tagSet);
5524
+ const withCollection = await processCollectionBlocks(withComponents, tagSet, opts);
5509
5525
  const withView = await processViewBlocks(withCollection, tagSet, opts.user || null, flags);
5510
5526
  const withStaticBlock = await processStaticBlocks(withView, tagSet);
5511
5527
  const menuCtx = opts.urlPath
@@ -12,6 +12,14 @@ const COLLECTIONS_DIR = path.resolve(config.content.collectionsDir);
12
12
  // contacts, enquiries, feedback, notes, categories, posts, comments, to-do
13
13
  // have been removed - they belong to plugins and are seeded on plugin enable.
14
14
 
15
+ /**
16
+ * The outreach Tools' shared lists (people's addresses). Whichever Tool is
17
+ * enabled first makes them, and the unsubscribe page makes the suppression
18
+ * list with no Tool at all - so one of these can exist with no `plugin` mark.
19
+ * They are a Tool's collections all the same.
20
+ */
21
+ export const SHARED_TOOL_SLUGS = new Set(['outreach-contacts', 'outreach-groups', 'outreach-unsubscribes']);
22
+
15
23
  /** A chat preset: system-managed, no public API, MongoDB where the site can have it. */
16
24
  function chatPreset(slug, title, description, fields) {
17
25
  const closed = {enabled: false, access: 'admin'};
@@ -552,6 +560,13 @@ const PRESETS = [
552
560
  /** Slugs exported for use in adapterRegistry and the delete guard. */
553
561
  export const PRESET_COLLECTION_SLUGS = PRESETS.map(p => p.slug);
554
562
 
563
+ /**
564
+ * Every built-in collection, by name. A stored schema cannot be asked: reading
565
+ * one turns `preset` into `bundled` (collections.js readSchema), and `bundled`
566
+ * is also a switch a site can set on a collection of its own.
567
+ */
568
+ export const BUILT_IN_SLUGS = new Set(['roles', 'user-profiles', ...PRESET_COLLECTION_SLUGS]);
569
+
555
570
  /**
556
571
  * The presets that hold people's own data - the Notes, Todo and Contacts
557
572
  * Tools - rather than the site's workings. These, and only these, may live in
@@ -584,12 +599,13 @@ async function keptStorage(schemaPath) {
584
599
  return null;
585
600
  }
586
601
 
587
- /** Whether an existing schema.json switches scope=mine off (`api.mine: false`). */
588
- async function keptMineOff(schemaPath) {
602
+ /** A site's own api choices in an existing schema.json: scope=mine off, and Show on pages on. */
603
+ async function keptChoices(schemaPath) {
589
604
  try {
590
- return JSON.parse(await fs.readFile(schemaPath, 'utf8'))?.api?.mine === false;
605
+ const api = JSON.parse(await fs.readFile(schemaPath, 'utf8'))?.api;
606
+ return {mineOff: api?.mine === false, pagesOn: api?.pages === true};
591
607
  } catch {
592
- return false;
608
+ return {mineOff: false, pagesOn: false};
593
609
  }
594
610
  }
595
611
 
@@ -612,9 +628,14 @@ export async function seedAll() {
612
628
  let written = kept ? {...schema, storage: kept} : schema;
613
629
  // A site's `api.mine: false` (own rows not readable through scope=mine)
614
630
  // survives the rewrite; it only ever narrows access.
615
- if (schema.api?.mine !== false && await keptMineOff(schemaPath)) {
631
+ const choices = await keptChoices(schemaPath);
632
+ if (schema.api?.mine !== false && choices.mineOff) {
616
633
  written = {...written, api: {...(written.api || {}), mine: false}};
617
634
  }
635
+ // So does "Show on pages" switched on for a built-in (pagesAllowed in
636
+ // collectionAccess.js): the site said so, and without this the switch
637
+ // would go back off at every start.
638
+ if (choices.pagesOn) written = {...written, api: {...(written.api || {}), pages: true}};
618
639
  await fs.writeFile(schemaPath, JSON.stringify(written, null, 2) + '\n', 'utf8');
619
640
 
620
641
  try {