disallow hq-usps-ops on payment accounts

This commit is contained in:
24c02 2025-12-18 17:11:39 -05:00
parent 204c67f1cb
commit 665bc1dcd2
2 changed files with 16 additions and 1 deletions

View file

@ -51,7 +51,9 @@ class HCB::PaymentAccountsController < ApplicationController
end
def available_organizations
current_user.hcb_oauth_connection.organizations
current_user.hcb_oauth_connection.organizations.reject do |org|
HCB::PaymentAccount::BLOCKED_ORGANIZATION_IDS.include?(org.id)
end
rescue => e
Rails.logger.error "Failed to fetch HCB organizations: #{e.message}"
[]

View file

@ -24,8 +24,21 @@ class HCB::PaymentAccount < ApplicationRecord
belongs_to :user
belongs_to :oauth_connection, class_name: "HCB::OauthConnection", foreign_key: :hcb_oauth_connection_id
BLOCKED_ORGANIZATION_IDS = %w[hq-usps-ops].freeze
validates :organization_id, presence: true, uniqueness: { scope: :user_id }
validates :organization_name, presence: true
validate :organization_not_blocked
private
def organization_not_blocked
if BLOCKED_ORGANIZATION_IDS.include?(organization_id)
errors.add(:organization_id, "is not allowed for payment accounts")
end
end
public
def self.theseus_client
HCBV4::Client.from_credentials(