diff --git a/frappe/core/doctype/docshare/test_docshare.py b/frappe/core/doctype/docshare/test_docshare.py index 5a2a8da936..e080b0d4ff 100644 --- a/frappe/core/doctype/docshare/test_docshare.py +++ b/frappe/core/doctype/docshare/test_docshare.py @@ -187,18 +187,13 @@ class TestDocShare(FrappeTestCase): Assigning a document to a user without access must not share the document, if sharing disabled. """ - from frappe.desk.form.assign_to import add, get + from frappe.desk.form.assign_to import add frappe.share.add("Event", self.event.name, self.user, share=1) frappe.set_user(self.user) - # Assign to 'test1@example.com' - add({"doctype": "Event", "name": self.event.name, "assign_to": ["test1@example.com"]}) - - # Check if assigned to 'test1@example.com' - assignments = get(dict(doctype="Event", name=self.event.name)) - self.assertEqual(len(assignments), 1) - - # Check if not shared with 'test1@example.com' - shared_users = [x.user for x in frappe.share.get_users("Event", self.event.name)] - self.assertNotIn("test1@example.com", shared_users) + self.assertRaises( + frappe.ValidationError, + add, + {"doctype": "Event", "name": self.event.name, "assign_to": ["test1@example.com"]}, + ) diff --git a/frappe/model/rename_doc.py b/frappe/model/rename_doc.py index 420cbee091..3908365291 100644 --- a/frappe/model/rename_doc.py +++ b/frappe/model/rename_doc.py @@ -488,6 +488,9 @@ def update_options_for_fieldtype(fieldtype: str, old: str, new: str) -> None: if frappe.conf.developer_mode: for name in frappe.get_all("DocField", filters={"options": old}, pluck="parent"): + if name in (old, new): + continue + doctype = frappe.get_doc("DocType", name) save = False for f in doctype.fields: @@ -496,11 +499,11 @@ def update_options_for_fieldtype(fieldtype: str, old: str, new: str) -> None: save = True if save: doctype.save() - else: - DocField = frappe.qb.DocType("DocField") - frappe.qb.update(DocField).set(DocField.options, new).where( - (DocField.fieldtype == fieldtype) & (DocField.options == old) - ).run() + + DocField = frappe.qb.DocType("DocField") + frappe.qb.update(DocField).set(DocField.options, new).where( + (DocField.fieldtype == fieldtype) & (DocField.options == old) + ).run() frappe.qb.update(CustomField).set(CustomField.options, new).where( (CustomField.fieldtype == fieldtype) & (CustomField.options == old) diff --git a/frappe/public/js/frappe/form/templates/contact_list.html b/frappe/public/js/frappe/form/templates/contact_list.html index e5fdc3f88e..c4cc08a549 100644 --- a/frappe/public/js/frappe/form/templates/contact_list.html +++ b/frappe/public/js/frappe/form/templates/contact_list.html @@ -1,49 +1,51 @@
-{% for(var i=0, l=contact_list.length; i- {%= contact_list[i].first_name %} {%= contact_list[i].last_name %} - {% if(contact_list[i].is_primary_contact) { %} + {%= contact.first_name %} {%= contact.last_name %} + {% if(contact.is_primary_contact) { %} ({%= __("Primary") %}) {% } %} - {% if(contact_list[i].designation){ %} - – {%= contact_list[i].designation %} + {% if(contact.designation){ %} + – {%= contact.designation %} {% } %} - {%= __("Edit") %}
- {% if (contact_list[i].phones || contact_list[i].email_ids) { %} + {% if (contact.phone || contact.mobile_no || contact.phone_nos.length > 0) { %}
- {% if(contact_list[i].phone) { %}
- {%= __("Phone") %}: {%= contact_list[i].phone %} ({%= __("Primary") %})
+ {% if(contact.phone) { %}
+ {%= frappe.utils.escape_html(contact.phone) %} · {%= __("Primary Phone") %}
{% endif %}
- {% if(contact_list[i].mobile_no) { %}
- {%= __("Mobile No") %}: {%= contact_list[i].mobile_no %} ({%= __("Primary") %})
+ {% if(contact.mobile_no) { %}
+ {%= frappe.utils.escape_html(contact.mobile_no) %} · {%= __("Primary Mobile") %}
{% endif %}
- {% if(contact_list[i].phone_nos) { %}
- {% for(var j=0, k=contact_list[i].phone_nos.length; j
- {% if(contact_list[i].email_id) { %}
- {%= __("Email") %}: {%= contact_list[i].email_id %} ({%= __("Primary") %})
- {% endif %}
- {% if(contact_list[i].email_ids) { %}
- {% for(var j=0, k=contact_list[i].email_ids.length; j
{% } %}
{% endif %}
- {% if (contact_list[i].address) { %}
- {%= __("Address") %}: {%= contact_list[i].address %}
- {% endif %}
+ {% if(contact.email_id) { %}
+ {%= frappe.utils.escape_html(contact.email_id) %} · {%= __("Primary Email") %}
+ {% endif %}
+ {% if(contact.email_ids) { %}
+ {% for(const email_id of contact.email_ids) { %}
+ {%= frappe.utils.escape_html(email_id.email_id) %}
+ {% } %}
+ {% endif %}
+ {%= contact.address %} +
+ {% endif %} {% } %} {% if(!contact_list.length) { %} @@ -51,4 +53,4 @@ {% } %}-
\ No newline at end of file + diff --git a/frappe/tests/test_nestedset.py b/frappe/tests/test_nestedset.py index 182831b680..ef63fb66c2 100644 --- a/frappe/tests/test_nestedset.py +++ b/frappe/tests/test_nestedset.py @@ -8,6 +8,7 @@ from frappe.core.doctype.doctype.test_doctype import new_doctype from frappe.query_builder import Field from frappe.query_builder.functions import Max from frappe.tests.utils import FrappeTestCase +from frappe.utils import random_string from frappe.utils.nestedset import ( NestedSetChildExistsError, NestedSetInvalidMergeError, @@ -213,6 +214,12 @@ class TestNestedSet(FrappeTestCase): remove_subtree("Test Tree DocType", "Parent 2") self.test_basic_tree() + def test_rename_nestedset(self): + doctype = new_doctype(is_tree=True).insert() + + # Rename doctype + frappe.rename_doc("DocType", doctype.name, "Test " + random_string(10), force=True) + def test_merge_groups(self): global records el = {"some_fieldname": "Parent 2", "parent_test_tree_doctype": "Root Node", "is_group": 1} diff --git a/frappe/tests/test_rename_doc.py b/frappe/tests/test_rename_doc.py index e48f908147..3f67bc4a1f 100644 --- a/frappe/tests/test_rename_doc.py +++ b/frappe/tests/test_rename_doc.py @@ -9,14 +9,9 @@ from unittest.mock import patch import frappe from frappe.core.doctype.doctype.test_doctype import new_doctype -from frappe.exceptions import DoesNotExistError, ValidationError +from frappe.exceptions import DoesNotExistError from frappe.model.base_document import get_controller -from frappe.model.rename_doc import ( - bulk_rename, - get_fetch_fields, - update_document_title, - update_linked_doctypes, -) +from frappe.model.rename_doc import bulk_rename, update_document_title from frappe.modules.utils import get_doc_path from frappe.tests.utils import FrappeTestCase from frappe.utils import add_to_date, now @@ -255,14 +250,16 @@ class TestRenameDoc(FrappeTestCase): ) def test_deprecated_utils(self): + from frappe.model.rename_doc import get_fetch_fields, update_linked_doctypes + stdout = StringIO() with redirect_stdout(stdout), patch_db(["set_value"]): get_fetch_fields("User", "ToDo", ["Activity Log"]) - self.assertTrue("Function frappe.model.rename_doc.get_fetch_fields" in stdout.getvalue()) + self.assertIn("Function frappe.model.rename_doc.get_fetch_fields", stdout.getvalue()) update_linked_doctypes("User", "ToDo", "str", "str") - self.assertTrue("Function frappe.model.rename_doc.update_linked_doctypes" in stdout.getvalue()) + self.assertIn("Function frappe.model.rename_doc.update_linked_doctypes", stdout.getvalue()) def test_doc_rename_method(self): name = choice(self.available_documents) diff --git a/frappe/tests/utils.py b/frappe/tests/utils.py index fe95960518..2cdcfb5643 100644 --- a/frappe/tests/utils.py +++ b/frappe/tests/utils.py @@ -143,7 +143,7 @@ def change_settings(doctype, settings_dict): # change setting for key, value in settings_dict.items(): setattr(settings, key, value) - settings.save() + settings.save(ignore_permissions=True) # singles are cached by default, clear to avoid flake frappe.db.value_cache[settings] = {} yield # yield control to calling function @@ -153,7 +153,7 @@ def change_settings(doctype, settings_dict): settings = frappe.get_doc(doctype) for key, value in previous_settings.items(): setattr(settings, key, value) - settings.save() + settings.save(ignore_permissions=True) def timeout(seconds=30, error_message="Test timed out."):