Files
sure/test/controllers/settings/llm_usages_controller_test.rb
Andrew B f8615f0e9c fix(settings): require admin for family-wide advanced settings pages (#2403)
The "Advanced" settings section is gated to admins in the navigation, but
the controllers exposing family-wide data performed no server-side
authorization — any authenticated user could reach them by navigating
directly to the URL.

Add `before_action :require_admin!` to the controllers that expose
family-wide data:
- Settings::AiPromptsController (family AI assistant config)
- Settings::LlmUsagesController (family LLM usage/billing)

This mirrors the existing guards on Settings::ProvidersController and
Settings::HostingsController. Non-admins are redirected with the standard
"Only admins can perform this action" message (403 for turbo_stream/json).

API key and MCP token management are intentionally left open: both are
user-scoped self-management. Their actions are already scoped to
Current.user, and any signed-in user (not just admins) can create an API
key or authorize an MCP client, so gating them would leave members unable
to view or revoke their own credentials.

Adds controller tests covering admin-only access for the family-wide pages
(member and guest rejected) and member self-service access for the API key
and MCP pages.
2026-07-21 09:01:45 +02:00

24 lines
697 B
Ruby

require "test_helper"
class Settings::LlmUsagesControllerTest < ActionDispatch::IntegrationTest
test "admin can view family LLM usage" do
sign_in users(:family_admin)
get settings_llm_usage_path
assert_response :success
end
test "non-admin member cannot view family LLM usage" do
sign_in users(:family_member)
get settings_llm_usage_path
assert_redirected_to accounts_path
assert_equal I18n.t("shared.require_admin"), flash[:alert]
end
test "guest cannot view family LLM usage" do
sign_in users(:intro_user)
get settings_llm_usage_path
assert_redirected_to accounts_path
assert_equal I18n.t("shared.require_admin"), flash[:alert]
end
end