fix(telephony): remove existing shares of voice call settings

(cherry picked from commit e3c06c65bc)
This commit is contained in:
Nabin Hait
2026-10-22 09:31:53 +00:00
committed by Mergify
parent b45caf3aeb
commit 55f0d9a9e3
2 changed files with 29 additions and 3 deletions
@@ -11,10 +11,18 @@ DESK_USER_PTYPES = ("read", "write", "create", "report", "export", "print", "ema
def execute():
"""Move customised sites from the `All` rule to the `Desk User` rule shipped in the DocType."""
if DOCTYPE not in get_doctypes_with_custom_docperms():
return
"""Keep each user's Voice Call Settings to that user and move customised sites to `Desk User`."""
remove_shares()
if DOCTYPE in get_doctypes_with_custom_docperms():
move_customised_rules()
def remove_shares():
# Shares grant access past the per-user permission hooks; the settings are personal.
frappe.db.delete("DocShare", {"share_doctype": DOCTYPE})
def move_customised_rules():
mirror_rules({DOCTYPE: {"Desk User": DESK_USER_PTYPES}})
removed = False
for rule in get_role_rules(DOCTYPE, "All"):
@@ -65,6 +65,24 @@ class TestVoiceCallSettings(ERPNextTestSuite):
)
self.assertTrue(frappe.db.exists("Voice Call Settings", settings.name))
def test_patch_removes_existing_shares(self):
from erpnext.patches.v16_0.scope_voice_call_settings_to_desk_users import execute
owner = make_user("voice-call-owner@example.com")
other_user = make_user("voice-call-other@example.com")
make_settings(owner)
frappe.share.add_docshare(
"Voice Call Settings", owner, other_user, write=1, flags={"ignore_share_permission": True}
)
with as_user(other_user):
self.assertIn(owner, frappe.get_list("Voice Call Settings", pluck="name"))
execute()
with as_user(other_user):
self.assertNotIn(owner, frappe.get_list("Voice Call Settings", pluck="name"))
self.assertRaises(frappe.PermissionError, frappe.client.get, "Voice Call Settings", owner)
def make_user(email: str) -> str:
return make_fenced_user(email, ["Sales User"])