Coverage for opt/mealie/lib/python3.12/site-packages/mealie/routes/_base/checks.py: 47%
24 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-11-25 17:29 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-11-25 17:29 +0000
1from fastapi import HTTPException, status 1a
3from mealie.schema.user.user import PrivateUser 1a
6class OperationChecks: 1a
7 """
8 OperationChecks class is a mixin class that can be used on routers to provide common permission
9 checks and raise the appropriate http error as necessary
10 """
12 user: PrivateUser 1a
14 ForbiddenException = HTTPException(status.HTTP_403_FORBIDDEN) 1a
15 UnauthorizedException = HTTPException(status.HTTP_401_UNAUTHORIZED) 1a
17 def __init__(self, user: PrivateUser) -> None: 1a
18 self.user = user 1bc
20 # =========================================
21 # User Permission Checks
23 def can_manage_household(self) -> bool: 1a
24 if not self.user.can_manage_household: 24 ↛ 25line 24 didn't jump to line 25 because the condition on line 24 was never true1bc
25 raise self.ForbiddenException
26 return True 1bc
28 def can_manage(self) -> bool: 1a
29 if not self.user.can_manage:
30 raise self.ForbiddenException
31 return True
33 def can_invite(self) -> bool: 1a
34 if not self.user.can_invite:
35 raise self.ForbiddenException
36 return True
38 def can_organize(self) -> bool: 1a
39 if not self.user.can_organize:
40 raise self.ForbiddenException
41 return True