Add custom domains (#314)

This commit is contained in:
Riccardo Graziosi
2024-03-24 12:54:02 +01:00
committed by GitHub
parent d47c70f576
commit d17b45c5c4
31 changed files with 221 additions and 39 deletions

View File

@@ -1,3 +1,5 @@
require 'httparty'
class TenantsController < ApplicationController
include ApplicationHelper
@@ -66,6 +68,23 @@ class TenantsController < ApplicationController
@tenant = Current.tenant_or_raise!
authorize @tenant
# If the custom domain has changed, we need to provision SSL certificate
custom_domain_response = AddCustomDomainWorkflow.new(
new_custom_domain: params[:tenant][:custom_domain],
current_custom_domain: @tenant.custom_domain
).run
if custom_domain_response == false
render json: {
error: "Error adding custom domain"
}, status: :unprocessable_entity
return
end
# Since custom_domain is unique at db level, we need to set it to nil if it is blank
# to avoid unique constraint violation
params[:tenant][:custom_domain] = nil if params[:tenant][:custom_domain].blank?
if @tenant.update(tenant_update_params)
render json: @tenant
else