From 346efbbe785164a5ee5f0ea8c7b33dea00044482 Mon Sep 17 00:00:00 2001 From: Shariq Ansari Date: Sun, 19 Jan 2025 14:41:17 +0530 Subject: [PATCH] fix: allow agent to set default medium from settings --- crm/api/session.py | 34 +++++++++++-------- frontend/src/components/Settings/Settings.vue | 8 +++-- .../components/Settings/TelephonySettings.vue | 15 ++++++-- frontend/src/stores/users.js | 5 +++ 4 files changed, 42 insertions(+), 20 deletions(-) diff --git a/crm/api/session.py b/crm/api/session.py index 2e2b9375..746de854 100644 --- a/crm/api/session.py +++ b/crm/api/session.py @@ -5,7 +5,16 @@ import frappe def get_users(): users = frappe.qb.get_query( "User", - fields=["name", "email", "enabled", "user_image", "first_name", "last_name", "full_name", "user_type"], + fields=[ + "name", + "email", + "enabled", + "user_image", + "first_name", + "last_name", + "full_name", + "user_type", + ], order_by="full_name asc", distinct=True, ).run(as_dict=1) @@ -14,11 +23,13 @@ def get_users(): if frappe.session.user == user.name: user.session_user = True - user.is_manager = ( - "Sales Manager" in frappe.get_roles(user.name) or user.name == "Administrator" - ) + user.is_manager = "Sales Manager" in frappe.get_roles(user.name) or user.name == "Administrator" + + user.is_agent = frappe.db.exists("CRM Telephony Agent", {"user": user.name}) + return users + @frappe.whitelist() def get_contacts(): contacts = frappe.get_all( @@ -37,7 +48,7 @@ def get_contacts(): "mobile_no", "phone", "company_name", - "modified" + "modified", ], order_by="first_name asc", distinct=True, @@ -58,18 +69,12 @@ def get_contacts(): return contacts + @frappe.whitelist() def get_lead_contacts(): lead_contacts = frappe.get_all( "CRM Lead", - fields=[ - "name", - "lead_name", - "mobile_no", - "phone", - "image", - "modified" - ], + fields=["name", "lead_name", "mobile_no", "phone", "image", "modified"], filters={"converted": 0}, order_by="lead_name asc", distinct=True, @@ -77,11 +82,12 @@ def get_lead_contacts(): return lead_contacts + @frappe.whitelist() def get_organizations(): organizations = frappe.qb.get_query( "CRM Organization", - fields=['*'], + fields=["*"], order_by="name asc", distinct=True, ).run(as_dict=1) diff --git a/frontend/src/components/Settings/Settings.vue b/frontend/src/components/Settings/Settings.vue index 2f1c981d..fde93938 100644 --- a/frontend/src/components/Settings/Settings.vue +++ b/frontend/src/components/Settings/Settings.vue @@ -67,7 +67,7 @@ import { import { Dialog, Button, Avatar } from 'frappe-ui' import { ref, markRaw, computed, watch, h } from 'vue' -const { isManager, getUser } = usersStore() +const { isManager, isAgent, getUser } = usersStore() const user = computed(() => getUser() || {}) @@ -108,20 +108,22 @@ const tabs = computed(() => { label: __('Telephony'), icon: PhoneIcon, component: markRaw(TelephonySettings), + condition: () => isManager() || isAgent(), }, { label: __('WhatsApp'), icon: WhatsAppIcon, component: markRaw(WhatsAppSettings), - condition: () => isWhatsappInstalled.value, + condition: () => isWhatsappInstalled.value && isManager(), }, { label: __('ERPNext'), icon: ERPNextIcon, component: markRaw(ERPNextSettings), + condition: () => isManager(), }, ], - condition: () => isManager(), + condition: () => isManager() || isAgent(), }, ] diff --git a/frontend/src/components/Settings/TelephonySettings.vue b/frontend/src/components/Settings/TelephonySettings.vue index 8134df82..a4fb0555 100644 --- a/frontend/src/components/Settings/TelephonySettings.vue +++ b/frontend/src/components/Settings/TelephonySettings.vue @@ -19,17 +19,18 @@ -
+
{{ __('Twilio') }} @@ -42,7 +43,7 @@
-
+
{{ __('Exotel') }} @@ -85,9 +86,12 @@ import { call, } from 'frappe-ui' import { defaultCallingMedium } from '@/composables/settings' +import { usersStore } from '@/stores/users' import { createToast, getRandom } from '@/utils' import { ref, computed, watch } from 'vue' +const { isManager, isAgent } = usersStore() + const twilioFields = createResource({ url: 'crm.api.doc.get_fields', cache: ['fields', 'Twilio Settings'], @@ -273,6 +277,9 @@ function update() { if (mediumChanged.value) { updateMedium() } + + if (!isManager()) return + if (twilio.isDirty) { twilio.save.submit() } @@ -298,6 +305,8 @@ async function updateMedium() { const error = ref('') function validateIfDefaultMediumIsEnabled() { + if (isAgent() && !isManager()) return true + if (defaultCallingMedium.value === 'Twilio' && !twilio.doc.enabled) { error.value = __('Twilio is not enabled') return false diff --git a/frontend/src/stores/users.js b/frontend/src/stores/users.js index bee56d56..5965c537 100644 --- a/frontend/src/stores/users.js +++ b/frontend/src/stores/users.js @@ -53,9 +53,14 @@ export const usersStore = defineStore('crm-users', () => { return getUser(email).is_manager } + function isAgent(email) { + return getUser(email).is_agent + } + return { users, getUser, isManager, + isAgent, } })