From c4ef07662de074b99fe07bf708e0bfa1e1e0fc91 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 23 Jan 2014 16:39:11 +0530 Subject: [PATCH] added conditions in todo --- webnotes/core/doctype/todo/todo.py | 17 ++++++++++++++++- webnotes/model/controller.py | 24 ++++++++++++------------ webnotes/widgets/reportview.py | 6 ++++-- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/webnotes/core/doctype/todo/todo.py b/webnotes/core/doctype/todo/todo.py index ed9c607987..6095e3c39a 100644 --- a/webnotes/core/doctype/todo/todo.py +++ b/webnotes/core/doctype/todo/todo.py @@ -6,4 +6,19 @@ import webnotes class DocType: def __init__(self, d, dl): - self.doc, self.doclist = d, dl \ No newline at end of file + self.doc, self.doclist = d, dl + +# todo is viewable if either user or assigned_to or System Manager in roles + +def get_permission_query_conditions(): + if "System Manager" in webnotes.get_roles(): + return None + else: + return """(tabToDo.owner = '{user}' or tabToDo.assigned_to = '{user}' or )""".format(user=webnotes.session.user) + +def has_permission(doc): + if "System Manager" in webnotes.get_roles(): + return True + else: + return doc.owner==webnotes.session.user or doc.assigned_to==webnotes.session.user + \ No newline at end of file diff --git a/webnotes/model/controller.py b/webnotes/model/controller.py index a64485808d..4f3310184e 100644 --- a/webnotes/model/controller.py +++ b/webnotes/model/controller.py @@ -7,18 +7,6 @@ from webnotes import msgprint, _ from webnotes.utils import flt, cint, cstr from webnotes.model.meta import get_field_precision -error_condition_map = { - "=": "!=", - "!=": "=", - "<": ">=", - ">": "<=", - ">=": "<", - "<=": ">", - "in": _("not in"), - "not in": _("in"), - "^": _("cannot start with"), -} - class EmptyTableError(webnotes.ValidationError): pass class DocListController(object): @@ -37,6 +25,18 @@ class DocListController(object): def validate_value(self, fieldname, condition, val2, doc=None, raise_exception=None): """check that value of fieldname should be 'condition' val2 else throw exception""" + error_condition_map = { + "=": "!=", + "!=": "=", + "<": ">=", + ">": "<=", + ">=": "<", + "<=": ">", + "in": _("not in"), + "not in": _("in"), + "^": _("cannot start with"), + } + if not doc: doc = self.doc diff --git a/webnotes/widgets/reportview.py b/webnotes/widgets/reportview.py index 622dd84349..608038b878 100644 --- a/webnotes/widgets/reportview.py +++ b/webnotes/widgets/reportview.py @@ -265,9 +265,11 @@ def get_permission_query_conditions(doctype): if condition_methods: conditions = [] for method in condition_methods: - conditions.append(webnotes.get_attr(method)()) + c = webnotes.get_attr(method)() + if c: + conditions.append(c) - return " and ".join(conditions) + return " and ".join(conditions) if conditions else None def get_tables(doctype, fields): """extract tables from fields"""