From b15d5a1cc0139f8b810c279077d1d7551b8a589e Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Thu, 26 Sep 2024 19:06:50 +0200 Subject: [PATCH] fix(User): append base role before validation --- landa/hooks.py | 1 + landa/organization_management/user/user.py | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/landa/hooks.py b/landa/hooks.py index d258d7b2..794a608d 100644 --- a/landa/hooks.py +++ b/landa/hooks.py @@ -291,6 +291,7 @@ "on_trash": "landa.address_and_contact.on_trash", }, "User": { + "before_validate": "landa.organization_management.user.user.before_validate", "validate": "landa.organization_management.user.user.validate", "after_insert": "landa.organization_management.user.user.after_insert", "on_update": "landa.organization_management.user.user.on_update", diff --git a/landa/organization_management/user/user.py b/landa/organization_management/user/user.py index e497dcc3..dad70215 100644 --- a/landa/organization_management/user/user.py +++ b/landa/organization_management/user/user.py @@ -9,12 +9,15 @@ from landa.utils import delete_records_linked_to, get_default_company, remove_from_table +def before_validate(doc: User, event=None): + if doc.landa_member and doc.enabled and doc.name not in STANDARD_USERS: + doc.append_roles("LANDA Member") + + def validate(doc: User, event=None): if (not doc.enabled) or (doc.name in STANDARD_USERS): return - doc.append_roles("LANDA Member") - if doc.landa_member: existing_user = frappe.db.exists( "User",