Coverage for sites/ptf_tools/comments_moderation/templatetags/moderation_tags.py: 100%
15 statements
« prev ^ index » next coverage.py v7.3.2, created at 2024-11-04 17:46 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2024-11-04 17:46 +0000
1from django import template
2from django.conf import settings
3from django.contrib.auth.models import AnonymousUser
4from django.contrib.auth.models import User
6from comments_moderation.rights import ModeratorUserRights
7from ptf_tools.templatetags.tools_helpers import get_authorized_collections
9from ..utils import is_comment_moderator
11register = template.Library()
14@register.filter
15def show_comments_nav(user: User | AnonymousUser) -> bool:
16 return (
17 not getattr(settings, "COMMENTS_DISABLED", False)
18 and isinstance(user, User)
19 and (is_comment_moderator(user) or get_authorized_collections(user) or user.is_superuser)
20 )
23@register.filter
24def can_manage_moderators(user: User) -> bool:
25 rights = ModeratorUserRights(user)
26 return (
27 len(rights.get_user_admin_collections()) > 0
28 or len(rights.get_user_staff_collections()) > 0
29 )