From 3a745f96853d6f3fa2b090991687291cc176bedd Mon Sep 17 00:00:00 2001 From: Martin Mares <mj@ucw.cz> Date: Fri, 20 Aug 2021 00:57:38 +0200 Subject: [PATCH] =?UTF-8?q?Pr=C3=A1va:=20Vyhodnocov=C3=A1n=C3=AD=20rol?= =?UTF-8?q?=C3=AD=20p=C5=99esunuto=20do=20t=C5=99=C3=ADdy=20UserRole?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mo/db.py | 6 ++++++ mo/rights.py | 5 +---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/mo/db.py b/mo/db.py index 3c795049..ed2b0356 100644 --- a/mo/db.py +++ b/mo/db.py @@ -528,6 +528,12 @@ class UserRole(Base): return " ".join(parts) + def applies_to(self, at: Optional[Place] = None, year: Optional[int] = None, cat: Optional[str] = None, seq: Optional[int] = None) -> bool: + return ((at is None or self.place_id == at.place_id) + and (self.year is None or year is None or self.year == year) + and (self.category is None or cat is None or self.category == cat or (self.category == 'Z' and cat.startswith('Z'))) + and (self.seq is None or seq is None or self.seq == seq)) + class PaperType(MOEnum): solution = auto() diff --git a/mo/rights.py b/mo/rights.py index 29553db0..85531c93 100644 --- a/mo/rights.py +++ b/mo/rights.py @@ -325,10 +325,7 @@ class Gatekeeper: rights.rights = set() def try_role(role: db.UserRole, at: Optional[db.Place]): - if ((at is None or role.place_id == at.place_id) - and (role.year is None or year is None or role.year == year) - and (role.category is None or cat is None or role.category == cat or (role.category == 'Z' and cat.startswith('Z'))) - and (role.seq is None or seq is None or role.seq == seq) + if (role.applies_to(at=at, year=year, cat=cat, seq=seq) and (min_role is None or role_order_by_type[min_role] >= role_order_by_type[role.role])): rights.user_roles.append(role) r = roles_by_type[role.role] -- GitLab