diff --git a/html/users.js b/html/users.js
index 064d6d0..4edd95b 100644
--- a/html/users.js
+++ b/html/users.js
@@ -44,6 +44,7 @@ async function boot(){
renderScope();
}
renderCreateForm();
+ renderBulkActions();
loadUsers();
}
@@ -176,6 +177,119 @@ document.addEventListener('change', e => {
}
});
+// ── bulk actions (CR-020, T12.3) ──────────────────────────────────────────────
+// The toolbar offers only what this caller may do: the roles they may grant, the
+// projects they administer, the per-project roles they may hand out. The server
+// re-checks every row anyway (T12.1); this is so nobody is offered a choice that
+// can only fail.
+function renderBulkActions(){
+ const box = document.getElementById('bulk-actions');
+ if(!box || !manages()) return;
+ const grantable = PERM_ROLES.filter(r => (_scope.grantable_roles || []).indexOf(r) >= 0);
+ const projects = (_scope.managed_projects || []).slice()
+ .sort((a,b) => (a.archived?1:0) - (b.archived?1:0));
+ const projRoles = PROJECT_SCOPED_ROLES.filter(r => (_scope.grantable_project_roles || []).indexOf(r) >= 0);
+ const group = (label, inner) => '
'+
+ ''+uesc(label)+''+inner+'
';
+ box.innerHTML =
+ group('Permissions',
+ ''+
+ '') +
+ group('Sign-in',
+ ''+
+ '') +
+ (projects.length ? group('Project access',
+ ''+
+ ''+
+ ''+
+ '') : '');
+}
+
+function selectedIds(){ return _users.filter(u => _selected.has(u.id)).map(u => u.id); }
+function people(n){ return n + ' user' + (n === 1 ? '' : 's'); }
+function selVal(id){ return (document.getElementById(id) || {}).value || ''; }
+function selText(id){
+ const s = document.getElementById(id);
+ return (s && s.selectedIndex >= 0) ? s.options[s.selectedIndex].text : '';
+}
+
+// One path for every bulk action: confirm through the dialog kit with the exact
+// count, send, report row by row, reload. A reload clears the selection, which is
+// right: the rows may have changed underneath it.
+async function runBulk(path, body, ask){
+ const ids = selectedIds();
+ if(!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))+'…');
+ const { status, json } = await api('POST', path, Object.assign({ user_ids: ids }, body));
+ if(status !== 200 || !json || !Array.isArray(json.results)){
+ bannerHtml('bulk-banner', 'bad', '✕ '+uesc(apiError(status, json, ask.title+' failed'))+' Nothing was changed.');
+ return;
+ }
+ showBulkResult(json, ask.title);
+ loadUsers();
+}
+
+// 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).
+function showBulkResult(json, title){
+ const failed = json.results.filter(r => r.status === 'failed');
+ const parts = [json.ok+' changed'];
+ if(json.unchanged) parts.push(json.unchanged+' already set');
+ if(failed.length) parts.push(failed.length+' failed');
+ const kind = !failed.length ? 'ok' : (json.ok + json.unchanged ? 'warn' : 'bad');
+ const lead = (failed.length ? (kind === 'bad' ? '✕ ' : '⚠ ') : '✓ ')+uesc(title)+': '+parts.join(', ')+'.';
+ const list = failed.length
+ ? '