From b1ea6b1f66b87037a540f281bfa8e4c15c571bd1 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Wed, 27 Nov 2013 12:39:15 +0530 Subject: [PATCH] [permissions] Added Test Cases --- hr/doctype/employee/employee.py | 5 ++++- patches/1311/p06_update_user_properties.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/hr/doctype/employee/employee.py b/hr/doctype/employee/employee.py index a7deb0fcf4..46f46da80f 100644 --- a/hr/doctype/employee/employee.py +++ b/hr/doctype/employee/employee.py @@ -43,11 +43,14 @@ class DocType: self.update_profile() def update_user_default(self): + from webnotes.defaults import get_restrictions if not "HR User" in webnotes.local.user.get_roles(): - webnotes.conn.set_default("Employee", self.doc.name, self.doc.user_id, "Restriction") + if not self.doc.user_id in get_restrictions().get("Employee", []): + webnotes.conn.set_default("Employee", self.doc.name, self.doc.user_id, "Restriction") webnotes.conn.set_default("employee", self.doc.name, self.doc.user_id) webnotes.conn.set_default("employee_name", self.doc.employee_name, self.doc.user_id) + webnotes.conn.set_default("company", self.doc.company, self.doc.user_id) self.set_default_leave_approver() def set_default_leave_approver(self): diff --git a/patches/1311/p06_update_user_properties.py b/patches/1311/p06_update_user_properties.py index 5d5b508c4c..de19df2a9b 100644 --- a/patches/1311/p06_update_user_properties.py +++ b/patches/1311/p06_update_user_properties.py @@ -24,7 +24,7 @@ def update_user_properties(): parent not in ('__global', 'Control Panel')""", (df[0].options, d.defkey)) # remove duplicate restrictions (if they exist) - for d in webnotes.conn.sql("""select parent, defkey, substr(defvalue,0,10), + for d in webnotes.conn.sql("""select parent, defkey, defvalue, count(*) as cnt from tabDefaultValue where parent not in ('__global', 'Control Panel') group by parent, defkey, defvalue""", as_dict=1):