mirror of
https://github.com/storytold/discord-github-ticket-relay.git
synced 2026-11-20 22:41:08 +01:00
Moderator access: one moderator at a time, tool switches, one-click levels, quick sets and copy, floating moderator picker
This commit is contained in:
1 parent
b4ccfe886b
commit
c6fe1623da
6 files changed
+368
-202
No files matched your search
+74
-65
@@ -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%; }
|
||||
}
|
||||
+181
-63
@@ -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 ------------------------------------------------------
|
||||
|
||||
|
||||
+82
-55
@@ -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' }) : ''}</div>`)}`
|
||||
: '';
|
||||
|
||||
// ---- 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`<form id="${formId(m, mobile)}" method="post" action="${b}/members/${m.id}/access" data-async hidden>${csrfField(ctx.csrf)}</form>`;
|
||||
const levelSelect = (m: Member, a: Area, mobile: boolean) => {
|
||||
const level = levelOf(m.access, a);
|
||||
return selectWrap(html`<select name="${a}" form="${formId(m, mobile)}" class="level-select" data-level="${level}" data-tool="${AREAS[a].tool}" aria-label="${nameOf(m)}: ${areaLabel(a)}">${levelsFor(a).map((l) => html`<option value="${l}" ${l === level ? raw('selected') : ''}>${LEVEL_NAMES[l]}</option>`)}</select>`, { 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`<select class="set-select" data-set-levels="${formId(m, mobile)}" ${tool ? html`data-set-group="${tool}"` : ''} data-level="${current ?? 'custom'}" aria-label="${nameOf(m)}: ${label}"><option value="" ${current ? '' : raw('selected')} disabled hidden>Custom</option>${(['none', 'view', 'edit'] as const).map((l) => html`<option value="${l}" ${l === current ? raw('selected') : ''}>${SET_NAMES[l]}</option>`)}</select>`, { sm: true, cls: 'level' });
|
||||
};
|
||||
const who = (m: Member) => html`<span class="who-cell">${avatar(nameOf(m), 24, { src: discordAvatar(m) })}<span><span class="name"><span class="truncate">${nameOf(m)}</span></span><span class="sub truncate">@${m.username}</span></span></span>`;
|
||||
const cells = (render: (m: Member) => SafeHtml | string) => mods.map((m) => html`<td class="lv" data-col="${m.id}">${render(m)}</td>`);
|
||||
// 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`<form id="${formId(m)}" method="post" action="${b}/members/${m.id}/access" data-async hidden>${csrfField(ctx.csrf)}</form>`;
|
||||
// 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`<div class="l">${name}</div><div class="d">${desc}</div>`;
|
||||
// One page: No access / View / Edit, one click.
|
||||
const levelSeg = (m: Member, a: Area) => {
|
||||
const level = levelOf(m.access, a);
|
||||
return html`<div class="lvl-seg" role="radiogroup" aria-label="${nameOf(m)}: ${areaLabel(a)}">${levelsFor(a).map((l) => html`<label><input type="radio" name="${a}" value="${l}" form="${formId(m)}" data-tool="${AREAS[a].tool}" ${l === level ? raw('checked') : ''}><span>${LEVEL_NAMES[l]}</span></label>`)}</div>`;
|
||||
};
|
||||
const toolSection = (m: Member, tool: Tool) => {
|
||||
const open = toolOpen(m, tool);
|
||||
const id = `acc-${m.id}-${tool}`;
|
||||
return html`<section class="acc-tool${open ? ' on expanded' : ''}" data-tool="${tool}">
|
||||
<div class="acc-tool-h">
|
||||
<button type="button" class="acc-expand" aria-expanded="${open ? 'true' : 'false'}" aria-controls="${id}" data-acc-expand>
|
||||
<span class="acc-tile">${icon(TOOL_ICONS[tool], 16)}</span>
|
||||
<span class="acc-tool-t"><span class="n">${TOOL_NAMES[tool]}</span><span class="s" data-tool-summary>${toolSummary(m, tool)}</span></span>
|
||||
${icon('chevron-down', 16, 'chev')}
|
||||
</button>
|
||||
<span class="js-only">${switchInput({ name: '', checked: open, label: `${nameOf(m)}: ${tool === 'tickets' ? 'open every Discord tickets page' : `open ${TOOL_NAMES[tool]}`}`, attrs: html`data-tool-switch` })}</span>
|
||||
</div>
|
||||
<div class="acc-pages" id="${id}">${areasOf(tool).map((a) => html`<div class="acc-page">
|
||||
<div class="acc-page-t"><div class="l">${AREAS[a].name}${always(a)}</div><div class="d">${AREAS[a].desc}</div></div>
|
||||
${levelSeg(m, a)}</div>`)}</div>
|
||||
</section>`;
|
||||
};
|
||||
const editor = (m: Member) => html`<section class="acc-editor" id="mod-${m.id}" data-mod="${m.id}" aria-labelledby="acc-name-${m.id}" ${m.id === selected?.id ? '' : raw('hidden')}>
|
||||
<div class="acc-who">
|
||||
${avatar(nameOf(m), 32, { src: discordAvatar(m) })}
|
||||
<div class="acc-who-t"><h3 id="acc-name-${m.id}" tabindex="-1">${nameOf(m)}</h3><div class="sub">@${m.username} · <span data-acc-summary>${accessCount(m)}</span></div></div>
|
||||
<div class="acc-quick js-only">
|
||||
<div class="seg" role="group" aria-label="Quick set for ${nameOf(m)}">
|
||||
<button type="button" class="seg-item" data-preset="none" title="Only the tickets inbox, view only">Inbox only</button>
|
||||
<button type="button" class="seg-item" data-preset="view" title="View on every page">View all</button>
|
||||
<button type="button" class="seg-item" data-preset="edit" title="Edit on every page">Edit all</button>
|
||||
</div>
|
||||
${mods.length > 1 ? selectWrap(html`<select data-copy-from aria-label="Copy another moderator’s access to ${nameOf(m)}"><option value="">Copy from…</option>${mods.filter((x) => x.id !== m.id).map((x) => html`<option value="${x.id}">${nameOf(x)}</option>`)}</select>`, { sm: true }) : ''}
|
||||
</div>
|
||||
</div>
|
||||
${TOOLS.map((tool) => toolSection(m, tool))}
|
||||
<div class="nojs acc-save"><button type="submit" class="btn sm" form="${formId(m)}">Save ${nameOf(m)}’s access</button></div>
|
||||
</section>`;
|
||||
// Floats at the bottom while the card is in view: pick whose access to change.
|
||||
const switcher = html`<nav class="acc-switcher" aria-label="Choose a moderator">
|
||||
${mods.length > 6 ? html`<label class="acc-find js-only">${icon('search', 14)}<input type="search" placeholder="Find a moderator" aria-label="Find a moderator" autocomplete="off" data-mod-search></label>` : ''}
|
||||
<div class="acc-chips" data-mod-chips>${mods.map((m) => html`<a class="acc-chip" href="${b}/members?mod=${m.id}#moderator-access" data-mod-pick="${m.id}" data-find="${`${nameOf(m)} ${m.username}`.toLowerCase()}" title="${nameOf(m)} · ${accessCount(m)}" ${m.id === selected?.id ? raw('aria-current="true"') : ''}>${avatar(nameOf(m), 24, { src: discordAvatar(m) })}<span class="n">${nameOf(m)}</span><span class="c" data-chip-count>${String(openCount(m))}</span></a>`)}</div>
|
||||
<span class="acc-none small muted" data-mod-none hidden>No moderator matches.</span>
|
||||
</nav>`;
|
||||
|
||||
const matrix = html`<div class="table-wrap only-desktop"><table class="access-matrix">
|
||||
<thead><tr><th class="page-col" scope="col">Page</th>${mods.map((m) => html`<th class="lv" scope="col" id="mod-${m.id}" title="${nameOf(m)}" data-flash data-flash-col="${m.id}" data-flash-alt="mod-m-${m.id}">${who(m)}</th>`)}</tr></thead>
|
||||
<tbody class="all"><tr><th class="page-col" scope="row">${pageLabel('All pages', 'Set every page at once.')}</th>${cells((m) => setSelect(m, false))}</tr></tbody>
|
||||
${TOOLS.map((tool) => {
|
||||
const areas = areasOf(tool);
|
||||
return html`<tbody>
|
||||
<tr class="tool-h"><th class="page-col" scope="rowgroup"><span class="tool-name">${icon(TOOL_ICONS[tool], 16)}${TOOL_NAMES[tool]}</span></th>${cells((m) => (areas.length > 1 ? setSelect(m, false, tool) : ''))}</tr>
|
||||
${areas.map((a) => html`<tr><th class="page-col" scope="row">${pageLabel(html`${AREAS[a].name}${always(a)}`, AREAS[a].desc)}</th>${cells((m) => levelSelect(m, a, false))}</tr>`)}
|
||||
</tbody>`;
|
||||
})}
|
||||
<tfoot class="nojs"><tr><th class="page-col"></th>${cells((m) => html`<button type="submit" class="btn sm" form="${formId(m, false)}">Save</button>`)}</tr></tfoot>
|
||||
</table></div>`;
|
||||
|
||||
const mobileBlocks = html`<div class="only-mobile">${mods.map((m) => html`<details class="mod-block" id="mod-m-${m.id}" data-flash ${mods.length === 1 ? raw('open') : ''}>
|
||||
<summary>${who(m)}<span class="count">${accessCount(m)}</span>${icon('chevron-down', 16, 'chev')}</summary>
|
||||
<div class="acc-row all"><div><div class="lbl">All pages</div><div class="desc">Set every page at once.</div></div>${setSelect(m, true)}</div>
|
||||
${TOOLS.map((tool) => {
|
||||
const areas = areasOf(tool);
|
||||
return html`<div class="acc-tool"><span class="tool-name">${icon(TOOL_ICONS[tool], 16)}${TOOL_NAMES[tool]}</span>${areas.length > 1 ? setSelect(m, true, tool) : ''}</div>
|
||||
${areas.map((a) => html`<div class="acc-row"><div><div class="lbl">${AREAS[a].name}${always(a)}</div><div class="desc">${AREAS[a].desc}</div></div>${levelSelect(m, a, true)}</div>`)}`;
|
||||
})}
|
||||
<div class="nojs card-b tight"><button type="submit" class="btn sm" form="${formId(m, true)}">Save</button></div></details>`)}</div>`;
|
||||
|
||||
// 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`<div class="card access-card${mods.length <= 4 ? ` readable cols-${mods.length}` : ''}" id="moderator-access">
|
||||
<div class="card-h"><div><h2>Moderator access</h2><div class="desc">What each moderator can open, tool by tool. <strong>View</strong> shows a page with its controls turned off; <strong>Edit</strong> lets them change it. GitHub and Discord connections, workspace settings, deployment and members stay with admins.</div></div></div>
|
||||
const modAccess = html`<div class="card access-card readable" id="moderator-access" data-access-editor>
|
||||
<div class="card-h"><div><h2>Moderator access</h2><div class="desc">${mods.length > 1 ? 'Pick a moderator in the bar at the bottom, then open the tools they need. ' : ''}<strong>View</strong> shows a page with its controls turned off; <strong>Edit</strong> lets them change it. GitHub and Discord connections, workspace settings, deployment and members stay with admins.</div></div></div>
|
||||
${mods.length
|
||||
? html`${mods.map((m) => html`${accessForm(m, false)}${accessForm(m, true)}`)}
|
||||
${matrix}
|
||||
${mobileBlocks}
|
||||
<div class="card-note">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.</div>`
|
||||
? html`${mods.map(accessForm)}
|
||||
${mods.map(editor)}
|
||||
<div class="card-note">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.</div>
|
||||
${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)}
|
||||
</div>`;
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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(`<form id="acc-${mod.user.id}" method="post" action="${w()}/members/${mod.user.id}/access" data-async hidden>`);
|
||||
expect(body).toContain(`<form id="acc-m-${mod.user.id}" method="post" action="${w()}/members/${mod.user.id}/access" data-async hidden>`);
|
||||
expect(body).toContain(`id="mod-${mod.user.id}"`);
|
||||
for (const a of AREA_KEYS) expect(body, a).toContain(`name="${a}" form="acc-${mod.user.id}"`);
|
||||
// Inbox can't be turned off; Activity has nothing to edit.
|
||||
const select = (name: string) => body.match(new RegExp(`<select name="${name.replace('.', '\\.')}" form="acc-${mod.user.id}"[^>]*>(.*?)</select>`))![0];
|
||||
expect(select('inbox')).toContain('data-level="edit"');
|
||||
expect(select('inbox')).not.toContain('value="none"');
|
||||
expect(select('triage.activity')).not.toContain('value="edit"');
|
||||
expect(select('triage.prompt')).toContain('<option value="view" selected>View</option>');
|
||||
// A select for every page, and one per tool with more than one page; Custom when they differ.
|
||||
expect(body).toMatch(new RegExp(`data-set-levels="acc-${mod.user.id}"\\s+data-level="custom"`));
|
||||
for (const tool of ['tickets', 'issues', 'triage', 'contributors']) expect(body, tool).toContain(`data-set-levels="acc-${mod.user.id}" data-set-group="${tool}"`);
|
||||
expect(body).not.toContain('data-set-group="setup"');
|
||||
expect(body).toMatch(new RegExp(`data-set-group="issues" data-level="none"`));
|
||||
expect(body).toContain(`<section class="acc-editor" id="mod-${mod.user.id}" data-mod="${mod.user.id}"`);
|
||||
expect(body).toContain(`<h3 id="acc-name-${mod.user.id}" tabindex="-1">mia</h3>`);
|
||||
expect(body).toContain('2 of 19 pages open · 1 editable');
|
||||
// No Access / View / Edit per page: the Inbox can't be turned off, Activity has nothing to edit.
|
||||
const radios = (name: string) => [...body.matchAll(new RegExp(`<input type="radio" name="${name.replace('.', '\\.')}" value="(\\w+)" form="acc-${mod.user.id}"[^>]*?( checked)?>`, 'g'))].map((m) => `${m[1]}${m[2] ? '*' : ''}`);
|
||||
for (const a of AREA_KEYS) expect(radios(a).length, a).toBeGreaterThan(1);
|
||||
expect(radios('inbox')).toEqual(['view', 'edit*']);
|
||||
expect(radios('triage.activity')).toEqual(['none*', 'view']);
|
||||
expect(radios('triage.prompt')).toEqual(['none', 'view*', 'edit']);
|
||||
// Each tool: a switch that opens or closes all of it, and a summary.
|
||||
expect(body).toMatch(/aria-label="mia: open AI triage"\s+checked\s+data-tool-switch/);
|
||||
expect(body).toMatch(/aria-label="mia: open GitHub issues"\s+data-tool-switch/);
|
||||
expect(body).toContain('1 of 6 pages · view only');
|
||||
expect(body).toContain('1 of 5 pages · 1 editable');
|
||||
expect(body).toContain('<section class="acc-tool" data-tool="issues">');
|
||||
// Quick sets, and no moderator bar with only one moderator.
|
||||
expect(body).toContain('data-preset="edit"');
|
||||
expect(body).not.toContain('class="acc-switcher"');
|
||||
const other = await makeAdmin(env, 'noah');
|
||||
await env.server.inject({ method: 'POST', url: `/invite/${await createInvite(env.db, wid(), ws.owner.user.id, 'moderator')}`, ...form(other) });
|
||||
const two = (await page(`/members?mod=${other.user.id}`, ws.owner)).body;
|
||||
expect(two).toContain('class="acc-switcher"');
|
||||
expect(two).toContain(`data-mod-pick="${other.user.id}"`);
|
||||
expect(two).toMatch(new RegExp(`data-mod-pick="${other.user.id}"[^>]*aria-current="true"`));
|
||||
expect(two).toContain(`<section class="acc-editor" id="mod-${mod.user.id}" data-mod="${mod.user.id}" aria-labelledby="acc-name-${mod.user.id}" hidden>`);
|
||||
expect(two).toContain(`<option value="${mod.user.id}">mia</option>`);
|
||||
// The members table sums it up per tool.
|
||||
expect(body).toContain('Inbox: edit');
|
||||
expect(body).toContain('Prompt: view');
|
||||
@@ -159,7 +171,7 @@ describe('Members › Moderator access', () => {
|
||||
// A plain form (no JavaScript) comes back to the card.
|
||||
const plain = await post(`/members/${mod.user.id}/access`, { 'triage.prompt': 'view' }, ws.owner);
|
||||
expect(plain.statusCode).toBe(302);
|
||||
expect(plain.headers.location).toBe(`${w()}/members#moderator-access`);
|
||||
expect(plain.headers.location).toBe(`${w()}/members?mod=${mod.user.id}#moderator-access`);
|
||||
});
|
||||
|
||||
it('no longer has the old routes', async () => {
|
||||
|
||||
@@ -42,7 +42,7 @@ describe('Triage access for moderators', () => {
|
||||
it('is set page by page on the Members page, and saved right away', async () => {
|
||||
const members = await page('/members', ws.owner);
|
||||
expect(members.body).toContain('id="moderator-access"');
|
||||
expect(members.body).toContain(`name="triage.labels" form="acc-${mod.user.id}"`);
|
||||
expect(members.body).toContain(`name="triage.labels" value="edit" form="acc-${mod.user.id}"`);
|
||||
|
||||
const res = await env.server.inject({
|
||||
method: 'POST', url: `${w()}/members/${mod.user.id}/access`,
|
||||
|
||||
Reference in new issue
Block a user