Coverage for users/permissions.py: 91%

13 statements  

« prev     ^ index     » next       coverage.py v6.4.4, created at 2023-05-04 17:09 -0600

1from rest_framework.permissions import BasePermission, SAFE_METHODS 

2 

3 

4class AdminPanel(BasePermission): 

5 """ 

6 Allows access only to authenticated users that are employees. 

7 """ 

8 

9 def has_permission(self, request, view): 

10 if bool(request.user and request.user.is_authenticated) and hasattr(request.user, "employee"): 

11 if request.method in SAFE_METHODS: 

12 return True 

13 else: 

14 if request.user.employee.permissions: 14 ↛ 16line 14 didn't jump to line 16, because the condition on line 14 was never false

15 return True 

16 return False 

17 else: 

18 return False 

19 

20 

21class MemberPanel(BasePermission): 

22 """ 

23 Allows access only to authenticated users that are members. 

24 """ 

25 

26 def has_permission(self, request, view): 

27 return ( 

28 bool(request.user and request.user.is_authenticated) 

29 and request.user.membership_set.exists() 

30 and request.user.is_active 

31 )