fix: Save hostname for the custom domain in the portal (#5984)

* fix: Save hostname for the custom domain in the portal
This commit is contained in:
Tejaswini Chile 2022-12-03 20:37:56 +05:30 committed by GitHub
parent c8ec397c79
commit 0b5c82ad5f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View file

@ -21,6 +21,7 @@ class Api::V1::Accounts::PortalsController < Api::V1::Accounts::BaseController
def create def create
@portal = Current.account.portals.build(portal_params) @portal = Current.account.portals.build(portal_params)
@portal.custom_domain = parsed_custom_domain
@portal.save! @portal.save!
process_attached_logo process_attached_logo
end end
@ -28,6 +29,7 @@ class Api::V1::Accounts::PortalsController < Api::V1::Accounts::BaseController
def update def update
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
@portal.update!(portal_params) if params[:portal].present? @portal.update!(portal_params) if params[:portal].present?
# @portal.custom_domain = parsed_custom_domain
process_attached_logo process_attached_logo
rescue StandardError => e rescue StandardError => e
Rails.logger.error e Rails.logger.error e
@ -73,4 +75,9 @@ class Api::V1::Accounts::PortalsController < Api::V1::Accounts::BaseController
def set_current_page def set_current_page
@current_page = params[:page] || 1 @current_page = params[:page] || 1
end end
def parsed_custom_domain
domain = URI.parse(@portal.custom_domain)
domain.is_a?(URI::HTTP) ? domain.host : @portal.custom_domain
end
end end

View file

@ -91,7 +91,8 @@ RSpec.describe 'Api::V1::Accounts::Portals', type: :request do
portal_params = { portal_params = {
portal: { portal: {
name: 'test_portal', name: 'test_portal',
slug: 'test_kbase' slug: 'test_kbase',
custom_domain: 'https://support.chatwoot.dev'
}, },
logo: file logo: file
} }
@ -103,6 +104,7 @@ RSpec.describe 'Api::V1::Accounts::Portals', type: :request do
json_response = JSON.parse(response.body) json_response = JSON.parse(response.body)
expect(json_response['name']).to eql('test_portal') expect(json_response['name']).to eql('test_portal')
expect(json_response['logo']['filename']).to eql('avatar.png') expect(json_response['logo']['filename']).to eql('avatar.png')
expect(json_response['custom_domain']).to eql('support.chatwoot.dev')
end end
end end
end end