Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions lib/tasks/flobyte.rake
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ module FlobyteCatalog
BILLING_ENTITY_CODE = "flobyte"
BILLING_ENTITY_NAME = "Flobyte"

# Premium integrations the reseller/agency "SaaS Mode" needs enabled on the
# org (License.premium? is always-on in this fork):
# - multi_entities_enterprise: unlimited billing entities (one per reseller)
# - from_email: per-entity branded from-address on agency invoices
RESELLER_PREMIUM_INTEGRATIONS = %w[multi_entities_enterprise from_email].freeze

# Only the white-label plan meters usage (active flows). Standard tiers are
# flat price + hard feature caps.
METRICS = [
Expand Down Expand Up @@ -91,6 +97,7 @@ module FlobyteCatalog
organization = Organization.find(organization_id)
puts "Seeding Flobyte in organization #{organization.id} (#{organization.name}) dry_run=#{dry_run}\n\n"
ActiveRecord::Base.transaction do
ensure_premium_integrations!(organization, dry_run:)
ensure_billing_entity!(organization, dry_run:)
METRICS.each { |m| ensure_metric!(organization, m, dry_run:) }
FEATURES.each { |f| ensure_feature!(organization, f, dry_run:) }
Expand All @@ -100,6 +107,18 @@ module FlobyteCatalog
puts "\n#{dry_run ? '[dry_run] no changes persisted' : '✓ done'}"
end

def self.ensure_premium_integrations!(organization, dry_run:)
missing = RESELLER_PREMIUM_INTEGRATIONS - organization.premium_integrations
if missing.empty?
puts "✓ premium integrations #{RESELLER_PREMIUM_INTEGRATIONS.inspect}"
return organization
end
puts "+ premium integrations #{missing.inspect}"
return nil if dry_run
organization.update!(premium_integrations: organization.premium_integrations + missing)
organization
end

def self.ensure_billing_entity!(organization, dry_run:)
existing = organization.billing_entities.find_by(code: BILLING_ENTITY_CODE)
return existing if existing
Expand Down
Loading