mirror of
https://github.com/ae-utbm/sith.git
synced 2026-09-09 22:09:14 +00:00
Fix ue comment view permission
This commit is contained in:
+11
-2
@@ -26,6 +26,7 @@ from django.conf import settings
|
|||||||
from django.core import validators
|
from django.core import validators
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models import Exists, OuterRef
|
from django.db.models import Exists, OuterRef
|
||||||
|
from django.db.models.query_utils import Q
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
@@ -159,7 +160,15 @@ class UECommentQuerySet(models.QuerySet):
|
|||||||
# so he can view non-moderated comments
|
# so he can view non-moderated comments
|
||||||
return self
|
return self
|
||||||
if user.has_perm("pedagogy.view_uecomment"):
|
if user.has_perm("pedagogy.view_uecomment"):
|
||||||
return self.filter(reports=None)
|
return self.filter(
|
||||||
|
Q(reports=None)
|
||||||
|
| Q(author=user)
|
||||||
|
| Q(
|
||||||
|
reports__in=UECommentReport.objects.filter(
|
||||||
|
comment=OuterRef("pk"), reporter__in=[user]
|
||||||
|
).all()
|
||||||
|
)
|
||||||
|
).distinct()
|
||||||
return self.filter(author=user)
|
return self.filter(author=user)
|
||||||
|
|
||||||
def annotate_is_reported(self) -> Self:
|
def annotate_is_reported(self) -> Self:
|
||||||
@@ -261,7 +270,7 @@ class UEResult(models.Model):
|
|||||||
|
|
||||||
|
|
||||||
class UECommentReport(models.Model):
|
class UECommentReport(models.Model):
|
||||||
"""Report an inapropriate comment."""
|
"""Report an inappropriate comment."""
|
||||||
|
|
||||||
comment = models.ForeignKey(
|
comment = models.ForeignKey(
|
||||||
UEComment,
|
UEComment,
|
||||||
|
|||||||
Reference in New Issue
Block a user