Files
feuerwerk/src/editor/plugins/PluginsPane.ts
T
adminandClaude Opus 5.5 ceaa44e5b8
game-maker / gate (push) Successful in 2m50s
game-maker / suite (push) Successful in 8m57s
Add roles and a user management tab for admins (#180, #179)
Until now every account could do the same, and managing accounts
meant running make-user.php on the server. Accounts now carry a role,
and admins get a tab in the editor to create, rename, re-role, reset
and delete accounts. Both issues share the same server files, so they
land in one commit.

#180 Roles:
- Every account is admin or user. A missing or unknown role counts as
  user, on the server and in the client.
- auth/session and auth/login return {user, role}.
- Auth::requireAdmin() answers everyone else with 403.
- make-user.php takes the role as a third argument. Without it an
  existing account keeps its role, so a password reset from the CLI
  never demotes an admin.
- Admins see and save other users' projects like their own. Saving
  keeps the original owner.

#179 User management:
- The account menu gets "User management" (admins only) and "Plugins"
  (everyone). Both open the same closable tab, accounts on top and
  plugins below. The fixed Plugins tab is gone.
- Per account: Rename, Role, Password (no old password needed) and
  Delete with a confirmation. "New user..." creates one.
- Each account lists its projects with an Open button.
- Delete is refused while the account still owns projects.
- Renaming moves the projects along and ends every session of the
  account. transfer takes the same lock as save.
- On their own row an admin can only set the password. The last admin
  cannot be demoted or deleted. The server enforces both.
- The account rules live in AccountRules.php and accountRules.ts as
  pure functions, so they are testable without a server.

Findings:
- At 1280 px the Delete button reached past the column edge and was
  not clickable. The name column is flexible now, and module 49 checks
  the layout.
- The server lets an admin delete other users' projects, but the
  editor has no button for it yet. Left open in the issue.

Tests:
- ./check.sh: 148 files, 2214 tests, exit 0 (was 147 / 2204).
- New tests/php/accounts.test.php, 51 checks, plain PHP. CI runs it
  as its own step in the gate job, the host has no PHP.
- New e2e module 49 with 18 checks. CI creates the e2e-admin account
  in serve.sh. Modules 14, 38, 46 and the scaffold follow the new tab.
- e2e 1-16,37,38,45,46,49: all passed, 581 checks.
- Counter-checks: owner on save, admin view, default role and self
  delete in PHP fail 7, 5, 5 and 1 checks. Unchecked requireAdmin,
  a wider column and the caller as owner each fail exactly their
  e2e check.
- Check sum 1314 -> 1333 (+1 in 38, +18 in 49), computed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-23 13:59:04 +02:00

151 lines
5.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { Checkbox, HStack, Label, ScrollContainer, Spacer, Theme, VStack } from '../../ui';
import { TabHeader } from '../TabHeader';
import type { PluginManager, PluginRecord } from './loader';
const NAME_WIDTH = 200;
const VERSION_WIDTH = 70;
const FILE_WIDTH = 200;
/** What one plugin's row says about its state, beside the switch. */
export function statusText(record: PluginRecord): string {
if (record.status === 'failed') return `Failed: ${record.error ?? 'unknown reason'}`;
if (record.error) return `Switched off, but: ${record.error}`;
return record.status === 'active' ? 'Active' : 'Off';
}
/** The name to show: known once the plugin has been active in this session, the file name until then. */
export function displayName(record: PluginRecord): string {
return record.meta?.name ?? '—';
}
class PluginRow extends HStack {
readonly switch: Checkbox;
private readonly nameLabel: Label;
private readonly version: Label;
private readonly file: Label;
private readonly status: Label;
constructor(
public record: PluginRecord,
onToggle: (active: boolean) => void,
) {
super({ gap: Theme.gap, padding: Theme.padding, align: 'center' });
this.minHeight = Theme.rowHeight + Theme.padding;
this.switch = new Checkbox(record.status !== 'inactive');
this.switch.onChange = onToggle;
this.add(this.switch);
this.nameLabel = new Label('', { width: NAME_WIDTH, style: 'bodyBold' });
this.version = new Label('', { width: VERSION_WIDTH, style: 'muted' });
this.file = new Label('', { width: FILE_WIDTH, style: 'muted' });
this.status = new Label('', { style: 'small' });
this.add(this.nameLabel);
this.add(this.version);
this.add(this.file);
this.add(this.status, 1);
this.show(record);
}
show(record: PluginRecord): void {
this.record = record;
this.switch.setChecked(record.status !== 'inactive');
this.nameLabel.setText(displayName(record));
this.version.setText(record.meta?.version ?? '');
this.file.setText(record.file);
this.status.setText(statusText(record));
this.status.setStyle(record.status === 'failed' ? 'warning' : 'small');
}
}
/**
* The plugins (#114, #119), in the user management tab since #179: every file in `data/plugins/` with a switch. Switching one on loads
* and activates it there and then, switching it off takes its tabs and listeners away again – the
* switch is part of the open project, so it travels with it and undo takes it back.
*
* A plugin that is off is never loaded, which is why its row has no name until it has run once:
* reading a name out of it would mean running it.
*/
export class PluginsPane extends VStack {
private readonly hint: Label;
private readonly rows = new VStack();
private readonly scroll = new ScrollContainer();
private readonly empty: Label;
private manager: PluginManager | null = null;
private unsubscribe: (() => void) | null = null;
constructor() {
super();
const header = new TabHeader();
header.add(new Label('Plugins', { style: 'bodyBold' }));
header.add(new Spacer(Theme.padding));
this.hint = new Label('', { style: 'small' });
header.add(this.hint, 1);
this.add(header);
this.empty = new Label('Loading…', { style: 'muted', padding: Theme.padding });
this.rows.add(this.empty);
this.scroll.setContent(this.rows);
this.add(this.scroll, 1);
}
setManager(manager: PluginManager): void {
this.unsubscribe?.();
this.manager = manager;
this.unsubscribe = manager.onChange(() => this.refresh());
this.refresh();
}
/** The list could not even be read; there is nothing to show but why. */
showError(message: string): void {
this.manager = null;
this.empty.setText(message);
this.refresh();
}
/** The rows as drawn, and the switch to click – what the check scripts read. */
debugInfo(): {
rows: { file: string; name: string; status: string; checked: boolean; text: string }[];
} {
return {
rows: this.rowWidgets().map((row) => ({
file: row.record.file,
name: displayName(row.record),
status: row.record.status,
checked: row.switch.checked,
text: statusText(row.record),
})),
};
}
/** The switch of one plugin's row, for the check scripts; null when it has no row. */
switchOf(file: string): Checkbox | null {
return this.rowWidgets().find((row) => row.record.file === file)?.switch ?? null;
}
private rowWidgets(): PluginRow[] {
return this.rows.children.filter((child): child is PluginRow => child instanceof PluginRow);
}
private refresh(): void {
const records = this.manager?.records ?? [];
const rows = this.rowWidgets();
const sameList =
rows.length === records.length && rows.every((row, i) => row.record.file === records[i]?.file);
if (sameList) {
rows.forEach((row, i) => row.show(records[i]!));
} else {
for (const row of rows) row.destroy({ children: true });
for (const record of records) {
const row = new PluginRow(record, (active) => void this.manager?.setActive(record.file, active));
this.rows.add(row);
}
}
const nothing = records.length === 0;
this.empty.visible = nothing;
if (nothing && this.manager) this.empty.setText('No plugins in data/plugins');
this.hint.setText(
nothing ? '' : 'Loaded from data/plugins. The switch belongs to this project and is an undo step.',
);
this.scroll.relayoutContent();
this.relayout();
}
}