Skip to content

feat(server): --recipes-only shows guests only the recipes - #621

Merged
LeMyst merged 1 commit into
cooklang:mainfrom
LeMyst:feat/recipes-only-guests
Oct 5, 2026
Merged

LeMyst merged 1 commit into
cooklang:mainfrom
LeMyst:feat/recipes-only-guests

Conversation

@LeMyst

@LeMyst LeMyst commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator

Closes #620.

cook server --recipes-only (or COOK_RECIPES_ONLY=1) keeps visitors who are not signed in to reading recipes and menus. Signed-in users keep everything their role allows. Without a users file nobody can sign in, so every visitor gets the recipes only, which makes a read-only public cookbook.

Recipe page Preferences
recipe preferences

The screenshots were taken as a guest of cook server ./seed --recipes-only. The recipe page has no Shopping/Pantry pills and no Edit or Add to shopping list buttons, and the preferences page shows only the language picker.

What a guest gets

  • Allowed: /, /directory, /random, /recipe (recipes and menus), /preferences, the feeds, /static, GET /api/recipes…, /api/search, pictures under /api/static, and sign-in/out.

  • Everything else:

    • with sign-in on, the API answers 401 and pages redirect to /login?next=…;
    • with sign-in off, the server answers 404.

    This covers /api/static/.shopping-list and other non-picture files in the recipe directory.

How

  • auth::middleware::browses_recipes is an allowlist, so a route added later stays hidden from guests by default. It runs in the existing auth middleware, right after the Viewer is worked out. All routes stay registered, because signed-in users still need them.
  • Viewer::limited_to_recipes applies to anyone not signed in. Such a viewer can do nothing, so the existing can_edit_lists() / can_edit_recipes() guards already hide every editing and shopping control. viewer.recipes_only() hides the remaining preferences sections and the g s / g p shortcuts.
  • Nav links: the request's FeatureFlags are switched off, which hides the Shopping/Pantry links. The visitor's own cookie is left as it was for when they sign in.
  • Preferences page: for a recipes-only viewer, the handler stops naming the server paths.
  • Docs: docs/server.md gets the option, the env var and a "Showing guests only the recipes" section.

Tests

  • Unit tests:
    • the allowlist, including look-alike paths and non-picture /api/static files;
    • the viewer;
    • COOK_RECIPES_ONLY values.
  • tests/server_auth_test.rs:
    • without users, everything but the recipes is 404 and the pages carry no shopping/edit links;
    • with users, a guest is asked to sign in, while a signed-in shopper gets the shopping list but not the editor;
    • the env var turns the mode on, and an empty value doesn't.
  • The readiness probe in that file moved from /api/menus to /api/recipes, which a guest can reach in every mode.
  • cargo fmt, cargo clippy --all-targets and cargo test all pass.

🤖 Generated with Claude Code

`cook server --recipes-only` (or COOK_RECIPES_ONLY=1) keeps visitors who
are not signed in to reading recipes and menus: no shopping list, pantry,
editor, API docs, stats or sync, and a preferences page cut down to the
language picker. Signed-in users keep everything their role allows.
Without a users file nobody can sign in, so every visitor gets the
recipes only, which makes a read-only public cookbook.

The auth middleware decides it from an allowlist (`browses_recipes`), so
a route added later stays hidden from guests by default. Anything else
asks them to sign in (401 for the API, a redirect for pages), or answers
404 when sign-in is off. Files under /api/static are limited to pictures,
so the shopping list and pantry files in the recipe directory stay out of
reach. The guest's Viewer can do nothing, which removes the editing and
shopping controls through the existing `can_*` guards, and the shopping
list and pantry links are turned off for the request without touching
the visitor's own cookie.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@LeMyst

LeMyst commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator Author

@dubadub
What do you think about, I want to share my recipe server but not show to guest what I'm currently cooking, through shopping list.

@LeMyst
LeMyst marked this pull request as ready for review October 3, 2026 20:02
@LeMyst
LeMyst merged commit d682b15 into cooklang:main Oct 5, 2026
6 checks passed
LeMyst added a commit that referenced this pull request Oct 8, 2026
)

The Preferences page listed the full paths of the aisle file, the pantry
file and the recipe directory to anyone who could open it, which with
sign-in on includes guests. That told any visitor the server's directory
layout and, usually, the account it runs as. It came with the new UI in
e200582; since #621 (d682b15) only `--recipes-only` blanked them.

Admins still get the full paths; with sign-in off that is everyone, so a
local server looks as before. Everyone else sees where a file is inside
the recipe directory (`config/aisle.conf`), "Global configuration" for
one outside it, and no Recipe Directory card. "Not configured" is now
translated through the existing `pref-not-configured` key.

Closes #637

Co-authored-by: myst <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(server): show guests only the recipes

1 participant