Prevent guests from mutating family configuration

Merged
RY
2mo ago
+156-0

Problem

Guests are read-only by design (see the comment in ConnectorAuthorizable), but the controllers for family-wide configuration had no role check at all. A user with the guest role could:

  • create, rename and delete categories, tags and merchants (including "delete all")
  • create, edit and delete rules, and apply them to existing transactions (apply, apply_all) — rewriting transactions across the whole family, including accounts shared read-only with the guest

Fixes #3992.

What changed

  • Added ApplicationController#require_non_guest!, following the existing require_admin! pattern (redirect + alert for HTML, head :forbidden for turbo_stream/json). Allows member, admin and super_admin; blocks guests.
  • Added before_action :require_non_guest!, except: %i[index] to CategoriesController, TagsController, FamilyMerchantsController and RulesController, so read-only index stays open to guests while every mutation action (including apply/apply_all/confirm, merge, bootstrap, enhance, destroy_all) is gated. Using except: keeps future actions deny-by-default for guests.
  • Also gated the nested Category::DeletionsController and Tag::DeletionsController.
  • Added shared.require_non_guest locale key ("Guests cannot perform this action") to en.yml; other locales fall back via config.i18n.fallbacks.

Read-only views are unchanged; guests still see the pages but can no longer mutate anything through them.

Validation

  • Ran the affected controller tests: 67 runs, 287 assertions, 0 failures, 0 errors. Includes 13 new tests: guest is redirected to the accounts page with no record created/destroyed and no job enqueued; member can still create (all four controllers).
  • Ruby syntax checked on all changed files; YAML parses cleanly.

Possible follow-ups (out of scope): hiding the mutation buttons in views for guests, and auditing the api/v1 category/tag/rule endpoints against the guest role.

Summary by CodeRabbit

  • Access Control
    • Guests can continue viewing category, merchant, rule, and tag lists, but cannot create or delete these items. HTML requests redirect to accounts with an explanatory message; other request types receive a forbidden response.
    • Family members retain the ability to manage these items.