fix: append user email signature if content is empty
This commit is contained in:
parent
c049a57c74
commit
b634063f56
@ -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
|
||||
@ -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,22 @@ const subject = computed(() => {
|
||||
return `${prefix} (#${doc.value.data.name})`
|
||||
})
|
||||
|
||||
const signature = createResource({
|
||||
url: 'crm.api.get_user_signature',
|
||||
cache: 'user-email-signature',
|
||||
auto: true,
|
||||
})
|
||||
|
||||
watch(
|
||||
() => showEmailBox.value,
|
||||
(value) => {
|
||||
if (value) {
|
||||
newEmailEditor.value.editor.commands.focus()
|
||||
|
||||
if (!newEmail.value && signature.data) {
|
||||
signature.data = signature.data.replace(/\n/g, '<br>')
|
||||
newEmail.value = signature.data
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
@ -248,5 +259,9 @@ function toggleCommentBox() {
|
||||
showCommentBox.value = !showCommentBox.value
|
||||
}
|
||||
|
||||
defineExpose({ show: showEmailBox, showComment: showCommentBox, editor: newEmailEditor })
|
||||
defineExpose({
|
||||
show: showEmailBox,
|
||||
showComment: showCommentBox,
|
||||
editor: newEmailEditor,
|
||||
})
|
||||
</script>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user