Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: auto populate email signatures (agent only) #1603

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions desk/src/pages/ticket/TicketAgent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ import { Icon } from "@iconify/vue";
import { emitter } from "@/emitter";
import { socket } from "@/socket";
import { useAgentStore } from "@/stores/agent";
import { useAuthStore } from "@/stores/auth";
import { useError } from "@/composables/error";
import TicketAgentActions from "./TicketAgentActions.vue";
import TicketAgentSidebar from "./TicketAgentSidebar.vue";
Expand All @@ -210,6 +211,7 @@ enum Mode {

const props = defineProps<P>();
const agentStore = useAgentStore();
const authStore = useAuthStore();
const ticket = createResource({
url: "helpdesk.helpdesk.doctype.hd_ticket.api.get_one",
cache: ["Ticket", props.ticketId],
Expand Down Expand Up @@ -265,17 +267,21 @@ const comment = createResource({
const response = createResource({
url: "run_doc_method",
debounce: 300,
makeParams: () => ({
dt: "HD Ticket",
dn: props.ticketId,
method: "reply_via_agent",
args: {
attachments: attachments.value.map((x) => x.name),
cc: cc.value,
bcc: bcc.value,
message: content.value,
},
}),
makeParams: () => {
editor.value.editor.commands.insertContent("<br /><br />---<br />");
editor.value.editor.commands.insertContent(authStore.emailSignature);
return {
dt: "HD Ticket",
dn: props.ticketId,
method: "reply_via_agent",
args: {
attachments: attachments.value.map((x) => x.name),
cc: cc.value,
bcc: bcc.value,
message: content.value,
},
};
},
onSuccess: () => {
clear();
emitter.emit("update:ticket");
Expand Down
8 changes: 6 additions & 2 deletions desk/src/stores/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ export const useAuthStore = defineStore("auth", () => {
});

const user__ = computed(() => userInfo.data || {});
const hasDeskAccess: ComputedRef<boolean> = computed(
() => user__.value.has_desk_access
const emailSignature: ComputedRef<string> = computed(
() => user__.value.email_signature
);
const isAdmin: ComputedRef<boolean> = computed(() => user__.value.is_admin);
const isAgent: ComputedRef<boolean> = computed(() => user__.value.is_agent);
const hasDeskAccess: ComputedRef<boolean> = computed(
() => isAdmin.value || isAgent.value
);
const isLoggedIn: ComputedRef<boolean> = computed(
() => !isEmpty(user__.value)
);
Expand Down Expand Up @@ -84,6 +87,7 @@ export const useAuthStore = defineStore("auth", () => {
}

return {
emailSignature,
hasDeskAccess,
init,
isAdmin,
Expand Down
28 changes: 10 additions & 18 deletions helpdesk/api/auth.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import frappe

from helpdesk.utils import is_agent as _is_agent
from helpdesk.utils import is_admin, is_agent


@frappe.whitelist()
def get_user():
current_user = frappe.session.user
filters = {"name": current_user}
fields = [
"email_signature",
"first_name",
"full_name",
"name",
Expand All @@ -21,24 +22,15 @@ def get_user():
as_dict=True,
)

is_agent = _is_agent()
is_admin = user.username == "administrator"
has_desk_access = is_agent or is_admin
user_image = user.user_image
user_first_name = user.first_name
user_name = user.full_name
user_id = user.name
username = user.username

return {
"has_desk_access": has_desk_access,
"is_admin": is_admin,
"is_agent": is_agent,
"user_id": user_id,
"user_image": user_image,
"user_first_name": user_first_name,
"user_name": user_name,
"username": username,
"email_signature": user.email_signature,
"is_admin": is_admin(),
"is_agent": is_agent(),
"user_first_name": user.first_name,
"user_id": user.name,
"user_image": user.user_image,
"user_name": user.full_name,
"username": user.username,
}


Expand Down
Loading