From f7abf3b1cff7affc429355c277417037daea0a57 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Mon, 12 Jun 2023 21:37:31 +0530 Subject: [PATCH 1/7] fix: handle fixture syncing for missing doctypes --- frappe/utils/fixtures.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/frappe/utils/fixtures.py b/frappe/utils/fixtures.py index 821b1a1187..81e0edbca5 100644 --- a/frappe/utils/fixtures.py +++ b/frappe/utils/fixtures.py @@ -17,15 +17,31 @@ def sync_fixtures(app=None): frappe.flags.in_fixtures = True for app in apps: - fixtures_path = frappe.get_app_path(app, "fixtures") - if os.path.exists(fixtures_path): - import_doc(fixtures_path) - + import_fixtures(app) import_custom_scripts(app) frappe.flags.in_fixtures = False +def import_fixtures(app): + fixtures_path = frappe.get_app_path(app, "fixtures") + if not os.path.exists(fixtures_path): + return + + fixture_files = os.listdir(fixtures_path) + + for fname in fixture_files: + if not fname.endswith(".json"): + continue + + file_path = frappe.get_app_path(app, "fixtures", fname) + try: + import_doc(file_path) + except (ImportError, frappe.DoesNotExistError) as e: + # fixture syncing for missing doctypes + print(f"Skipping fixture syncing from the file {fname}. Reason: {e}") + + def import_custom_scripts(app): """Import custom scripts from `[app]/fixtures/custom_scripts`""" if os.path.exists(frappe.get_app_path(app, "fixtures", "custom_scripts")): From 1bab900e6f2f0757a2870e13a967fc800bff74c3 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Mon, 12 Jun 2023 22:09:08 +0530 Subject: [PATCH 2/7] fix: skip custom script syncing for missing doctypes --- frappe/utils/fixtures.py | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/frappe/utils/fixtures.py b/frappe/utils/fixtures.py index 81e0edbca5..241f17e62b 100644 --- a/frappe/utils/fixtures.py +++ b/frappe/utils/fixtures.py @@ -44,18 +44,34 @@ def import_fixtures(app): def import_custom_scripts(app): """Import custom scripts from `[app]/fixtures/custom_scripts`""" - if os.path.exists(frappe.get_app_path(app, "fixtures", "custom_scripts")): - for fname in os.listdir(frappe.get_app_path(app, "fixtures", "custom_scripts")): - if fname.endswith(".js"): - with open(frappe.get_app_path(app, "fixtures", "custom_scripts") + os.path.sep + fname) as f: - doctype = fname.rsplit(".", 1)[0] - script = f.read() - if frappe.db.exists("Client Script", {"dt": doctype}): - custom_script = frappe.get_doc("Client Script", {"dt": doctype}) - custom_script.script = script - custom_script.save() - else: - frappe.get_doc({"doctype": "Client Script", "dt": doctype, "script": script}).insert() + scripts_folder = frappe.get_app_path(app, "fixtures", "custom_scripts") + if not os.path.exists(scripts_folder): + return + + for fname in os.listdir(scripts_folder): + if not fname.endswith(".js"): + continue + + doctype = fname.rsplit(".", 1)[0] + if not frappe.db.exists("DocType", doctype): + print( + f"Skipping custom script fixture syncing for the missing doctype {doctype} from the file {fname}" + ) + continue + + # not using get_app_path here as it scrubs the fname (will not work for dt name with > 1 word) + file_path = scripts_folder + os.path.sep + fname + + with open(file_path) as f: + script = f.read() + if frappe.db.exists("Client Script", {"dt": doctype}): + client_script = frappe.get_doc("Client Script", {"dt": doctype}) + client_script.script = script + client_script.save() + else: + client_script = frappe.new_doc("Client Script") + client_script.update({"__newname": doctype, "dt": doctype, "script": script}) + client_script.insert() def export_fixtures(app=None): From fb438f342d59e40a9cc4b6240df2d4e4d4729210 Mon Sep 17 00:00:00 2001 From: Sagar Vora Date: Tue, 13 Jun 2023 10:42:57 +0530 Subject: [PATCH 3/7] fix: clean `insert_after` setters when resetting layout (#21346) --- .../custom/doctype/customize_form/customize_form.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/frappe/custom/doctype/customize_form/customize_form.py b/frappe/custom/doctype/customize_form/customize_form.py index 8930833760..868a913ce3 100644 --- a/frappe/custom/doctype/customize_form/customize_form.py +++ b/frappe/custom/doctype/customize_form/customize_form.py @@ -573,18 +573,17 @@ class CustomizeForm(Document): if not self.doc_type: return - property_setter = frappe.db.get_value( + property_setters = frappe.get_all( "Property Setter", - filters={ - "doc_type": self.doc_type, - "property": "field_order", - }, + filters={"doc_type": self.doc_type, "property": ("in", ("field_order", "insert_after"))}, + pluck="name", ) - if not property_setter: + if not property_setters: return - frappe.delete_doc("Property Setter", property_setter) + frappe.db.delete("Property Setter", {"name": ("in", property_setters)}) + frappe.clear_cache(doctype=self.doc_type) self.fetch_to_customize() @classmethod From 9d20509492198a62099d15d082e7699ba76cfa15 Mon Sep 17 00:00:00 2001 From: Vishal Kumar Date: Tue, 13 Jun 2023 11:10:47 +0530 Subject: [PATCH 4/7] fix: no role assigned message when role profile is passed (#21342) * Fix: no role assigned message when role profile is passed * refactor: rename misleading method --------- Co-authored-by: Ankush Menat --- frappe/core/doctype/user/user.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/frappe/core/doctype/user/user.py b/frappe/core/doctype/user/user.py index 4c5cea3130..9bcc9ebd3d 100644 --- a/frappe/core/doctype/user/user.py +++ b/frappe/core/doctype/user/user.py @@ -28,6 +28,7 @@ from frappe.utils import ( now_datetime, today, ) +from frappe.utils.deprecations import deprecated from frappe.utils.password import check_password, get_password_reset_limit from frappe.utils.password import update_password as _update_password from frappe.utils.user import get_system_managers @@ -75,6 +76,7 @@ class User(Document): self.validate_email_type(self.email) self.validate_email_type(self.name) self.add_system_manager_role() + self.populate_role_profile_roles() self.check_roles_added() self.set_system_user() self.set_full_name() @@ -85,7 +87,6 @@ class User(Document): self.remove_disabled_roles() self.validate_user_email_inbox() ask_pass_update() - self.validate_roles() self.validate_allowed_modules() self.validate_user_image() self.set_time_zone() @@ -98,12 +99,16 @@ class User(Document): ): self.set_social_login_userid("frappe", frappe.generate_hash(length=39)) - def validate_roles(self): + def populate_role_profile_roles(self): if self.role_profile_name: role_profile = frappe.get_doc("Role Profile", self.role_profile_name) self.set("roles", []) self.append_roles(*[role.role for role in role_profile.roles]) + @deprecated + def validate_roles(self): + self.populate_role_profile_roles() + def validate_allowed_modules(self): if self.module_profile: module_profile = frappe.get_doc("Module Profile", self.module_profile) From 22149b5bffa7fa23c79126f666ade0b8f50a05b2 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Tue, 13 Jun 2023 12:12:21 +0530 Subject: [PATCH 5/7] chore: increase communication limit This needs better fix, added temporarily --- frappe/desk/form/load.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/desk/form/load.py b/frappe/desk/form/load.py index 9e7e818cf0..55d57a0a82 100644 --- a/frappe/desk/form/load.py +++ b/frappe/desk/form/load.py @@ -253,7 +253,7 @@ def get_point_logs(doctype, docname): ) -def _get_communications(doctype, name, start=0, limit=20): +def _get_communications(doctype, name, start=0, limit=100): communications = get_communication_data(doctype, name, start, limit) for c in communications: if c.communication_type == "Communication": From 74cbdbf07fe86e8cf96a445b6dc44f98867c29c4 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Tue, 13 Jun 2023 12:31:14 +0530 Subject: [PATCH 6/7] refactor: Deprecate importing of fixturs/custom_scripts --- frappe/utils/fixtures.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/frappe/utils/fixtures.py b/frappe/utils/fixtures.py index 241f17e62b..67035f9fac 100644 --- a/frappe/utils/fixtures.py +++ b/frappe/utils/fixtures.py @@ -5,6 +5,7 @@ import os import frappe from frappe.core.doctype.data_import.data_import import export_json, import_doc +from frappe.utils.deprecations import deprecation_warning def sync_fixtures(app=None): @@ -61,6 +62,9 @@ def import_custom_scripts(app): # not using get_app_path here as it scrubs the fname (will not work for dt name with > 1 word) file_path = scripts_folder + os.path.sep + fname + deprecation_warning( + f"Importing client script {fname} from {scripts_folder} is deprecated and will be removed in version-15. Use client scripts as fixtures directly." + ) with open(file_path) as f: script = f.read() From cfdbad6653920d0108fc201cb8f84859b23d3f9d Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Tue, 13 Jun 2023 12:34:53 +0530 Subject: [PATCH 7/7] refactor!: Remove custom script import --- frappe/utils/fixtures.py | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/frappe/utils/fixtures.py b/frappe/utils/fixtures.py index 67035f9fac..ddd8650451 100644 --- a/frappe/utils/fixtures.py +++ b/frappe/utils/fixtures.py @@ -3,9 +3,10 @@ import os +import click + import frappe from frappe.core.doctype.data_import.data_import import export_json, import_doc -from frappe.utils.deprecations import deprecation_warning def sync_fixtures(app=None): @@ -53,30 +54,11 @@ def import_custom_scripts(app): if not fname.endswith(".js"): continue - doctype = fname.rsplit(".", 1)[0] - if not frappe.db.exists("DocType", doctype): - print( - f"Skipping custom script fixture syncing for the missing doctype {doctype} from the file {fname}" - ) - continue - - # not using get_app_path here as it scrubs the fname (will not work for dt name with > 1 word) - file_path = scripts_folder + os.path.sep + fname - deprecation_warning( - f"Importing client script {fname} from {scripts_folder} is deprecated and will be removed in version-15. Use client scripts as fixtures directly." + click.secho( + f"Importing Client Script `{fname}` from `{scripts_folder}` is not supported. Convert the client script to fixture.", + fg="red", ) - with open(file_path) as f: - script = f.read() - if frappe.db.exists("Client Script", {"dt": doctype}): - client_script = frappe.get_doc("Client Script", {"dt": doctype}) - client_script.script = script - client_script.save() - else: - client_script = frappe.new_doc("Client Script") - client_script.update({"__newname": doctype, "dt": doctype, "script": script}) - client_script.insert() - def export_fixtures(app=None): """Export fixtures as JSON to `[app]/fixtures`"""