From 7c6bab88f48474ff213a035121b5b7844130cb2b Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Tue, 28 Jul 2020 20:22:10 +0200 Subject: [PATCH] Update permissions to see buses --- apps/permission/fixtures/initial.json | 4 ++-- apps/permission/models.py | 8 +++++++- apps/permission/test.py | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/apps/permission/fixtures/initial.json b/apps/permission/fixtures/initial.json index 79311eb9..1b740419 100644 --- a/apps/permission/fixtures/initial.json +++ b/apps/permission/fixtures/initial.json @@ -1743,7 +1743,7 @@ "wei", "bus" ], - "query": "[\"AND\", {\"wei\": [\"club\"]}, [\"OR\", [\"NOT\", [\"membership\", \"registration\", \"first_year\"]], {\"wei__date_end__lte\": [\"today\"]}]]", + "query": "[\"AND\", {\"wei\": [\"club\"]}, [\"OR\", [\"NOT\", [\"membership\", \"weimembership\", \"registration\", \"first_year\"]], {\"wei__date_end__lte\": [\"today\"]}]]", "type": "view", "mask": 1, "field": "", @@ -1759,7 +1759,7 @@ "wei", "busteam" ], - "query": "[\"AND\", {\"bus__wei\": [\"club\"]}, [\"OR\", [\"NOT\", [\"membership\", \"registration\", \"first_year\"]], {\"bus__wei__date_end__lte\": [\"today\"]}]]", + "query": "[\"AND\", {\"bus__wei\": [\"club\"]}, [\"OR\", [\"NOT\", [\"membership\", \"weimembership\", \"registration\", \"first_year\"]], {\"bus__wei__date_end__lte\": [\"today\"]}]]", "type": "view", "mask": 1, "field": "", diff --git a/apps/permission/models.py b/apps/permission/models.py index 56ca9685..12db9135 100644 --- a/apps/permission/models.py +++ b/apps/permission/models.py @@ -238,6 +238,9 @@ class Permission(models.Model): field = Permission.compute_param(value[i], **kwargs) continue + if not hasattr(field, value[i][0]): + return False + field = getattr(field, value[i][0]) params = [] call_kwargs = {} @@ -251,6 +254,9 @@ class Permission(models.Model): params.append(param) field = field(*params, **call_kwargs) else: + if not hasattr(field, value[i]): + return False + field = getattr(field, value[i]) return field @@ -275,7 +281,7 @@ class Permission(models.Model): elif query[0] == 'NOT': return ~Permission._about(query[1], **kwargs) else: - return Q(pk=F("pk")) + return Q(pk=F("pk")) if Permission.compute_param(query, **kwargs) else ~Q(pk=F("pk")) elif isinstance(query, dict): q_kwargs = {} for key in query: diff --git a/apps/permission/test.py b/apps/permission/test.py index de46d5aa..e728e9a6 100644 --- a/apps/permission/test.py +++ b/apps/permission/test.py @@ -76,7 +76,7 @@ class PermissionQueryTestCase(TestCase): model = perm.model.model_class() model.objects.filter(query).all() # print("Good query for permission", perm) - except (FieldError, AttributeError, ValueError): + except (FieldError, AttributeError, ValueError, TypeError): print("Query error for permission", perm) print("Query:", perm.query) if instanced.query: