Files
Docwell/Database/pb_hooks/docwell.pb.js
T
tajniak81andClaude Opus 5.5 03f3434c10 Add organizations with cascading user rights
Same model as DriverVault, with organizations above workspaces:

- users get a role (user, admin, superadmin) and at most one
  organization; existing instance admins become superadmins
- rights cascade: superadmins own everything, org admins own their
  organization's workspaces, others get their workspace role
  (owner > admin > member > guest) while they stay in the org
- nobody grants a role above their own, acts on someone ranked above
  them, or changes their own role; rules live in internal/access as
  pure, tested functions
- self-service organizations: an org-less user creates one and becomes
  its admin; the last admin can delete it and is demoted
- endpoints for users, orgs, workspaces and members; token cache is
  dropped when a user's rights change
- admin panel: Users and Organizations pages scoped to the caller
- web app: organization page, workspace list, workspace settings with
  member management (EN/PL)
- fix: organization name missing after login/refresh, and stale tokens
  redirecting public pages to sign-in

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 22:53:11 +01:00

42 lines
1.4 KiB
JavaScript

/// <reference path="../pb_data/types.d.ts" />
// Token check used by docwell-server: returns the "users" record that owns the
// bearer token (with its organization expanded), or 401. Unlike auth-refresh,
// it does not issue a new token.
routerAdd(
"GET",
"/api/docwell/auth/verify",
(e) => {
e.auth.ignoreEmailVisibility(true);
e.app.expandRecord(e.auth, ["organization"], null);
return e.json(200, e.auth);
},
$apis.requireAuth("users"),
);
// Instance settings come from the environment and are applied on every start,
// so changing an env var and restarting is enough.
onBootstrap((e) => {
e.next();
const env = (key, def) => $os.getenv(key) || def;
const settings = e.app.settings();
settings.meta.appName = env("DOCWELL_APP_NAME", "Docwell");
settings.meta.appURL = env("DOCWELL_WEB_URL", "http://localhost:3000");
settings.meta.senderName = settings.meta.appName;
settings.meta.senderAddress = env("DOCWELL_MAIL_FROM", "no-reply@docwell.localhost");
const smtpHost = env("DOCWELL_SMTP_HOST", "");
settings.smtp.enabled = smtpHost !== "";
if (smtpHost) {
settings.smtp.host = smtpHost;
settings.smtp.port = parseInt(env("DOCWELL_SMTP_PORT", "587"), 10);
settings.smtp.username = env("DOCWELL_SMTP_USERNAME", "");
settings.smtp.password = env("DOCWELL_SMTP_PASSWORD", "");
settings.smtp.tls = env("DOCWELL_SMTP_TLS", "false") === "true";
}
e.app.save(settings);
});