Skip to content

Commit

Permalink
Merge pull request #127 from aplijobs/fix/newConv
Browse files Browse the repository at this point in the history
Fixes | referral, DNS filtering, and a bit more.
  • Loading branch information
cmm-apli authored Mar 7, 2024
2 parents f2872d9 + 52d7268 commit 20fac61
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
7 changes: 5 additions & 2 deletions app/controllers/widgets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ def set_web_widget

def check_domain
return if Rails.env.development?
return if request.headers['Referer'].downcase.start_with? @web_widget.website_url.downcase

# support multiple domains from same referer header param
domains = @web_widget.website_url.downcase.split("|")
domains.each do |domain|
return if request.headers['Referer'].downcase.start_with? domain
end
Rails.logger.error('web widget does not match with expected domain')
render json: { error: 'web widget does not match with expected domain' }, status: :not_found
end
Expand Down
1 change: 0 additions & 1 deletion app/javascript/widget/components/ChatFooter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ export default {
startNewConversation() {
this.clearConversations();
this.clearConversationAttributes();
this.replaceRoute('prechat-form');
},
async sendTranscript() {
const { email } = this.currentUser;
Expand Down
10 changes: 6 additions & 4 deletions app/javascript/widget/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<script>
import configMixin from '../mixins/configMixin';
import TeamAvailability from 'widget/components/TeamAvailability';
import { mapGetters } from 'vuex';
import { mapGetters, mapActions } from 'vuex';
import routerMixin from 'widget/mixins/routerMixin';
export default {
name: 'Home',
Expand Down Expand Up @@ -43,12 +43,14 @@ export default {
}),
},
methods: {
...mapActions('conversation', [
'clearConversations',
]),
startConversation() {
const ref = new URLSearchParams(window.location.search).get('referral');
if (ref) {
this.$store.dispatch('conversation/createConversation', {});
}
if (this.preChatFormEnabled && !this.conversationSize) {
this.clearConversations();
} else if (this.preChatFormEnabled && !this.conversationSize) {
return this.replaceRoute('prechat-form');
}
return this.replaceRoute('messages');
Expand Down
2 changes: 2 additions & 0 deletions spec/controllers/widgets_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@

describe 'GET /widget' do
it 'renders the page correctly when called with website_token' do
Rails.env = 'development'
get widget_url(website_token: web_widget.website_token)
expect(response).to be_successful
expect(response.body).not_to include(token)
end

it 'renders the page correctly when called with website_token and cw_conversation' do
Rails.env = 'development'
get widget_url(website_token: web_widget.website_token, cw_conversation: token)
expect(response).to be_successful
expect(response.body).to include(token)
Expand Down

0 comments on commit 20fac61

Please sign in to comment.