Coverage for apps/users/permissions.py: 79%

14 statements  

« prev     ^ index     » next       coverage.py v6.4.4, created at 2023-10-12 15:59 -0600

1from rest_framework.permissions import SAFE_METHODS, BasePermission 

2 

3from .models import Employee 

4 

5 

6class IsEmployee(BasePermission): 

7 """ 

8 Allows access only to authenticated users that are employees. 

9 """ 

10 

11 def has_permission(self, request, view): 

12 return bool(request.user and request.user.is_authenticated) and hasattr(request.user, "employee") 

13 

14 

15class AdminPanel(BasePermission): 

16 """ 

17 Allows access only to authenticated users that are employees. 

18 """ 

19 

20 def has_permission(self, request, view): 

21 if bool(request.user and request.user.is_authenticated) and hasattr(request.user, "employee"): 21 ↛ 29line 21 didn't jump to line 29, because the condition on line 21 was never false

22 if request.method in SAFE_METHODS: 

23 return True 

24 else: 

25 if request.user.employee.permissions == Employee.Permissions.WRITE: 25 ↛ 27line 25 didn't jump to line 27, because the condition on line 25 was never false

26 return True 

27 return False 

28 else: 

29 return False