Commit bceddcc4 authored by Samuel GAIST's avatar Samuel GAIST Committed by Samuel GAIST
Browse files

[reports] Add for_user method

This allows to accurately reflect what the user
can see from the platform.
parent 4e428cd1
......@@ -33,6 +33,7 @@ from django.conf import settings
from django.contrib.auth.models import User
from django.core import exceptions as django_exceptions
from django.db import models
from django.db.models import Q
from django.urls import reverse
from django.utils.encoding import force_bytes
from django.utils.encoding import force_text
......@@ -93,6 +94,17 @@ class ReportManager(models.Manager):
def published(self):
return self.filter(status=Report.PUBLISHED)
def for_user(self, user, add_public=False):
if user.is_anonymous:
return self.published()
query = Q(author=user)
if add_public:
query |= Q(status=Report.PUBLISHED)
return self.filter(query).distinct()
# ----------------------------------------------------------
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment