Merge pull request #217 from shariquerik/email-signature

fix: append user email signature if content is empty
This commit is contained in:
Shariq Ansari 2024-06-11 12:30:08 +05:30 committed by GitHub
commit bc80e54fe3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 80 additions and 19 deletions

View File

@ -1,5 +1,7 @@
from bs4 import BeautifulSoup
import frappe
from frappe.translate import get_all_translations
from frappe.utils import cstr
@frappe.whitelist(allow_guest=True)
@ -9,4 +11,37 @@ def get_translations():
else:
language = frappe.db.get_single_value("System Settings", "language")
return get_all_translations(language)
return get_all_translations(language)
@frappe.whitelist()
def get_user_signature():
user = frappe.session.user
user_email_signature = (
frappe.db.get_value(
"User",
user,
"email_signature",
)
if user
else None
)
signature = user_email_signature or frappe.db.get_value(
"Email Account",
{"default_outgoing": 1, "add_signature": 1},
"signature",
)
if not signature:
return
soup = BeautifulSoup(signature, "html.parser")
html_signature = soup.find("div", {"class": "ql-editor read-mode"})
_signature = None
if html_signature:
_signature = html_signature.renderContents()
content = ""
if (cstr(_signature) or signature):
content = f'<br><p class="signature">{signature}</p>'
return content

View File

@ -479,22 +479,26 @@
</div>
<div class="flex gap-0.5">
<Tooltip :text="__('Reply')">
<Button
variant="ghost"
class="text-gray-700"
@click="reply(activity.data)"
>
<ReplyIcon class="h-4 w-4" />
</Button>
<div>
<Button
variant="ghost"
class="text-gray-700"
@click="reply(activity.data)"
>
<ReplyIcon class="h-4 w-4" />
</Button>
</div>
</Tooltip>
<Tooltip :text="__('Reply All')">
<Button
variant="ghost"
class="text-gray-700"
@click="reply(activity.data, true)"
>
<ReplyAllIcon class="h-4 w-4" />
</Button>
<div>
<Button
variant="ghost"
class="text-gray-700"
@click="reply(activity.data, true)"
>
<ReplyAllIcon class="h-4 w-4" />
</Button>
</div>
</Tooltip>
</div>
</div>

View File

@ -1,5 +1,5 @@
<template>
<div class="flex justify-between gap-3 border-t sm:px-10 px-4 py-2.5">
<div class="flex justify-between gap-3 border-t px-4 py-2.5 sm:px-10">
<div class="flex gap-1.5">
<Button
ref="sendEmailRef"
@ -102,7 +102,7 @@ import CommentIcon from '@/components/Icons/CommentIcon.vue'
import EmailIcon from '@/components/Icons/EmailIcon.vue'
import { usersStore } from '@/stores/users'
import { useStorage } from '@vueuse/core'
import { call } from 'frappe-ui'
import { call, createResource } from 'frappe-ui'
import { ref, watch, computed, nextTick } from 'vue'
const props = defineProps({
@ -138,11 +138,29 @@ const subject = computed(() => {
return `${prefix} (#${doc.value.data.name})`
})
const signature = createResource({
url: 'crm.api.get_user_signature',
cache: 'user-email-signature',
auto: true,
})
function setSignature(editor) {
signature.data = signature.data.replace(/\n/g, '<br>')
let emailContent = editor.getHTML()
emailContent = emailContent.startsWith('<p></p>')
? emailContent.slice(7)
: emailContent
editor.commands.setContent(signature.data + emailContent)
editor.commands.focus('start')
}
watch(
() => showEmailBox.value,
(value) => {
if (value) {
newEmailEditor.value.editor.commands.focus()
let editor = newEmailEditor.value.editor
editor.commands.focus()
setSignature(editor)
}
}
)
@ -248,5 +266,9 @@ function toggleCommentBox() {
showCommentBox.value = !showCommentBox.value
}
defineExpose({ show: showEmailBox, showComment: showCommentBox, editor: newEmailEditor })
defineExpose({
show: showEmailBox,
showComment: showCommentBox,
editor: newEmailEditor,
})
</script>