Repository navigation
feat(server): reader / shopper / editor / admin roles for signed-in users - #563
Merged
Merged
Conversation
…sers
With sign-in on, a signed-in user could change everything. Each user in
users.toml now has a role, and each role can do everything the ones
before it can:
- reader: reads, like a guest
- shopper: also the shopping list and the pantry
- editor: also recipes, menus and title pictures
- admin: also cook.md sync and the editor's language server
A bare hash still means admin, so existing files keep working. Other
roles are written as `{ hash = "…", role = "editor" }`, which an older
server refuses instead of making that user an admin; an unknown role
or key stops the server from starting.
`cook server user add --role <role>` (default admin), `user role <name>
<role>` and a role column in `user list`. Edits keep the entry's form
and its comments.
The middleware now maps each request to the capability it needs; a
write route it does not list still needs the highest one. Roles are read
from the live users file on every request, so a changed role applies at
once without signing anyone out. A signed-in user whose role falls short
gets 403 (a page, not a sign-in redirect loop), and pages leave out the
controls they cannot use; an editor's editor page no longer tries to
reach the language server.
Closes cooklang#559
Co-Authored-By: Claude Opus 5.5 <[email protected]>
LeMyst
force-pushed
the
feat/server-roles
branch
from
September 28, 2026 12:14
a3fec24 to
45e6ae1
Compare
/api/ws/lsp now needs EditRecipes instead of Administer, and the editor page connects to it for everyone who can open that page. The bridge pins the workspace root to the served directory and drops workspace-folder changes; cooklang-language-server 0.2.4 then only lists .cook/.menu file names under that root and reads config/aisle.conf, which an editor can already read. It writes nothing, and --max-lsp-sessions caps the processes it starts. Also translate the error page's title and "Back to recipes" link into German, Spanish, Basque, French and Dutch. They were missing since the error page was added, so the new 403 page was half in English. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Sep 28, 2026
Closed
LeMyst
marked this pull request as ready for review
September 28, 2026 18:06
This was referenced Sep 28, 2026
Member
|
@LeMyst that looks great, thank you! I think it leaves room for future defining own roles with granular access without needing to update interface |
LeMyst
added a commit
that referenced
this pull request
Sep 28, 2026
#563 (2c82f28) and #567 (347e0e2) each added `error-title` and `error-back-home`, under the same `# Errors` block, to the common.ftl of de-DE, es-ES, eu-ES, fr-FR and nl-NL, and merged seconds apart. Fluent refuses a bundle that defines a message twice, so since 347e0e2 every page the server renders panics ("Overriding { kind: Message, id: "error-title" }") and the tests using translations fail with it. The two copies are identical; keep the first. tests/locales_test.rs gains a check that no locale defines a message twice, across all its files, and names each one — rather than leaving dozens of unrelated tests to panic on a poisoned loader. Co-authored-by: myst <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
This was referenced Oct 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #559. Follow-up to #534.
With sign-in on, a signed-in user could change everything. This adds a role to each user in
users.toml. Each role can do everything the ones before it can:readershoppereditoradminDecisions on the issue's open questions
/api/ws/lspto admins, which left editors editing without completions or diagnostics. The server doesn't need that restriction. The bridge rewritesinitializeto the served directory and dropsworkspace/didChangeWorkspaceFolders. cooklang-language-server 0.2.4 only falls back to the document URI's folder when it has no root, and the bridge always gives it one. All it reads is the names of.cook/.menufiles under that root andconfig/aisle.conf: nothing an editor can't already read in the web UI. It writes nothing and starts no processes. What an editor can still do is startcook lspprocesses, and--max-lsp-sessionsalready caps those.shopperrole. The issue's second use case ("ticks off the shopping list and updates the pantry, but doesn't edit recipes") didn't fit the three-role table, so the roles are orderedreader < shopper < editor < admin.user adddefaults toadmin. That is what a plain hash has always meant, so scripts that runcook server user addbehave as before.{ hash = "…", role = "…" }, which an older server refuses instead of making that user an admin.toml::Valueand checked separately, so a mistake names the user:"bob" has an unknown role "chef": use reader, shopper, editor, admin. Unknown keys (rol = …) are still refused, and the server fails closed at startup.Users file
[users.bob]sub-tables work too.CLI
The role argument uses clap's possible values, so
--helpand the shell completions list the four roles.passwdkeeps the role androlekeeps the password. Both keep the entry's form (bare string, inline table or sub-table) and the comments around it.Server
Viewercarries the role.can_edit()is replaced bycan(Capability), pluscan_edit_lists()/can_edit_recipes()/can_admin()for the templates.auth::middleware::required_capabilitymaps each request to aCapability:WRITESneedsAdminister, so a new route is kept to admins until someone lists it./new,/edit,/api/ws/lsp→ recipes;/api/sync→ admin.Auth::viewerreads the role from the live users file on every request, socook server user roleapplies to the next request without a restart or a new sign-in.401or the sign-in redirect. A signed-in user whose role falls short gets403: JSON for the API, and a translated error page for/newand/edit(redirecting to sign-in there would loop, because the login page sends signed-in users straight back).window.__CAN_EDIT__is renamed__CAN_EDIT_LISTS__, since the shopping list page is the only thing that reads it.Tests
/api/pantryx,/api/recipes-bulk);Viewer.tests/server_auth_test.rs):each_role_can_do_only_what_it_allows: each role against list and pantry writes, recipe saves (file checked on disk),/editand/new,/api/ws/lsp,/api/sync/statusand/api/sync/logout, and which controls the recipe, home, editor and preferences pages render;a_changed_role_applies_without_signing_in_again;a_refused_page_is_translated_throughout: the403page in French, title and link included;user_commands_manage_roles;refuses_a_users_file_with_an_unknown_role.cargo fmt --check,cargo clippy --all-targets(no warnings), andcargo testall pass. The Playwright chromium project: 185 passed, 5 skipped.Docs
docs/server.mdhas a new Roles section and updated users-file and command tables.docs/api.md(regenerated fromsrc/web/api_docs.rs) documents the new403, and CLAUDE.md describes the capability table. The newrole-forbiddenstring is translated into all eight locales.Out of scope
Per-folder and per-recipe access, as the issue says. Nothing here depends on it or gets in its way: a future viewer-scoped data layer can take the same
Viewer.🤖 Generated with Claude Code