Hide contribution payments from demo user(s) (#738)

* Hide payment contribution options from demo and manually created users

Demo data users and manually created users don't have stripe_customer_id
set on their family, so they should not see payment/contribution options.

Changes:
- Add can_manage_subscription? method to Family::Subscribeable that checks
  for presence of stripe_customer_id
- Guard Settings::PaymentsController to return 403 for users without
  stripe_customer_id
- Guard SubscriptionsController#show action (Stripe portal redirect) for
  users without stripe_customer_id
- Update settings navigation to hide the payment link when
  stripe_customer_id is not present
- Add tests for the new behavior

* Fix broken test

---------

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Juan José Mata
2026-01-23 12:35:49 +01:00
committed by GitHub
parent 5ba051c8cf
commit e0fb585bda
7 changed files with 71 additions and 8 deletions

View File

@@ -1,7 +1,22 @@
require "test_helper"
class Settings::PaymentsControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
setup do
sign_in @user = users(:empty)
@family = @user.family
end
test "returns forbidden when family has no stripe_customer_id" do
assert_nil @family.stripe_customer_id
get settings_payment_path
assert_response :forbidden
end
test "shows payment settings when family has stripe_customer_id" do
@family.update!(stripe_customer_id: "cus_test123")
get settings_payment_path
assert_response :success
end
end