diff --git a/mo/db.py b/mo/db.py index 3c795049a35e2cf28f32a0c145ef9e0be5c06a2d..ed2b0356f463975c7085aab801685917ade9ae9c 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 29553db03b62c9409ca58aeba7be6db0bc36d827..85531c939e79deca4fd56533ff7467a3a8c2790a 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]