diff --git a/opentech/apply/determinations/tests/test_views.py b/opentech/apply/determinations/tests/test_views.py index 062e9f6f367237c9b2b608bdc836b99b60a42c8a..01a61dbdbab34af2ee76a3b5126ef4297fb0e7ec 100644 --- a/opentech/apply/determinations/tests/test_views.py +++ b/opentech/apply/determinations/tests/test_views.py @@ -123,6 +123,19 @@ class BatchDeterminationTestCase(BaseViewTestCase): url_name = 'funds:submissions:determinations:{}' base_view_name = 'batch' + def test_cant_access_without_submissions(self): + url = self.url(None) + '?action=rejected' + response = self.client.get(url, follow=True, secure=True) + self.assertRedirects(response, self.url_from_pattern('apply:submissions:list')) + self.assertEqual(len(response.context['messages']), 1) + + def test_cant_access_without_action(self): + submission = ApplicationSubmissionFactory() + url = self.url(None) + '?submissions=' + str(submission.id) + response = self.client.get(url, follow=True, secure=True) + self.assertRedirects(response, self.url_from_pattern('apply:submissions:list')) + self.assertEqual(len(response.context['messages']), 1) + def test_can_submit_batch_determination(self): submissions = ApplicationSubmissionFactory.create_batch(4) diff --git a/opentech/apply/determinations/views.py b/opentech/apply/determinations/views.py index 373812be3ddf849a0b2869919129757d4b19c5f3..7055211ee7487cb3900a6053714b8fbfb201141f 100644 --- a/opentech/apply/determinations/views.py +++ b/opentech/apply/determinations/views.py @@ -56,15 +56,24 @@ def get_form_for_stage(submission, batch=False): class BatchDeterminationCreateView(CreateView): template_name = 'determinations/batch_determination_form.html' + def dispatch(self, *args, **kwargs): + if not self.get_action() or not self.get_submissions(): + messages.warning(self.request, 'Improperly configured request, please try again.') + return HttpResponseRedirect(self.get_success_url()) + return super().dispatch(*args, **kwargs) + def get_action(self): return self.request.GET.get('action', '') def get_submissions(self): - submission_ids = self.request.GET.get('submissions').split(',') + try: + submission_ids = self.request.GET.get('submissions').split(',') + except AttributeError: + return None try: ids = [int(pk) for pk in submission_ids] except ValueError: - ids = [] + return None return ApplicationSubmission.objects.filter(id__in=ids) def get_form_kwargs(self):