feat/wave-12-bulk-users #4

Merged
m.mabrey merged 9 commits from feat/wave-12-bulk-users into main 2026-10-06 22:41:39 +00:00
2 changed files with 61 additions and 4 deletions
Showing only changes of commit 1c4d1bbccb - Show all commits

View File

@@ -212,7 +212,9 @@ function renderBulkActions(){
projRoles.map(r => '<option value="'+r+'">Role: '+uesc(PERM_LABELS[r])+' here</option>').join('')+ projRoles.map(r => '<option value="'+r+'">Role: '+uesc(PERM_LABELS[r])+' here</option>').join('')+
'</select>'+ '</select>'+
'<button type="button" onclick="bulkProject(\'add\')">Add to project</button>'+ '<button type="button" onclick="bulkProject(\'add\')">Add to project</button>'+
'<button type="button" onclick="bulkProject(\'remove\')">Remove from project</button>') : ''); '<button type="button" onclick="bulkProject(\'remove\')">Remove from project</button>') : '') +
group('Delete',
'<button type="button" class="danger" onclick="bulkDelete()">Delete selected…</button>');
} }
function selectedIds(){ return _users.filter(u => _selected.has(u.id)).map(u => u.id); } function selectedIds(){ return _users.filter(u => _selected.has(u.id)).map(u => u.id); }
@@ -230,16 +232,44 @@ async function runBulk(path, body, ask){
const ids = selectedIds(); const ids = selectedIds();
if(!ids.length) return; if(!ids.length) return;
if(!(await wpConfirmDialog({title: ask.title, okLabel: ask.ok, message: ask.message(ids.length)}))) return; if(!(await wpConfirmDialog({title: ask.title, okLabel: ask.ok, message: ask.message(ids.length)}))) return;
bannerHtml('bulk-banner', '', uesc(ask.title)+': working on '+uesc(people(ids.length))+'…'); return sendBulk(path, body, ask.title, ids);
}
async function sendBulk(path, body, title, ids){
bannerHtml('bulk-banner', '', uesc(title)+': working on '+uesc(people(ids.length))+'…');
const { status, json } = await api('POST', path, Object.assign({ user_ids: ids }, body)); const { status, json } = await api('POST', path, Object.assign({ user_ids: ids }, body));
if(status !== 200 || !json || !Array.isArray(json.results)){ if(status !== 200 || !json || !Array.isArray(json.results)){
bannerHtml('bulk-banner', 'bad', '✕ '+uesc(apiError(status, json, ask.title+' failed'))+' Nothing was changed.'); bannerHtml('bulk-banner', 'bad', '✕ '+uesc(apiError(status, json, title+' failed'))+' Nothing was changed.');
return; return;
} }
showBulkResult(json, ask.title); showBulkResult(json, title);
loadUsers(); loadUsers();
} }
// T12.5: delete is permanent (a hard delete, as for one account) and one bad
// multi-select now removes many, so it asks more than the other actions do:
// every affected username is listed, and nothing is sent until the word DELETE
// is typed, whatever the count (confirmed 2026-10-06). Your own account cannot
// be selected; if it ever reached the request, the server refuses that row and
// the report names it.
async function bulkDelete(){
const chosen = _users.filter(u => _selected.has(u.id));
if(!chosen.length) return;
const n = chosen.length;
const typed = await wpPromptDialog({
title: 'Delete '+people(n),
message: 'Delete '+(n === 1 ? 'this account' : 'these '+n+' accounts')+'? Each one, and every project '+
'assignment it has, is removed. This cannot be undone. Disable them instead if you only want to '+
'block sign-in.\n\n'+chosen.map(u => '• '+u.username+(u.full_name ? ' ('+u.full_name+')' : '')).join('\n'),
label: 'Type DELETE to confirm',
value: '',
okLabel: 'Delete '+people(n),
validate: v => v === 'DELETE' ? '' : 'Type DELETE, in capital letters, to confirm.',
});
if(typed !== 'DELETE') return;
return sendBulk('/api/auth/bulk-users/delete', {}, 'Delete accounts', chosen.map(u => u.id));
}
// Every row is accounted for: changed, already so, or failed with the server's // Every row is accounted for: changed, already so, or failed with the server's
// reason. A batch that partly failed never reads as a success (CR-020). // reason. A batch that partly failed never reads as a success (CR-020).
function showBulkResult(json, title){ function showBulkResult(json, title){

View File

@@ -112,6 +112,33 @@ def main():
chk("cancel means no: bob is still an account", chk("cancel means no: bob is still an account",
st == 200 and any(u.get("username") == "bob" for u in (users or [])), st == 200 and any(u.get("username") == "bob" for u in (users or [])),
ascii_([u.get("username") for u in (users or [])])) ascii_([u.get("username") for u in (users or [])]))
# CR-020 / T12.5: the bulk delete is a PROMPT-style dialog (typed DELETE),
# the kind this file's docstring says belongs back here.
print("\n4. bulk delete needs the typed word")
page.eval("(() => { const b=[...document.querySelectorAll('input.selbox')]"
".find(x => x.dataset.id==='user_bob'); b.click(); })()")
time.sleep(0.3)
chk("ticking a row shows the bulk bar",
page.eval("!document.getElementById('bulk-bar').hidden"))
page.eval("document.querySelector('[onclick=\"bulkDelete()\"]').click()")
time.sleep(0.4)
chk("the bulk delete asks through the kit's prompt, listing the username",
page.eval("(() => { const o=document.getElementById('wp-dlg-overlay');"
" return o.classList.contains('open')"
" && document.getElementById('wp-dlg-input-wrap').style.display !== 'none'"
" && /bob/.test(document.getElementById('wp-dlg-msg').textContent); })()"))
page.eval("document.getElementById('wp-dlg-input').value='delete';"
"document.getElementById('wp-dlg-ok').click()")
time.sleep(0.3)
chk("the wrong word keeps it open and names what to type",
page.eval("document.getElementById('wp-dlg-overlay').classList.contains('open')"
" && /DELETE/.test(document.getElementById('wp-dlg-err').textContent)"))
page.eval("document.getElementById('wp-dlg-cancel').click()")
time.sleep(0.6)
st, users = api(base, "/api/auth/users", tok["root"])
chk("cancel means no: bob is still an account after the bulk prompt",
st == 200 and any(u.get("username") == "bob" for u in (users or [])))
errs = [e for e in page.js_errors() if "beforeunload" not in e] errs = [e for e in page.js_errors() if "beforeunload" not in e]
chk("no JavaScript errors, and no path reached a native dialog (they throw here)", chk("no JavaScript errors, and no path reached a native dialog (they throw here)",
not errs, ascii_(errs[:3])) not errs, ascii_(errs[:3]))