Repository: liqd/a4-meinberlin

Issue:
testing 4295: 402 error for poll export
**URL:** https://meinberlin-dev.liqd.net/dashboard/modules/umfrage-24/poll/export/
**user:** initiator, moderator, group member
**expected behaviour:** download export
**behaviour:** 403 error
**important screensize:**
**device & browser:** big sur, firefox
**Comment/Question:** 

Screenshot?



Discussion:

Resolving patch:
diff --git a/meinberlin/apps/polls/exports.py b/meinberlin/apps/polls/exports.py
--- a/meinberlin/apps/polls/exports.py
+++ b/meinberlin/apps/polls/exports.py
@@ -50,6 +50,9 @@ class PollExportView(
 
     permission_required = 'a4projects.change_project'
 
+    def get_permission_object(self):
+        return self.module.project
+
     def get_queryset(self):
         creators_vote = poll_models.Vote.objects.filter(
             choice__question__poll=self.poll).values_list('creator', flat=True)
@@ -63,47 +66,37 @@ def poll(self):
         return poll_models.Poll.objects.get(module=self.module)
 
     @property
-    def single_choice_questions(self):
-        return self.poll.questions.filter(
-            multiple_choice=False,
-            is_open=False).order_by('id')
-
-    @property
-    def multiple_choice_questions(self):
-        return self.poll.questions.filter(multiple_choice=True).order_by('id')
-
-    @property
-    def open_questions(self):
-        return self.poll.questions.filter(is_open=True).order_by('id')
+    def questions(self):
+        return self.poll.questions.all()
 
     def get_virtual_fields(self, virtual):
         virtual = super().get_virtual_fields(virtual)
-        virtual = self.get_virtual_fields_choice_questions(
-            virtual, self.single_choice_questions)
-        virtual = self.get_virtual_fields_choice_questions(
-            virtual, self.multiple_choice_questions)
-        virtual = self.get_virtual_fields_open_questions(
-            virtual, self.open_questions)
+
+        for question in self.questions:
+            if question.is_open:
+                virtual = \
+                    self.get_virtual_field_open_question(virtual, question)
+            else:
+                virtual = \
+                    self.get_virtual_field_choice_question(virtual, question)
 
         return virtual
 
-    def get_virtual_fields_choice_questions(self, virtual, choice_questions):
-        for question in choice_questions.all():
-            for choice in question.choices.all():
-                identifier = 'Q' + str(question.pk) + '_A' + str(choice.pk)
-                virtual[(choice, False)] = identifier
-                if choice.is_other_choice:
-                    identifier_answer = identifier + '_text'
-                    virtual[(choice, True)] = identifier_answer
+    def get_virtual_field_choice_question(self, virtual, choice_question):
+        for choice in choice_question.choices.all():
+            identifier = 'Q' + str(choice_question.pk) + '_A' + str(choice.pk)
+            virtual[(choice, False)] = identifier
+            if choice.is_other_choice:
+                identifier_answer = identifier + '_text'
+                virtual[(choice, True)] = identifier_answer
 
         return virtual
 
-    def get_virtual_fields_open_questions(self, virtual, open_questions):
-        for question in open_questions.all():
-            identifier = 'Q' + str(question.pk)
-            virtual[(question, False)] = identifier
-            identifier_answer = identifier + '_text'
-            virtual[(question, True)] = identifier_answer
+    def get_virtual_field_open_question(self, virtual, open_question):
+        identifier = 'Q' + str(open_question.pk)
+        virtual[(open_question, False)] = identifier
+        identifier_answer = identifier + '_text'
+        virtual[(open_question, True)] = identifier_answer
 
         return virtual
 


Test patch: