From bce2a07d03fd4be4b09f195d433dbc9eae01c237 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Fri, 12 Apr 2024 15:30:07 +0530 Subject: [PATCH] feat: do not send contact details to the widget (#9223) * refactor: use has_email instead of email * feat: remove usage of details directly in forms * test: update payload * test: fix transcript test * refactor: use computed hasEmail --------- Co-authored-by: Muhsin Keloth --- .../api/v1/widget/conversations_controller.rb | 4 +- app/javascript/widget/api/conversation.js | 5 +-- .../widget/components/ChatFooter.vue | 12 +++--- .../widget/components/PreChat/Form.vue | 12 +++--- .../modules/specs/contact/getters.spec.js | 8 ++-- .../modules/specs/contact/mutations.spec.js | 4 +- .../v1/widget/contacts/set_user.json.jbuilder | 6 +-- .../api/v1/widget/contacts/show.json.jbuilder | 6 +-- .../v1/widget/contacts/update.json.jbuilder | 6 +-- .../api/v1/widget/contacts_controller_spec.rb | 40 +++++++++++++++++-- .../widget/conversations_controller_spec.rb | 4 +- 11 files changed, 70 insertions(+), 37 deletions(-) diff --git a/app/controllers/api/v1/widget/conversations_controller.rb b/app/controllers/api/v1/widget/conversations_controller.rb index 1d1ba8a7e..7e6d84bd2 100644 --- a/app/controllers/api/v1/widget/conversations_controller.rb +++ b/app/controllers/api/v1/widget/conversations_controller.rb @@ -33,10 +33,10 @@ class Api::V1::Widget::ConversationsController < Api::V1::Widget::BaseController end def transcript - if permitted_params[:email].present? && conversation.present? + if conversation.present? && conversation.contact.present? && conversation.contact.email.present? ConversationReplyMailer.with(account: conversation.account).conversation_transcript( conversation, - permitted_params[:email] + conversation.contact.email )&.deliver_later end head :ok diff --git a/app/javascript/widget/api/conversation.js b/app/javascript/widget/api/conversation.js index 5cae5bc13..1060b285d 100755 --- a/app/javascript/widget/api/conversation.js +++ b/app/javascript/widget/api/conversation.js @@ -38,10 +38,9 @@ const setUserLastSeenAt = async ({ lastSeen }) => { { contact_last_seen_at: lastSeen } ); }; -const sendEmailTranscript = async ({ email }) => { +const sendEmailTranscript = async () => { return API.post( - `/api/v1/widget/conversations/transcript${window.location.search}`, - { email } + `/api/v1/widget/conversations/transcript${window.location.search}` ); }; const toggleStatus = async () => { diff --git a/app/javascript/widget/components/ChatFooter.vue b/app/javascript/widget/components/ChatFooter.vue index 2a8ef36dc..20d3d820f 100755 --- a/app/javascript/widget/components/ChatFooter.vue +++ b/app/javascript/widget/components/ChatFooter.vue @@ -87,7 +87,10 @@ export default { return !allowMessagesAfterResolved && status === 'resolved'; }, showEmailTranscriptButton() { - return this.currentUser && this.currentUser.email; + return this.hasEmail; + }, + hasEmail() { + return this.currentUser && this.currentUser.has_email; }, hasReplyTo() { return ( @@ -141,12 +144,9 @@ export default { this.inReplyTo = message; }, async sendTranscript() { - const { email } = this.currentUser; - if (email) { + if (this.hasEmail) { try { - await sendEmailTranscript({ - email, - }); + await sendEmailTranscript(); window.bus.$emit(BUS_EVENTS.SHOW_ALERT, { message: this.$t('EMAIL_TRANSCRIPT.SEND_EMAIL_SUCCESS'), type: 'success', diff --git a/app/javascript/widget/components/PreChat/Form.vue b/app/javascript/widget/components/PreChat/Form.vue index 394b338d5..3ff597c67 100644 --- a/app/javascript/widget/components/PreChat/Form.vue +++ b/app/javascript/widget/components/PreChat/Form.vue @@ -1,7 +1,7 @@