From 913c0b44d4635c18cd56b60a83b25e5ee850d79f Mon Sep 17 00:00:00 2001 From: Tanmay Sharma Date: Mon, 24 Nov 2025 20:25:53 +0530 Subject: [PATCH] add billing policy --- app/policies/account_policy.rb | 28 ------------------ app/policies/billing_policy.rb | 29 +++++++++++++++++++ .../enterprise/api/v2/billing_controller.rb | 2 +- 3 files changed, 30 insertions(+), 29 deletions(-) create mode 100644 app/policies/billing_policy.rb diff --git a/app/policies/account_policy.rb b/app/policies/account_policy.rb index bd8fc7b98..61e02ae77 100644 --- a/app/policies/account_policy.rb +++ b/app/policies/account_policy.rb @@ -30,32 +30,4 @@ class AccountPolicy < ApplicationPolicy def toggle_deletion? @account_user.administrator? end - - def v2_pricing_plans? - @account_user.administrator? - end - - def v2_topup_options? - @account_user.administrator? - end - - def v2_topup? - @account_user.administrator? - end - - def v2_subscribe? - @account_user.administrator? - end - - def cancel_subscription? - @account_user.administrator? - end - - def credit_grants? - @account_user.administrator? - end - - def change_pricing_plan? - @account_user.administrator? - end end diff --git a/app/policies/billing_policy.rb b/app/policies/billing_policy.rb new file mode 100644 index 000000000..3ba450e21 --- /dev/null +++ b/app/policies/billing_policy.rb @@ -0,0 +1,29 @@ +class BillingPolicy < ApplicationPolicy + def credit_grants? + @account_user.administrator? + end + + def pricing_plans? + @account_user.administrator? + end + + def topup_options? + @account_user.administrator? + end + + def topup? + @account_user.administrator? + end + + def subscribe? + @account_user.administrator? + end + + def cancel_subscription? + @account_user.administrator? + end + + def change_pricing_plan? + @account_user.administrator? + end +end diff --git a/enterprise/app/controllers/enterprise/api/v2/billing_controller.rb b/enterprise/app/controllers/enterprise/api/v2/billing_controller.rb index 892b6ea10..973c0aebc 100644 --- a/enterprise/app/controllers/enterprise/api/v2/billing_controller.rb +++ b/enterprise/app/controllers/enterprise/api/v2/billing_controller.rb @@ -1,6 +1,6 @@ class Enterprise::Api::V2::BillingController < Api::BaseController before_action :fetch_account - before_action :check_authorization + before_action -> { check_authorization(:billing) } before_action :validate_topup_amount, only: [:topup] rescue_from StandardError, with: :render_error