Coverage for apps/comments_views/core/rights.py: 91%

29 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-05-19 19:20 +0000

1from abc import ABC 

2from abc import abstractmethod 

3 

4from django.contrib.auth.models import AbstractBaseUser 

5from django.contrib.auth.models import AnonymousUser 

6 

7 

8class AbstractUserRights(ABC): 

9 COMMENT_POST_URL = "" 

10 user: AbstractBaseUser | AnonymousUser 

11 

12 def __init__(self, user: AbstractBaseUser | AnonymousUser): 

13 self.user = user 

14 

15 @abstractmethod 

16 def get_user_admin_collections(self) -> list[str]: 

17 pass 

18 

19 @abstractmethod 

20 def get_user_staff_collections(self) -> list[str]: 

21 pass 

22 

23 @abstractmethod 

24 def comment_rights_query_params(self) -> dict: 

25 """ 

26 Populates the correct query parameters according to the current user rights. 

27 The comment server will filter the comments queryset according to these filters. 

28 """ 

29 

30 @abstractmethod 

31 def comment_can_delete(self, comment: dict) -> bool: 

32 """Whether the current user can delete the provided comment.""" 

33 

34 @abstractmethod 

35 def comment_can_edit(self, comment: dict) -> bool: 

36 """Whether the current user can edit the provided comment.""" 

37 

38 @abstractmethod 

39 def comment_can_moderate(self, comment: dict) -> bool: 

40 """Whether the current user can moderate the provided comment.""" 

41 

42 @abstractmethod 

43 def comment_can_manage_moderators(self, comment) -> bool: 

44 """ 

45 Whether the curent user can manage the moderators of the given comment. 

46 """ 

47 

48 def is_admin_moderator(self) -> bool: 

49 """Whether the current user can manage all other moderators.""" 

50 return False 

51 

52 def is_staff_moderator(self) -> bool: 

53 """Whether the current user can manage base moderators.""" 

54 return False