mirror of
https://github.com/astuto/astuto.git
synced 2025-12-16 03:37:56 +01:00
Add custom domains (#314)
This commit is contained in:
committed by
GitHub
parent
d47c70f576
commit
d17b45c5c4
@@ -1,4 +1,7 @@
|
||||
require 'uri'
|
||||
|
||||
class ApplicationController < ActionController::Base
|
||||
include ApplicationHelper
|
||||
include Pundit::Authorization
|
||||
|
||||
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
|
||||
@@ -16,24 +19,14 @@ class ApplicationController < ActionController::Base
|
||||
end
|
||||
|
||||
def load_tenant_data
|
||||
if Rails.application.multi_tenancy?
|
||||
return if request.subdomain.blank? or RESERVED_SUBDOMAINS.include?(request.subdomain)
|
||||
current_tenant = get_tenant_from_request(request)
|
||||
|
||||
# Load the current tenant based on subdomain
|
||||
current_tenant = Tenant.find_by(subdomain: request.subdomain)
|
||||
if current_tenant.status == "pending" and controller_name != "confirmation" and action_name != "show"
|
||||
redirect_to pending_tenant_path; return
|
||||
end
|
||||
|
||||
if current_tenant.status == "pending" and controller_name != "confirmation" and action_name != "show"
|
||||
redirect_to pending_tenant_path; return
|
||||
end
|
||||
|
||||
if current_tenant.status == "blocked"
|
||||
redirect_to blocked_tenant_path; return
|
||||
end
|
||||
|
||||
redirect_to showcase_url unless current_tenant
|
||||
else
|
||||
# Load the one and only tenant
|
||||
current_tenant = Tenant.first
|
||||
if current_tenant.status == "blocked"
|
||||
redirect_to blocked_tenant_path; return
|
||||
end
|
||||
|
||||
return unless current_tenant
|
||||
|
||||
@@ -61,10 +61,10 @@ class OAuthsController < ApplicationController
|
||||
|
||||
if user
|
||||
oauth_token = user.generate_oauth_token
|
||||
redirect_to add_subdomain_to(method(:o_auth_sign_in_from_oauth_token_url), nil, {user_id: user.id, token: oauth_token})
|
||||
redirect_to get_url_for(method(:o_auth_sign_in_from_oauth_token_url), options: { user_id: user.id, token: oauth_token })
|
||||
else
|
||||
flash[:alert] = I18n.t('errors.o_auth_login_error', name: @o_auth.name)
|
||||
redirect_to add_subdomain_to(method(:new_user_session_url))
|
||||
redirect_to get_url_for(method(:new_user_session_url))
|
||||
end
|
||||
|
||||
elsif reason == 'test'
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user