Fix visibility of non-public plans in section list

This commit is contained in:
Stefan Wehrmeyer 2022-06-20 11:18:38 +02:00
parent 07d562f2d8
commit 5e43d627d7
4 changed files with 25 additions and 21 deletions

14
froide_govplan/auth.py Normal file
View file

@ -0,0 +1,14 @@
from .models import GovernmentPlan
def has_limited_access(user):
if not user.is_authenticated:
return True
return not user.has_perm("froide_govplan.add_governmentplan")
def get_allowed_plans(request):
if not has_limited_access(request.user):
return GovernmentPlan.objects.all()
groups = request.user.groups.all()
return GovernmentPlan.objects.filter(group__in=groups).distinct()