From c6fe1623da9a9f8d26d00a4dff5700fa2cea8946 Mon Sep 17 00:00:00 2001 From: juansebsol Date: Thu, 15 Oct 2026 19:02:43 -0700 Subject: [PATCH] Moderator access: one moderator at a time, tool switches, one-click levels, quick sets and copy, floating moderator picker --- src/web/public/app.css | 139 ++++++++++--------- src/web/public/app.js | 244 +++++++++++++++++++++++++--------- src/web/routes/members.ts | 137 +++++++++++-------- test/apps-access.test.ts | 2 +- test/moderator-access.test.ts | 46 ++++--- test/triage-access.test.ts | 2 +- 6 files changed, 368 insertions(+), 202 deletions(-) diff --git a/src/web/public/app.css b/src/web/public/app.css index 7f262a5..0aede26 100644 --- a/src/web/public/app.css +++ b/src/web/public/app.css @@ -782,7 +782,6 @@ dl.props dd .ic { color: var(--muted); } html:not(.js) [data-reset-fields] { display: none; } .invite-grid { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 12px 16px; align-items: start; } .invite-grid > .lbl { font-weight: 500; line-height: 32px; } -.mod-block + .mod-block { border-top: 1px solid var(--border); } .who-cell .sub { display: block; } .who-cell > span { min-width: 0; } .name { font-weight: 500; } @@ -1073,70 +1072,6 @@ progress.bar.wide { max-width: none; } .nav-item.locked:hover > .ic { color: var(--muted); } .nav-item.locked .trail .ic { color: var(--faint); } .list-row .l2.tri-line-m { overflow: visible; white-space: normal; } -/* ---- Members › Moderator access: pages (rows, grouped by tool) × moderators (columns) ------- */ -/* Levels read at a glance: No access is muted, View is plain, Edit is tinted with the accent. */ -.select.level select { width: 100%; } -.select.level select[data-level="none"], .select.level select[data-level="custom"] { color: var(--muted); } -.select.level select[data-level="edit"] { color: var(--accent-text); background: var(--accent-soft); border-color: var(--info-border); font-weight: 500; } -.select.level select[data-level="edit"]:hover { border-color: var(--accent); } -.select.level select[data-level="edit"] + .ic { color: var(--accent-text); } -/* Separate borders, so the sticky column keeps its lines while the table scrolls. */ -.access-matrix { border-collapse: separate; border-spacing: 0; } -.access-matrix th, .access-matrix td { border-top: 0; } -.access-matrix tbody > tr > * { border-top: 1px solid var(--border); } -.access-matrix tbody:first-of-type > tr:first-child > * { border-top: 0; } -/* The page names stay in view when there are more moderators than fit. */ -.access-matrix .page-col { position: sticky; left: 0; z-index: 1; text-align: left; box-shadow: inset -1px 0 0 var(--border); } -.access-matrix thead .page-col { z-index: 2; } -.access-matrix tbody th.page-col { height: auto; padding: 10px 20px; background: var(--surface); font: inherit; color: var(--text); white-space: normal; vertical-align: middle; } -.access-matrix .page-col .l { font: 500 13px/20px var(--font); min-width: 240px; } -.access-matrix .page-col .l .tag, .acc-row .lbl .tag { margin-left: 6px; vertical-align: 1px; } -.access-matrix .page-col .d { font: 400 12px/16px var(--font); color: var(--muted); max-width: 520px; margin-top: 2px; } -.access-matrix tbody.all .page-col .l { font-weight: 600; } -/* One column per moderator, just wide enough for “No access”. */ -.access-matrix .lv { width: 152px; min-width: 152px; padding: 8px 12px; height: auto; } -.access-matrix .lv:last-child { width: 160px; padding-right: 20px; } -.access-matrix thead .lv { padding-top: 10px; padding-bottom: 10px; } -.access-matrix thead .who-cell { width: 128px; gap: 8px; } -.access-matrix thead .who-cell .name { font: 500 13px/18px var(--font); color: var(--text); } -.access-matrix thead .who-cell .sub { margin-top: 0; font-weight: 400; } -/* A tool: its icon and name, and a select that sets all of its pages. */ -.access-matrix tr.tool-h > * { background: var(--surface-2); padding-top: 8px; padding-bottom: 8px; } -.access-matrix tbody tr.tool-h th.page-col { background: var(--surface-2); padding-top: 8px; padding-bottom: 8px; } -.tool-name { display: inline-flex; align-items: center; gap: 8px; font: 600 13px/20px var(--font); color: var(--text); min-width: 0; } -.tool-name > .ic { color: var(--muted); } -.access-matrix .flash { animation: flash 1200ms var(--ease); } -/* When every column fits, the table doesn't scroll sideways, so its header row can stay in view. */ -@media (min-width: 960px) { - .access-card.cols-1, .access-card.cols-2 { overflow: clip; } - :is(.access-card.cols-1, .access-card.cols-2) .table-wrap { overflow: visible; } - :is(.access-card.cols-1, .access-card.cols-2) .access-matrix thead th { position: sticky; top: 0; z-index: 3; } -} -@media (min-width: 1100px) { - .access-card.cols-3 { overflow: clip; } - .access-card.cols-3 .table-wrap { overflow: visible; } - .access-card.cols-3 .access-matrix thead th { position: sticky; top: 0; z-index: 3; } -} -@media (min-width: 1240px) { - .access-card.cols-4 { overflow: clip; } - .access-card.cols-4 .table-wrap { overflow: visible; } - .access-card.cols-4 .access-matrix thead th { position: sticky; top: 0; z-index: 3; } -} -/* Phones: one block per moderator, folded when there are several. */ -.mod-block > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 8px 16px; } -.mod-block > summary::-webkit-details-marker { display: none; } -.mod-block > summary:focus-visible { outline-offset: -2px; } -.mod-block > summary .who-cell { flex: 1; } -.mod-block > summary .count { font-size: 12px; line-height: 16px; color: var(--muted); white-space: nowrap; } -.mod-block > summary .chev { color: var(--muted); transition: transform var(--t) var(--ease); } -.mod-block[open] > summary .chev { transform: rotate(180deg); } -.mod-block.flash > summary { animation: flash 1200ms var(--ease); } -.acc-tool { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; padding: 6px 16px; background: var(--surface-2); border-top: 1px solid var(--border); } -.acc-row { display: grid; grid-template-columns: minmax(0, 1fr) 128px; gap: 12px; align-items: center; padding: 10px 16px; border-top: 1px solid var(--border); } -.acc-row .lbl { font: 500 13px/20px var(--font); } -.acc-row .desc { font-size: 12px; line-height: 16px; color: var(--muted); margin-top: 2px; } -.acc-row.all .lbl { font-weight: 600; } -.acc-tool .select.level, .acc-row .select.level { width: 128px; } .seg-item.locked { opacity: 0.6; cursor: not-allowed; } .seg-item.locked:hover { color: var(--muted); } .seg-item.locked svg { flex: none; } @@ -1271,3 +1206,77 @@ a.feed-row:focus-visible { outline-offset: -2px; } .feed-sep { display: none; } .feed-row > time { margin-top: 2px; } } + +/* ---- Members › Moderator access: one moderator at a time, tool by tool ------------------------ */ +/* The card lets its moderator header and the floating bar stick to the window. */ +.access-card { overflow: visible; } +.acc-editor[hidden] { display: none; } +/* Whose access this is: stays at the top while you scroll through their tools. */ +.acc-who { position: sticky; top: 0; z-index: 4; display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 14px 20px; background: var(--surface); border-bottom: 1px solid var(--border); } +.acc-who-t { flex: 1; min-width: 180px; } +.acc-who h3 { margin: 0; font: 600 15px/22px var(--font); color: var(--text); } +.acc-who h3:focus { outline: none; } +.acc-who .sub { font-size: 12px; line-height: 16px; color: var(--muted); margin-top: 1px; } +.acc-quick { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; } +.acc-quick .seg-item { font-size: 12px; } +/* A tool: its icon, name and summary (click to open its pages), and a switch to open or close all of it. */ +.acc-tool { border-bottom: 1px solid var(--border); } +.acc-tool-h { display: flex; align-items: center; gap: 12px; padding: 8px 20px 8px 12px; } +.acc-expand { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; padding: 6px 8px; border: 0; border-radius: var(--r-sm); background: transparent; color: var(--text); font: inherit; text-align: left; cursor: pointer; } +.acc-expand:hover { background: var(--nav-hover); } +.acc-expand:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; } +.acc-tile { width: 32px; height: 32px; flex: none; display: grid; place-items: center; border-radius: 8px; background: var(--surface-2); color: var(--faint); transition: background var(--t) var(--ease), color var(--t) var(--ease); } +.acc-tool.on .acc-tile { background: var(--accent-soft); color: var(--accent-text); } +.acc-tool-t { min-width: 0; display: flex; flex-direction: column; } +.acc-tool-t .n { font: 600 14px/20px var(--font); } +.acc-tool:not(.on) .acc-tool-t .n { color: var(--muted); } +.acc-tool-t .s { font-size: 12px; line-height: 16px; color: var(--muted); } +.acc-tool.on .acc-tool-t .s { color: var(--accent-text); } +.acc-expand .chev { margin-left: auto; color: var(--faint); transition: transform var(--t) var(--ease); } +.acc-tool.expanded .acc-expand .chev { transform: rotate(180deg); } +/* Pages fold away until the tool is opened (without JavaScript they're always shown). */ +.js .acc-tool:not(.expanded) .acc-pages { display: none; } +.acc-pages { padding: 0 20px 10px 64px; } +.acc-page { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 16px; align-items: center; padding: 10px 0; border-top: 1px solid var(--border); } +.acc-page .l { font: 500 13px/20px var(--font); color: var(--text); } +.acc-page .l .tag { margin-left: 6px; vertical-align: 1px; } +.acc-page .d { font-size: 12px; line-height: 16px; color: var(--muted); margin-top: 2px; max-width: 560px; } +/* One click per page: No access / View / Edit. Edit is tinted, No access reads as off. */ +.lvl-seg { display: inline-flex; gap: 2px; padding: 2px; border-radius: var(--r-sm); background: var(--surface-2); } +.lvl-seg label { display: contents; } +.lvl-seg input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; } +.lvl-seg span { min-width: 78px; height: 28px; padding: 0 10px; display: inline-flex; align-items: center; justify-content: center; border-radius: var(--r-xs); font: 500 12px/1 var(--font); color: var(--muted); white-space: nowrap; cursor: pointer; transition: color var(--t-fast), background var(--t-fast); } +.lvl-seg span:hover { color: var(--text); } +.lvl-seg input:checked + span { background: var(--seg-selected); color: var(--text); box-shadow: var(--shadow-seg); } +.lvl-seg input[value="none"]:checked + span { color: var(--muted); } +.lvl-seg input[value="edit"]:checked + span { background: var(--accent-soft); color: var(--accent-text); box-shadow: inset 0 0 0 1px var(--info-border); } +.lvl-seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; } +.lvl-seg input:disabled + span { cursor: progress; } +.acc-save { padding: 12px 20px; } +/* Floats at the bottom of the window while the card is in view: pick whose access to change. */ +.acc-switcher { position: sticky; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); z-index: 6; width: fit-content; max-width: calc(100% - 32px); margin: 16px auto; display: flex; align-items: center; gap: 6px; padding: 6px; border: 1px solid var(--border-strong); border-radius: var(--r-full); background: var(--surface); box-shadow: var(--shadow-pop); } +.acc-find { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px; border-radius: var(--r-full); background: var(--surface-2); color: var(--faint); flex: none; } +.acc-find input { width: 150px; border: 0; padding: 0; background: transparent; color: var(--text); font: 400 13px/1 var(--font); outline: none; } +.acc-chips { display: flex; gap: 4px; min-width: 0; overflow-x: auto; scrollbar-width: none; scroll-behavior: smooth; } +.acc-chips::-webkit-scrollbar { display: none; } +.acc-chips.more { -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 32px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 32px), transparent); } +.acc-chip { flex: none; height: 36px; display: inline-flex; align-items: center; gap: 8px; padding: 0 10px 0 6px; border-radius: var(--r-full); color: var(--muted); font: 500 13px/1 var(--font); text-decoration: none; white-space: nowrap; transition: background var(--t-fast), color var(--t-fast); } +.acc-chip:hover { background: var(--nav-hover); color: var(--text); text-decoration: none; } +.acc-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; } +.acc-chip[aria-current="true"] { background: var(--accent-soft); color: var(--accent-text); box-shadow: inset 0 0 0 1px var(--info-border); } +.acc-chip .c { min-width: 18px; height: 18px; padding: 0 5px; border-radius: var(--r-full); background: var(--surface-2); color: var(--muted); font: 600 11px/18px var(--font); text-align: center; font-variant-numeric: tabular-nums; } +.acc-chip[aria-current="true"] .c { background: var(--surface); color: var(--accent-text); } +.acc-none { padding: 0 12px; white-space: nowrap; } +@media (max-width: 720px) { + .acc-who { top: var(--topbar-h); padding: 12px 16px; } + .acc-tool-h { padding: 6px 16px 6px 8px; } + .acc-pages { padding: 0 16px 10px; } + .acc-page { grid-template-columns: minmax(0, 1fr); gap: 8px; } + .lvl-seg { display: flex; } + .lvl-seg span { flex: 1; min-width: 0; } + .acc-switcher { width: auto; max-width: none; margin: 12px; border-radius: 14px; } + .acc-find { flex: 1; } + .acc-find input { width: 100%; } + .acc-switcher:has(.acc-find) { flex-wrap: wrap; } + .acc-switcher:has(.acc-find) .acc-chips { flex-basis: 100%; } +} diff --git a/src/web/public/app.js b/src/web/public/app.js index 12b09ab..59cc8b2 100644 --- a/src/web/public/app.js +++ b/src/web/public/app.js @@ -713,74 +713,192 @@ }); show(); }); - // ---- Members › Moderator access --------------------------------------------------------------- + // ---- Members › Moderator access: one moderator at a time, tool by tool ------------------------ + // + // Every moderator's levels are radios of their own hidden form[data-async], so any change saves + // right away (the handler above posts the whole form). This adds picking a moderator, the tool + // switches, quick sets, copying another moderator's access, and keeps every summary current. - /** The level a page's select can take for "No access / View all / Edit all" (Inbox stays View, Activity tops out at View). */ - function capLevel(select, level) { - var has = [].some.call(select.options, function (o) { return o.value === level; }); - return has ? level : 'view'; - } - /** Each "All pages" and tool select shows the level its pages share, or Custom when they differ. */ - function syncSetLevels(formId) { - var selects = $$('select[form="' + formId + '"]'); - $$('[data-set-levels="' + formId + '"]').forEach(function (ctl) { - var group = ctl.getAttribute('data-set-group'); - var mine = group ? selects.filter(function (x) { return x.getAttribute('data-tool') === group; }) : selects; - var match = ['none', 'view', 'edit'].filter(function (l) { - return mine.every(function (x) { return x.value === capLevel(x, l); }); - })[0]; - ctl.value = match || ''; - ctl.setAttribute('data-level', match || 'custom'); - }); - // A phone block's summary: "12 of 19 pages · 3 editable". - var block = selects[0] && selects[0].closest('details.mod-block'); - var count = block && block.querySelector('summary .count'); - if (count) { - var levels = selects.filter(function (x) { return x.classList.contains('level-select'); }); - var open = levels.filter(function (x) { return x.value !== 'none'; }).length; - var edit = levels.filter(function (x) { return x.value === 'edit'; }).length; - count.textContent = open + ' of ' + levels.length + (levels.length === 1 ? ' page' : ' pages') + (edit ? ' · ' + edit + ' editable' : ' · view only'); + var accCard = document.querySelector('[data-access-editor]'); + if (accCard) (function () { + // Discord tickets always keeps the Inbox, so "closed" means only the inbox. + var INBOX_TOOL = 'tickets'; + function radios(scope) { return $$('input[type="radio"][data-tool]', scope); } + /** Each page's name, its levels (the first is its minimum) and the one chosen. */ + function pages(scope) { + var out = {}; + radios(scope).forEach(function (r) { + var p = out[r.name] || (out[r.name] = { name: r.name, levels: [], value: null }); + p.levels.push(r.value); + if (r.checked) p.value = r.value; + }); + return Object.keys(out).map(function (k) { return out[k]; }); } - } - // "All pages" sets every page of that moderator, a tool's select only that tool's pages; they're saved together. - $$('[data-set-levels]').forEach(function (ctl) { - var formId = ctl.getAttribute('data-set-levels'); - var group = ctl.getAttribute('data-set-group'); - ctl.addEventListener('change', function () { - var selects = $$('select[form="' + formId + '"]').filter(function (x) { return !group || x.getAttribute('data-tool') === group; }); - selects.forEach(function (sel) { - sel.value = capLevel(sel, ctl.value); - sel.setAttribute('data-level', sel.value); + /** The nearest level a page offers: the Inbox can't go below View, Activity can't go above it. */ + function cap(levels, l) { + if (levels.indexOf(l) !== -1) return l; + return l === 'none' ? levels[0] : levels.indexOf('view') !== -1 ? 'view' : levels[levels.length - 1]; + } + function set(scope, name, level) { + radios(scope).forEach(function (r) { if (r.name === name) r.checked = r.value === level; }); + } + function plural(n, word) { return n + ' ' + word + (n === 1 ? '' : 's'); } + /** Rewrites the tool lines, switches, header line and the moderator's chip from the radios. */ + function summarize(ed) { + $$('.acc-tool', ed).forEach(function (sec) { + var ps = pages(sec); + var on = ps.some(function (p) { return p.value !== p.levels[0]; }); + var open = ps.filter(function (p) { return p.value !== 'none'; }).length; + var edit = ps.filter(function (p) { return p.value === 'edit'; }).length; + sec.classList.toggle('on', on); + var sw = $('[data-tool-switch]', sec); + if (sw) sw.checked = on; + var line = $('[data-tool-summary]', sec); + if (line) { + line.textContent = !on ? (sec.getAttribute('data-tool') === INBOX_TOOL ? 'Only the inbox, view only' : 'No access') + : ps.length === 1 ? (edit ? 'Edit' : 'View') + : open + ' of ' + ps.length + ' pages' + (edit ? ' · ' + edit + ' editable' : ' · view only'); + } }); - if (selects[0]) selects[0].dispatchEvent(new Event('change', { bubbles: true })); - else syncSetLevels(formId); - }); - }); - /** The table and the phone blocks each have a form per moderator: the other one follows, so either saves what's shown. */ - function mirrorLevels(form) { - var action = form.getAttribute('action'); - $$('form[data-async]').forEach(function (twin) { - if (twin === form || twin.getAttribute('action') !== action) return; - $$('select.level-select[form="' + twin.id + '"]').forEach(function (x) { - var src = form.elements.namedItem(x.name); - if (!src || src.tagName !== 'SELECT') return; - x.value = src.value; - x.setAttribute('data-level', x.value); + var all = pages(ed); + var openAll = all.filter(function (p) { return p.value !== 'none'; }).length; + var editAll = all.filter(function (p) { return p.value === 'edit'; }).length; + var text = openAll + ' of ' + plural(all.length, 'page') + ' open' + (editAll ? ' · ' + editAll + ' editable' : ' · view only'); + var sum = $('[data-acc-summary]', ed); + if (sum) sum.textContent = text; + var chip = accCard.querySelector('[data-mod-pick="' + ed.getAttribute('data-mod') + '"]'); + if (chip) { + var c = $('[data-chip-count]', chip); + if (c) c.textContent = String(openAll); + chip.title = ($('.n', chip) ? $('.n', chip).textContent + ' · ' : '') + text; + } + } + function expand(sec, open) { + sec.classList.toggle('expanded', open); + var b = $('[data-acc-expand]', sec); + if (b) b.setAttribute('aria-expanded', open ? 'true' : 'false'); + } + /** Saves this moderator: one change event posts their whole form. */ + function save(ed) { + var r = radios(ed).filter(function (x) { return x.checked; })[0]; + if (r) r.dispatchEvent(new Event('change', { bubbles: true })); + } + /** Sets many pages at once (quick sets, tool switches, copying), then opens the tools that are on. */ + function apply(ed, scope, pick) { + pages(scope).forEach(function (p) { set(ed, p.name, cap(p.levels, pick(p))); }); + summarize(ed); + (scope === ed ? $$('.acc-tool', ed) : [scope]).forEach(function (sec) { expand(sec, sec.classList.contains('on')); }); + save(ed); + } + + // Picking a moderator: their editor shows, the address follows (so a reload keeps them). + function pick(id, focus) { + var ed = accCard.querySelector('.acc-editor[data-mod="' + id + '"]'); + if (!ed) return; + $$('.acc-editor', accCard).forEach(function (x) { x.hidden = x !== ed; }); + $$('[data-mod-pick]', accCard).forEach(function (c) { + if (c === accCard.querySelector('[data-mod-pick="' + id + '"]')) c.setAttribute('aria-current', 'true'); + else c.removeAttribute('aria-current'); }); - syncSetLevels(twin.id); + try { + var url = new URL(location.href); + url.searchParams.set('mod', id); + url.hash = 'moderator-access'; + history.replaceState(null, '', url.toString()); + } catch (err) { /* old browser: the link still works */ } + // Keep whose access this is in view. + var who = $('.acc-who', ed); + if (who && who.getBoundingClientRect().top < 0) ed.scrollIntoView({ block: 'start', behavior: reduceMotion ? 'auto' : 'smooth' }); + if (focus) { var h = $('h3', ed); if (h) h.focus({ preventScroll: true }); } + } + + accCard.addEventListener('click', function (e) { + var chip = e.target.closest('[data-mod-pick]'); + if (chip) { + if (e.metaKey || e.ctrlKey || e.shiftKey || e.button > 0) return; + e.preventDefault(); + pick(chip.getAttribute('data-mod-pick'), true); + return; + } + var ex = e.target.closest('[data-acc-expand]'); + if (ex) { + var sec = ex.closest('.acc-tool'); + expand(sec, !sec.classList.contains('expanded')); + return; + } + var preset = e.target.closest('[data-preset]'); + if (preset) { + var ed = preset.closest('.acc-editor'); + var level = preset.getAttribute('data-preset'); + apply(ed, ed, function () { return level; }); + } }); - } - // Each page's select shows its level. - document.addEventListener('change', function (e) { - var sel = e.target; - if (!sel.classList || !sel.classList.contains('level-select')) return; - sel.setAttribute('data-level', sel.value); - var formId = sel.getAttribute('form'); - if (!formId) return; - syncSetLevels(formId); - var form = document.getElementById(formId); - if (form) mirrorLevels(form); - }); + + accCard.addEventListener('change', function (e) { + var t = e.target; + var ed = t.closest('.acc-editor'); + if (!ed) return; + if (t.hasAttribute('data-tool-switch')) { + // On: closed pages open as View (the rest keep their level). Off: back to the minimum. + var sec = t.closest('.acc-tool'); + var on = t.checked; + apply(ed, sec, function (p) { return on ? (p.value === p.levels[0] ? 'view' : p.value) : 'none'; }); + return; + } + if (t.hasAttribute('data-copy-from')) { + var src = accCard.querySelector('.acc-editor[data-mod="' + t.value + '"]'); + var from = {}; + if (src) pages(src).forEach(function (p) { from[p.name] = p.value; }); + if (src) apply(ed, ed, function (p) { return from[p.name] || 'none'; }); + t.value = ''; + return; + } + if (t.type === 'radio' && t.hasAttribute('data-tool')) summarize(ed); + }); + + // With many moderators: type to find one, Enter picks the first match, arrows move along the bar. + var search = accCard.querySelector('[data-mod-search]'); + if (search) { + search.addEventListener('input', function () { + var q = search.value.trim().toLowerCase(); + var shown = 0; + $$('[data-mod-pick]', accCard).forEach(function (c) { + var hit = !q || c.getAttribute('data-find').indexOf(q) !== -1; + c.hidden = !hit; + if (hit) shown++; + }); + var none = accCard.querySelector('[data-mod-none]'); + if (none) none.hidden = shown > 0; + }); + search.addEventListener('keydown', function (e) { + if (e.key !== 'Enter') return; + e.preventDefault(); + var first = $$('[data-mod-pick]', accCard).filter(function (c) { return !c.hidden; })[0]; + if (first) pick(first.getAttribute('data-mod-pick'), true); + }); + } + var chips = accCard.querySelector('[data-mod-chips]'); + if (chips) { + chips.addEventListener('keydown', function (e) { + if (e.key !== 'ArrowLeft' && e.key !== 'ArrowRight') return; + var list = $$('[data-mod-pick]', chips).filter(function (c) { return !c.hidden; }); + var i = list.indexOf(document.activeElement); + if (i === -1) return; + e.preventDefault(); + var next = list[(i + (e.key === 'ArrowRight' ? 1 : -1) + list.length) % list.length]; + next.focus(); + }); + // The chosen moderator is in view in the bar (scrolling the bar only, never the page). + var current = chips.querySelector('[aria-current="true"]'); + if (current) chips.scrollLeft = current.offsetLeft - (chips.clientWidth - current.offsetWidth) / 2; + // More moderators than fit: the bar fades at its end until it's scrolled there. + var fade = function () { chips.classList.toggle('more', chips.scrollWidth - chips.scrollLeft - chips.clientWidth > 4); }; + chips.addEventListener('scroll', fade, { passive: true }); + window.addEventListener('resize', fade); + if (search) search.addEventListener('input', fade); + fade(); + } + })(); // ---- Triage › Actions: modes per source ------------------------------------------------------ diff --git a/src/web/routes/members.ts b/src/web/routes/members.ts index 1e7dc6d..e262d96 100644 --- a/src/web/routes/members.ts +++ b/src/web/routes/members.ts @@ -40,6 +40,7 @@ import { segRadios, selectWrap, submitBtn, + switchInput, tag, timeAgo, when, @@ -97,18 +98,35 @@ function accessTags(m: MemberAccess): SafeHtml { })}`; } -/** "6 of 19 pages · 2 editable", for a moderator's collapsed block on phones. */ +/** Pages a moderator can open (the Inbox included). */ +const openCount = (m: MemberAccess) => AREA_KEYS.filter((a) => levelOf(m.access, a) !== 'none').length; + +/** "6 of 19 pages open · 2 editable" (app.js writes the same after a change). */ function accessCount(m: MemberAccess): string { - const open = AREA_KEYS.filter((a) => levelOf(m.access, a) !== 'none').length; const edit = AREA_KEYS.filter((a) => levelOf(m.access, a) === 'edit').length; - return `${open} of ${plural(AREA_KEYS.length, 'page')}${edit ? ` · ${edit} editable` : ' · view only'}`; + return `${openCount(m)} of ${plural(AREA_KEYS.length, 'page')} open${edit ? ` · ${edit} editable` : ' · view only'}`; +} + +/** A tool is open when it gives more than the minimum (the Inbox is always visible, so it doesn't count). */ +function toolOpen(m: MemberAccess, tool: Tool): boolean { + return areasOf(tool).some((a) => levelOf(m.access, a) !== levelsFor(a)[0]); +} + +/** "3 of 5 pages · 1 editable", "Edit", "No access" (app.js writes the same after a change). */ +function toolSummary(m: MemberAccess, tool: Tool): string { + const areas = areasOf(tool); + if (!toolOpen(m, tool)) return tool === 'tickets' ? 'Only the inbox, view only' : 'No access'; + const open = areas.filter((a) => levelOf(m.access, a) !== 'none').length; + const edit = areas.filter((a) => levelOf(m.access, a) === 'edit').length; + if (areas.length === 1) return edit ? 'Edit' : 'View'; + return `${open} of ${areas.length} pages${edit ? ` · ${edit} editable` : ' · view only'}`; } export function registerMemberRoutes(app: FastifyInstance, web: Web): void { const { deps } = web; const nameOf = (m: { display_name: string | null; username: string }) => m.display_name ?? m.username; - async function renderMembers(ctx: WorkspaceRequestContext, reply: FastifyReply, o: { invite?: boolean; inviteUrl?: string; inviteRole?: string } = {}) { + async function renderMembers(ctx: WorkspaceRequestContext, reply: FastifyReply, o: { invite?: boolean; inviteUrl?: string; inviteRole?: string; mod?: string } = {}) { const b = ctx.base; const ws = ctx.workspace; const [members, invites] = await Promise.all([listMembers(deps.db, ws.id), listInvites(deps.db, ws.id)]); @@ -121,7 +139,7 @@ export function registerMemberRoutes(app: FastifyInstance, web: Web): void { if (m.role === 'owner' || m.id === ctx.user.id) return ''; const name = nameOf(m); return menu([ - m.role === 'moderator' ? { href: `#mod-${m.id}`, label: 'Edit access', icon: 'sliders-horizontal' } : null, + m.role === 'moderator' ? { href: `${b}/members?mod=${m.id}#moderator-access`, label: 'Edit access', icon: 'sliders-horizontal' } : null, owner ? { dialog: `role-${m.id}`, label: 'Change role…', icon: 'user-cog' } : null, owner ? 'sep' : null, owner ? { post: `${b}/members/${m.id}/remove`, label: 'Remove from workspace…', icon: 'user-x', danger: true, confirm: { title: `Remove ${name} from the workspace?`, body: `${name} loses access to the console right away. Their Discord roles aren’t affected.`, label: 'Remove', danger: true } } : null, @@ -163,59 +181,67 @@ export function registerMemberRoutes(app: FastifyInstance, web: Web): void { ${owner ? menu([{ post: `${b}/members/invites/${i.id}/revoke`, label: 'Revoke invite', icon: 'link-2-off', danger: true, confirm: { title: 'Revoke this invite?', body: 'The link stops working right away.', label: 'Revoke invite', danger: true } }], { csrf: ctx.csrf, label: 'Invite actions' }) : ''}`)}` : ''; - // ---- Moderator access: pages (rows, grouped by tool) × moderators (columns) ---------------- + // ---- Moderator access: one moderator at a time, tool by tool -------------------------------- - // Each moderator's selects belong to a hidden form that saves right away (one for the table, one for phones). - const formId = (m: Member, mobile: boolean) => `acc-${mobile ? 'm-' : ''}${m.id}`; - const accessForm = (m: Member, mobile: boolean) => html``; - const levelSelect = (m: Member, a: Area, mobile: boolean) => { - const level = levelOf(m.access, a); - return selectWrap(html``, { sm: true, cls: 'level' }); - }; - // Sets every page (or a whole tool) at once; shows Custom when those pages differ. - const setSelect = (m: Member, mobile: boolean, tool?: Tool) => { - const current = uniformLevel(m, tool ? areasOf(tool) : AREA_KEYS); - const label = tool ? `every ${TOOL_NAMES[tool]} page` : 'every page'; - return selectWrap(html``, { sm: true, cls: 'level' }); - }; - const who = (m: Member) => html`${avatar(nameOf(m), 24, { src: discordAvatar(m) })}${nameOf(m)}@${m.username}`; - const cells = (render: (m: Member) => SafeHtml | string) => mods.map((m) => html`${render(m)}`); + // The moderator being edited: picked in the floating bar (?mod=), else the first. + const selected = mods.find((m) => m.id === o.mod) ?? mods[0]; + // Each moderator's levels belong to a hidden form that saves on every change (JSON reply). + const formId = (m: Member) => `acc-${m.id}`; + const accessForm = (m: Member) => html``; // The Inbox can't be turned off: say so next to its name. const always = (a: Area) => ((AREAS[a] as AreaDef).min ? tag('Always visible', { cls: 'subtle', title: 'Moderators can always see the tickets inbox.' }) : ''); - const pageLabel = (name: SafeHtml | string, desc: string) => html`
${name}
${desc}
`; + // One page: No access / View / Edit, one click. + const levelSeg = (m: Member, a: Area) => { + const level = levelOf(m.access, a); + return html`
${levelsFor(a).map((l) => html``)}
`; + }; + const toolSection = (m: Member, tool: Tool) => { + const open = toolOpen(m, tool); + const id = `acc-${m.id}-${tool}`; + return html`
+
+ + ${switchInput({ name: '', checked: open, label: `${nameOf(m)}: ${tool === 'tickets' ? 'open every Discord tickets page' : `open ${TOOL_NAMES[tool]}`}`, attrs: html`data-tool-switch` })} +
+
${areasOf(tool).map((a) => html`
+
${AREAS[a].name}${always(a)}
${AREAS[a].desc}
+ ${levelSeg(m, a)}
`)}
+
`; + }; + const editor = (m: Member) => html`
+
+ ${avatar(nameOf(m), 32, { src: discordAvatar(m) })} +

${nameOf(m)}

@${m.username} · ${accessCount(m)}
+
+
+ + + +
+ ${mods.length > 1 ? selectWrap(html``, { sm: true }) : ''} +
+
+ ${TOOLS.map((tool) => toolSection(m, tool))} +
+
`; + // Floats at the bottom while the card is in view: pick whose access to change. + const switcher = html``; - const matrix = html`
- ${mods.map((m) => html``)} - ${cells((m) => setSelect(m, false))} - ${TOOLS.map((tool) => { - const areas = areasOf(tool); - return html` - ${cells((m) => (areas.length > 1 ? setSelect(m, false, tool) : ''))} - ${areas.map((a) => html`${cells((m) => levelSelect(m, a, false))}`)} - `; - })} - ${cells((m) => html``)} -
Page${who(m)}
${pageLabel('All pages', 'Set every page at once.')}
${icon(TOOL_ICONS[tool], 16)}${TOOL_NAMES[tool]}
${pageLabel(html`${AREAS[a].name}${always(a)}`, AREAS[a].desc)}
`; - - const mobileBlocks = html`
${mods.map((m) => html`
- ${who(m)}${accessCount(m)}${icon('chevron-down', 16, 'chev')} -
All pages
Set every page at once.
${setSelect(m, true)}
- ${TOOLS.map((tool) => { - const areas = areasOf(tool); - return html`
${icon(TOOL_ICONS[tool], 16)}${TOOL_NAMES[tool]}${areas.length > 1 ? setSelect(m, true, tool) : ''}
- ${areas.map((a) => html`
${AREAS[a].name}${always(a)}
${AREAS[a].desc}
${levelSelect(m, a, true)}
`)}`; - })} -
`)}
`; - - // A few moderators fit a readable width (and the moderators' names follow you down the page); - // more use the whole window, then scroll sideways beside the page names. - const modAccess = html`
-

Moderator access

What each moderator can open, tool by tool. View shows a page with its controls turned off; Edit lets them change it. GitHub and Discord connections, workspace settings, deployment and members stay with admins.
+ const modAccess = html`
+

Moderator access

${mods.length > 1 ? 'Pick a moderator in the bar at the bottom, then open the tools they need. ' : ''}View shows a page with its controls turned off; Edit lets them change it. GitHub and Discord connections, workspace settings, deployment and members stay with admins.
${mods.length - ? html`${mods.map((m) => html`${accessForm(m, false)}${accessForm(m, true)}`)} - ${matrix} - ${mobileBlocks} -
Changes apply right away. Applying or dismissing AI suggestions, on Review, tickets or issues, needs Edit on Review. “Use these settings” on a re-run also needs Edit on Actions, Label groups and Prompt. Edit on Apps & repositories lets them add, change and remove apps; updating the panel in Discord needs Edit on Discord tickets › Panel.
` + ? html`${mods.map(accessForm)} + ${mods.map(editor)} +
Changes save right away. Applying or dismissing AI suggestions, on Review, tickets or issues, needs Edit on Review. “Use these settings” on a re-run also needs Edit on Actions, Label groups and Prompt. Updating the panel in Discord needs Edit on Discord tickets › Panel.
+ ${mods.length > 1 ? switcher : ''}` : empty('users', 'No moderators yet', 'Moderators can read the tickets inbox. Invite someone as a moderator, then choose what else they can open here.', owner ? linkBtn(`${b}/members?invite=1#invite`, 'Invite', { icon: 'user-plus' }) : null)}
`; @@ -255,7 +281,8 @@ export function registerMemberRoutes(app: FastifyInstance, web: Web): void { app.get('/w/:wid/members', async (req, reply) => { const ctx = await web.requireWorkspace(req, reply); if (!ctx) return reply; - return renderMembers(ctx, reply, { invite: (req.query as { invite?: string }).invite === '1' }); + const q = req.query as { invite?: string; mod?: string }; + return renderMembers(ctx, reply, { invite: q.invite === '1', mod: q.mod }); }); app.post('/w/:wid/members/invites', async (req, reply) => { @@ -321,7 +348,7 @@ export function registerMemberRoutes(app: FastifyInstance, web: Web): void { if (web.wantsJson(req)) return reply.code(err.status).send({ ok: false, error: err.message }); setFlash(reply, 'error', err.message); } - return reply.redirect(`${ctx.base}/members#moderator-access`); + return reply.redirect(`${ctx.base}/members?mod=${encodeURIComponent(userId)}#moderator-access`); }); app.post('/w/:wid/members/:userId/remove', async (req, reply) => { diff --git a/test/apps-access.test.ts b/test/apps-access.test.ts index d5868ef..ef4d1bd 100644 --- a/test/apps-access.test.ts +++ b/test/apps-access.test.ts @@ -38,7 +38,7 @@ describe('Apps & repositories access for moderators', () => { await grant(env, wid(), mod.user.id, { 'triage.actions': 'view' }); const members = await page('/members', ws.owner); expect(members.body).toContain('id="moderator-access"'); - expect(members.body).toContain(`name="apps" form="acc-${mod.user.id}"`); + expect(members.body).toContain(`name="apps" value="view" form="acc-${mod.user.id}"`); expect(members.body).toContain('AI triage'); const res = await env.server.inject({ diff --git a/test/moderator-access.test.ts b/test/moderator-access.test.ts index 679f62d..1b641fc 100644 --- a/test/moderator-access.test.ts +++ b/test/moderator-access.test.ts @@ -105,7 +105,7 @@ describe('access map', () => { }); describe('Members › Moderator access', () => { - it('shows every page by tool, one column per moderator, with the levels each page offers', async () => { + it('edits one moderator at a time, tool by tool, with one click per page', async () => { await grant(env, wid(), mod.user.id, { inbox: 'edit', 'triage.prompt': 'view' }); const res = await page('/members', ws.owner); expect(res.statusCode).toBe(200); @@ -113,22 +113,34 @@ describe('Members › Moderator access', () => { expect(body).not.toContain('style="'); expect(body).toContain('id="moderator-access"'); expect(body).not.toContain('id="page-access"'); - // One form per moderator (and one for phones), saved right away. + // One form per moderator, saved on every change; their editor says whose access it is. expect(body).toContain(`