Coverage for opt/mealie/lib/python3.12/site-packages/mealie/routes/_base/checks.py: 56%

24 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-10-07 03:04 +0000

1from fastapi import HTTPException, status 

2 

3from mealie.schema.user.user import PrivateUser 

4 

5 

6class OperationChecks: 

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 

13 

14 ForbiddenException = HTTPException(status.HTTP_403_FORBIDDEN) 

15 UnauthorizedException = HTTPException(status.HTTP_401_UNAUTHORIZED) 

16 

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

18 self.user = user 

19 

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

21 # User Permission Checks 

22 

23 def can_manage_household(self) -> bool: 

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 true

25 raise self.ForbiddenException 

26 return True 

27 

28 def can_manage(self) -> bool: 

29 if not self.user.can_manage: 29 ↛ 30line 29 didn't jump to line 30 because the condition on line 29 was never true

30 raise self.ForbiddenException 

31 return True 

32 

33 def can_invite(self) -> bool: 

34 if not self.user.can_invite: 

35 raise self.ForbiddenException 

36 return True 

37 

38 def can_organize(self) -> bool: 

39 if not self.user.can_organize: 

40 raise self.ForbiddenException 

41 return True