Skip to content
Snippets Groups Projects
Verified Commit a6400c89 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Filter selectable groups in upload form by permissions

parent 1573dcf2
No related branches found
No related tags found
No related merge requests found
from django import forms
from django.http import HttpRequest
from guardian.shortcuts import get_objects_for_user
from material import Layout, Row
from .models import Poster, PosterGroup
......@@ -35,3 +37,10 @@ class PosterUploadForm(forms.ModelForm):
class Meta:
model = Poster
fields = ["group", "week", "year", "pdf"]
def __init__(self, request: HttpRequest, *args, **kwargs):
super().__init__(*args, **kwargs)
qs = PosterGroup.objects.all()
if not request.user.has_perm("resint.view_postergroup"):
qs = get_objects_for_user(request.user, "resint.add_poster_to_group", qs)
self.fields["group"].queryset = qs
......@@ -75,7 +75,7 @@ add_perm("resint.view_posters_rule", view_posters_predicate)
# Upload poster
upload_poster_predicate = view_posters_predicate & (
has_global_perm("resint.add_poster") | has_any_object("resint.add_poster_to_group", PosterGroup)
) # FIXME FIlter on form
)
add_perm("resint.upload_poster_rule", upload_poster_predicate)
# Edit poster
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment