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
« prev ^ index » next coverage.py v7.4.4, created at 2024-05-19 19:20 +0000
1from abc import ABC
2from abc import abstractmethod
4from django.contrib.auth.models import AbstractBaseUser
5from django.contrib.auth.models import AnonymousUser
8class AbstractUserRights(ABC):
9 COMMENT_POST_URL = ""
10 user: AbstractBaseUser | AnonymousUser
12 def __init__(self, user: AbstractBaseUser | AnonymousUser):
13 self.user = user
15 @abstractmethod
16 def get_user_admin_collections(self) -> list[str]:
17 pass
19 @abstractmethod
20 def get_user_staff_collections(self) -> list[str]:
21 pass
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 """
30 @abstractmethod
31 def comment_can_delete(self, comment: dict) -> bool:
32 """Whether the current user can delete the provided comment."""
34 @abstractmethod
35 def comment_can_edit(self, comment: dict) -> bool:
36 """Whether the current user can edit the provided comment."""
38 @abstractmethod
39 def comment_can_moderate(self, comment: dict) -> bool:
40 """Whether the current user can moderate the provided comment."""
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 """
48 def is_admin_moderator(self) -> bool:
49 """Whether the current user can manage all other moderators."""
50 return False
52 def is_staff_moderator(self) -> bool:
53 """Whether the current user can manage base moderators."""
54 return False