Coverage for src/comments_views/core/rights.py: 81%
27 statements
« prev ^ index » next coverage.py v7.7.0, created at 2025-04-09 14:49 +0000
« prev ^ index » next coverage.py v7.7.0, created at 2025-04-09 14:49 +0000
1from abc import ABC, abstractmethod
3from django.contrib.auth.models import AbstractBaseUser, AnonymousUser
6class AbstractUserRights(ABC):
7 COMMENT_POST_URL = ""
8 user: AbstractBaseUser | AnonymousUser
10 def __init__(self, user: AbstractBaseUser | AnonymousUser):
11 self.user = user
13 @abstractmethod
14 def get_user_admin_collections(self) -> list[str]:
15 pass
17 @abstractmethod
18 def get_user_staff_collections(self) -> list[str]:
19 pass
21 @abstractmethod
22 def comment_rights_query_params(self) -> dict:
23 """
24 Populates the correct query parameters according to the current user rights.
25 The comment server will filter the comments queryset according to these filters.
26 """
28 @abstractmethod
29 def comment_can_delete(self, comment: dict) -> bool:
30 """Whether the current user can delete the provided comment."""
32 @abstractmethod
33 def comment_can_edit(self, comment: dict) -> bool:
34 """Whether the current user can edit the provided comment."""
36 @abstractmethod
37 def comment_can_moderate(self, comment: dict) -> bool:
38 """Whether the current user can moderate the provided comment."""
40 @abstractmethod
41 def comment_can_manage_moderators(self, comment) -> bool:
42 """
43 Whether the curent user can manage the moderators of the given comment.
44 """
46 def is_admin_moderator(self) -> bool:
47 """Whether the current user can manage all other moderators."""
48 return False
50 def is_staff_moderator(self) -> bool:
51 """Whether the current user can manage base moderators."""
52 return False