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 15:48 +0000

1from fastapi import HTTPException, status 1a

2 

3from mealie.schema.user.user import PrivateUser 1a

4 

5 

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 """ 

11 

12 user: PrivateUser 1a

13 

14 ForbiddenException = HTTPException(status.HTTP_403_FORBIDDEN) 1a

15 UnauthorizedException = HTTPException(status.HTTP_401_UNAUTHORIZED) 1a

16 

17 def __init__(self, user: PrivateUser) -> None: 1a

18 self.user = user 1b

19 

20 # ========================================= 

21 # User Permission Checks 

22 

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 true1b

25 raise self.ForbiddenException 

26 return True 1b

27 

28 def can_manage(self) -> bool: 1a

29 if not self.user.can_manage: 

30 raise self.ForbiddenException 

31 return True 

32 

33 def can_invite(self) -> bool: 1a

34 if not self.user.can_invite: 

35 raise self.ForbiddenException 

36 return True 

37 

38 def can_organize(self) -> bool: 1a

39 if not self.user.can_organize: 

40 raise self.ForbiddenException 

41 return True