domma-cms 1.34.0 → 1.36.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/admin/js/api.js +1 -1
  3. package/admin/js/app.js +2 -2
  4. package/admin/js/lib/image-editor.js +1 -1
  5. package/admin/js/lib/media-arrange.js +1 -1
  6. package/admin/js/lib/media-picker.js +2 -2
  7. package/admin/js/lib/media-upload.js +1 -1
  8. package/admin/js/lib/seo-redirects.js +1 -1
  9. package/admin/js/templates/docs/usage-media.html +6 -0
  10. package/admin/js/templates/media.html +1 -0
  11. package/admin/js/views/media.js +3 -3
  12. package/docs/DommaFeatures.md +3 -0
  13. package/package.json +1 -1
  14. package/plugins/_lib/admin/mail/body-menu.js +1 -1
  15. package/plugins/_lib/admin/mail/cms-host.js +1 -1
  16. package/plugins/_lib/admin/mail/compose-window.js +1 -1
  17. package/plugins/_lib/admin/mail/contacts.js +1 -1
  18. package/plugins/_lib/admin/mail/diagnostics-section.js +1 -1
  19. package/plugins/_lib/admin/mail/drag-drop.js +1 -1
  20. package/plugins/_lib/admin/mail/folder-tree.js +26 -1
  21. package/plugins/_lib/admin/mail/font-controls.js +1 -1
  22. package/plugins/_lib/admin/mail/fonts.js +1 -1
  23. package/plugins/_lib/admin/mail/host-context.js +1 -1
  24. package/plugins/_lib/admin/mail/identity.js +1 -1
  25. package/plugins/_lib/admin/mail/image-senders-section.js +1 -1
  26. package/plugins/_lib/admin/mail/keyboard.js +1 -1
  27. package/plugins/_lib/admin/mail/mail.html +4 -1
  28. package/plugins/_lib/admin/mail/message-actions.js +1 -1
  29. package/plugins/_lib/admin/mail/oauth-panel.js +1 -1
  30. package/plugins/_lib/admin/mail/panes.js +1 -1
  31. package/plugins/_lib/admin/mail/reader-kit.js +9 -3
  32. package/plugins/_lib/admin/mail/reader-runtime.js +154 -6
  33. package/plugins/_lib/admin/mail/reader-view.js +1 -1
  34. package/plugins/_lib/admin/mail/resizable.js +1 -1
  35. package/plugins/_lib/admin/mail/restore-spam.js +1 -1
  36. package/plugins/_lib/admin/mail/rules.js +1 -1
  37. package/plugins/_lib/admin/mail/scheduling.js +1 -1
  38. package/plugins/_lib/admin/mail/section-kit.js +1 -1
  39. package/plugins/_lib/admin/mail/security-note.js +1 -1
  40. package/plugins/_lib/admin/mail/settings-section.js +1 -1
  41. package/plugins/_lib/admin/mail/templates.js +1 -1
  42. package/plugins/_lib/admin/mail/threads.js +1 -1
  43. package/plugins/_lib/admin/mail/vacation.js +1 -1
  44. package/plugins/_lib/admin/mail/when-closed.js +1 -1
  45. package/plugins/_lib/admin/ui/dates.js +1 -1
  46. package/plugins/_lib/admin/ui/resizable.js +1 -1
  47. package/plugins/_lib/domma-mail.lock.json +80 -80
  48. package/plugins/_lib/mail/accountFileStore.js +1 -1
  49. package/plugins/_lib/mail/accountRepository.js +1 -1
  50. package/plugins/_lib/mail/accountRoutes.js +1 -1
  51. package/plugins/_lib/mail/bodyTokenProvider.js +1 -1
  52. package/plugins/_lib/mail/bodyTokens.js +1 -1
  53. package/plugins/_lib/mail/compose.js +1 -1
  54. package/plugins/_lib/mail/defaults.js +1 -1
  55. package/plugins/_lib/mail/envelope.js +1 -1
  56. package/plugins/_lib/mail/folderActions.js +1 -1
  57. package/plugins/_lib/mail/folderRuntime.js +1 -1
  58. package/plugins/_lib/mail/folders.js +1 -1
  59. package/plugins/_lib/mail/imapPoolRuntime.js +1 -1
  60. package/plugins/_lib/mail/mbox.js +1 -1
  61. package/plugins/_lib/mail/message-action.js +1 -1
  62. package/plugins/_lib/mail/messageSecurity.js +1 -1
  63. package/plugins/_lib/mail/messageSecurityProvider.js +1 -1
  64. package/plugins/_lib/mail/networkAddresses.js +1 -1
  65. package/plugins/_lib/mail/networkPolicy.js +1 -1
  66. package/plugins/_lib/mail/oauthAccounts.js +1 -1
  67. package/plugins/_lib/mail/oauthRouteRuntime.js +1 -1
  68. package/plugins/_lib/mail/oauthRuntime.js +1 -1
  69. package/plugins/_lib/mail/pollSchedule.js +1 -1
  70. package/plugins/_lib/mail/poller.js +1 -1
  71. package/plugins/_lib/mail/pollerRuntime.js +1 -1
  72. package/plugins/_lib/mail/priority.js +1 -1
  73. package/plugins/_lib/mail/publicMailbox.js +1 -1
  74. package/plugins/_lib/mail/readRuntime.js +1 -1
  75. package/plugins/_lib/mail/render.js +1 -1
  76. package/plugins/_lib/mail/ruleRunner.js +1 -1
  77. package/plugins/_lib/mail/schedulerRuntime.js +1 -1
  78. package/plugins/_lib/mail/secretProvider.js +1 -1
  79. package/plugins/_lib/mail/secretbox.js +1 -1
  80. package/plugins/_lib/mail/senderAuth.js +1 -1
  81. package/plugins/_lib/mail/sieve.js +1 -1
  82. package/plugins/_lib/mail/smtpService.js +1 -1
  83. package/plugins/_lib/mail/snoozeRuntime.js +1 -1
  84. package/plugins/_lib/mail/store.js +1 -1
  85. package/plugins/_lib/mail/subscriptions.js +1 -1
  86. package/plugins/_lib/mail/syncPlan.js +1 -1
  87. package/plugins/_lib/mail/syncRuntime.js +1 -1
  88. package/plugins/_lib/mail/syncSelection.js +1 -1
  89. package/plugins/_lib/mail/unreadBadge.js +1 -1
  90. package/plugins/_lib/mail/unsubscribe.js +1 -1
  91. package/plugins/_lib/mail/vacationRuntime.js +1 -1
  92. package/plugins/_lib/mail/write.js +1 -1
  93. package/server/routes/api/media.js +3 -1
  94. package/server/routes/api/sidebar.js +2 -2
  95. package/server/services/content.js +26 -2
  96. package/server/services/hooks.js +27 -4
  97. package/server/services/plugins.js +9 -3
  98. package/server/services/renderer.js +3 -1
@@ -18,7 +18,7 @@
18
18
  */
19
19
  import {authenticate as defaultAuthenticate, checkVisibility} from '../../middleware/auth.js';
20
20
  import {isDcmStaff} from '../../services/staffAccess.js';
21
- import {getRegisteredSidebarItems} from '../../services/hooks.js';
21
+ import {getRegisteredSidebarItems, withoutHiddenSidebarUrls} from '../../services/hooks.js';
22
22
  import {filterItemsForUser, getMenu} from '../../services/menus.js';
23
23
  import {isDashboardPro} from '../../services/widgets.js';
24
24
  import {boardName, readPrefs, readSite} from '../../services/dashboardSettings.js';
@@ -51,7 +51,7 @@ export async function sidebarRoutes(fastify, opts = {}) {
51
51
  // renderer needs them to place Tools before it drops them. An item
52
52
  // this user may not see (`visibility`) arrives as a label-less hidden
53
53
  // stub for the same reason - see restrictedStub() in menus.js.
54
- const items = filterItemsForUser(menu.items || [], request.user, {keepHidden: true});
54
+ const items = withoutHiddenSidebarUrls(filterItemsForUser(menu.items || [], request.user, {keepHidden: true}));
55
55
  const label = await dashboardsLabel(request);
56
56
  return {...menu, items: label ? relabel(items, label) : items};
57
57
  });
@@ -387,7 +387,9 @@ export async function deletePage(urlPath) {
387
387
  // ---------------------------------------------------------------------------
388
388
 
389
389
  /**
390
- * List all files in the media directory.
390
+ * List the files at the top of the media directory. A folder is not a file, so
391
+ * it is not listed; what is inside one is still served at its own address
392
+ * (mediaFolderSummary counts it).
391
393
  *
392
394
  * @returns {Promise<object[]>}
393
395
  */
@@ -398,6 +400,7 @@ export async function listMedia() {
398
400
  files.map(async (file) => {
399
401
  const filePath = path.join(MEDIA_DIR, file);
400
402
  const stat = await fs.stat(filePath);
403
+ if (!stat.isFile()) return null;
401
404
  return {
402
405
  name: file,
403
406
  url: `/media/${file}`,
@@ -406,7 +409,28 @@ export async function listMedia() {
406
409
  };
407
410
  })
408
411
  );
409
- return stats.sort((a, b) => b.createdAt.localeCompare(a.createdAt));
412
+ return stats.filter(Boolean).sort((a, b) => b.createdAt.localeCompare(a.createdAt));
413
+ }
414
+
415
+ /**
416
+ * What the media directory holds inside folders, which the flat list above leaves
417
+ * out: how many folders, how many files in them.
418
+ *
419
+ * @returns {Promise<{folders: number, files: number}>}
420
+ */
421
+ export async function mediaFolderSummary() {
422
+ const out = {folders: 0, files: 0};
423
+ async function walk(dir, top) {
424
+ let entries;
425
+ try { entries = await fs.readdir(dir, {withFileTypes: true}); } catch { return; }
426
+ for (const e of entries) {
427
+ if (e.name.startsWith('.') || e.isSymbolicLink()) continue;
428
+ if (e.isDirectory()) { out.folders++; await walk(path.join(dir, e.name), false); }
429
+ else if (!top && e.isFile()) out.files++;
430
+ }
431
+ }
432
+ await walk(MEDIA_DIR, true);
433
+ return out;
410
434
  }
411
435
 
412
436
  /**
@@ -150,17 +150,40 @@ export function registerSidebarItem(opts) {
150
150
  /** Where a Tool's sidebar entry goes when it names no folder. */
151
151
  export const DEFAULT_TOOL_FOLDER = 'tools';
152
152
 
153
- /** Sidebar URLs taken off the sidebar - a built-in Tool a plugin has taken over. */
154
- const _hiddenSidebarUrls = new Set();
153
+ /** Sidebar URLs taken off the sidebar - a built-in Tool a plugin has taken over - and the entry that replaces each, if any. */
154
+ const _hiddenSidebarUrls = new Map();
155
155
 
156
156
  /**
157
157
  * Leave the item with this URL out of the sidebar. For a core Tool whose entry
158
158
  * is registered before the plugins load, so it cannot simply not be registered.
159
159
  *
160
160
  * @param {string} url - e.g. '#/contacts'
161
+ * @param {string|null} [replacedBy] - the plugin entry that takes its place in a saved menu
161
162
  */
162
- export function hideSidebarUrl(url) {
163
- _hiddenSidebarUrls.add(url);
163
+ export function hideSidebarUrl(url, replacedBy = null) {
164
+ _hiddenSidebarUrls.set(url, replacedBy);
165
+ }
166
+
167
+ /**
168
+ * The same for a saved menu (config/menus/admin-sidebar.json, where Media, say, was written long
169
+ * ago): a replaced entry keeps its place and label and points at what replaced it, so the plugin's
170
+ * Tool lands where the admin put the old one; an entry with no replacement goes. The menu on disk
171
+ * is not touched, so a lapsed licence brings the old entry straight back. Pure over its input.
172
+ *
173
+ * @param {object[]} items
174
+ * @returns {object[]}
175
+ */
176
+ export function withoutHiddenSidebarUrls(items) {
177
+ if (!_hiddenSidebarUrls.size) return items;
178
+ const walk = (list) => (list || []).flatMap((it) => {
179
+ if (!it || typeof it !== 'object') return [it];
180
+ if (_hiddenSidebarUrls.has(it.url)) {
181
+ const to = _hiddenSidebarUrls.get(it.url);
182
+ return to ? [{...it, url: to}] : [];
183
+ }
184
+ return [Array.isArray(it.items) ? {...it, items: walk(it.items)} : it];
185
+ });
186
+ return walk(items);
164
187
  }
165
188
 
166
189
  /**
@@ -192,7 +192,7 @@ export function isCorePlugin(name) { return CORE_PLUGINS.has(name); }
192
192
  * same data - and, like supersession, nothing is written down: a lapsed
193
193
  * licence means the plugin does not load and the core Tool is simply back.
194
194
  */
195
- export const BUILT_IN_TOOLS = new Set(['notes', 'todo', 'analytics', 'contacts', 'seo']);
195
+ export const BUILT_IN_TOOLS = new Set(['notes', 'todo', 'analytics', 'contacts', 'seo', 'media']);
196
196
 
197
197
  /** Built-in Tool → {plugin, route}, for the plugins that loaded this boot. */
198
198
  const _toolTakeovers = {};
@@ -583,7 +583,7 @@ export async function registerPlugins(fastify) {
583
583
  // (the admin sends its screen to the plugin - getAdminPluginConfig).
584
584
  for (const [tool, claim] of Object.entries(toolTakeoversOf(manifest, _toolTakeovers))) {
585
585
  _toolTakeovers[tool] = claim;
586
- hideSidebarUrl(`#/${tool}`);
586
+ hideSidebarUrl(`#/${tool}`, claim.route ? `#${claim.route}` : null);
587
587
  fastify.log.info(`[plugins] built-in Tool "${tool}" taken over by "${manifest.name}".`);
588
588
  }
589
589
 
@@ -1368,6 +1368,9 @@ export async function getAdminPluginConfig(viewer = null) {
1368
1368
  const routes = [];
1369
1369
  const views = {};
1370
1370
  const css = [];
1371
+ // A Tool that brings its own media picker (Media Pro's, with folders): every
1372
+ // pickMedia() in the admin opens it. The first one loaded wins.
1373
+ let mediaPicker = null;
1371
1374
  // Per-view plugin identity, so the admin can put the same banner above
1372
1375
  // every plugin screen without each plugin having to render one (and each
1373
1376
  // rendering it differently, which is what it did before).
@@ -1381,6 +1384,9 @@ export async function getAdminPluginConfig(viewer = null) {
1381
1384
 
1382
1385
  if (manifest.admin.sidebar) sidebar.push(...manifest.admin.sidebar);
1383
1386
  if (manifest.admin.routes) routes.push(...manifest.admin.routes);
1387
+ if (!mediaPicker && typeof manifest.admin.mediaPicker === 'string' && manifest.admin.mediaPicker.startsWith(`${manifest.name}/admin/`)) {
1388
+ mediaPicker = manifest.admin.mediaPicker;
1389
+ }
1384
1390
 
1385
1391
  // Auto-stamp view entries with an mtime-based version.
1386
1392
  //
@@ -1446,5 +1452,5 @@ export async function getAdminPluginConfig(viewer = null) {
1446
1452
  const staff = isDcmStaff(viewer);
1447
1453
  const tools = Object.fromEntries(CORE_TOOLS.map(t => [t.name, {displayName: t.displayName, enabled: toolOpenAt(toolStates[t.name], staff)}]));
1448
1454
 
1449
- return { sidebar, routes, views, css, meta, takeovers: getToolTakeovers(), tools };
1455
+ return { sidebar, routes, views, css, meta, takeovers: getToolTakeovers(), tools, mediaPicker };
1450
1456
  }
@@ -1462,7 +1462,9 @@ export async function renderBlogPage(templatePath, data = {}, seoMeta = {}) {
1462
1462
  dconfigScript: ''
1463
1463
  };
1464
1464
 
1465
- return interpolate(template, vars);
1465
+ // The same last step as a page: a Tool's render:afterRender sees a blog post or a Tool's page too. Not a
1466
+ // bare page: its address is a credential, so nothing of a Tool's goes on it.
1467
+ return bare ? interpolate(template, vars) : applyTransforms('render:afterRender', interpolate(template, vars), {page: null});
1466
1468
  }
1467
1469
 
1468
1470
  /**