Skip to content
Snippets Groups Projects
Commit 2ffcc2c7 authored by Yoann Schneider's avatar Yoann Schneider :tennis: Committed by Bastien Abadie
Browse files

ignore configuration filter when mode is set to template

parent d59cfa6e
No related branches found
No related tags found
1 merge request!1582ignore configuration filter when mode is set to template
......@@ -153,10 +153,6 @@ class DataImportsList(ProcessACLMixin, ListAPIView):
def get_queryset(self):
filters = Q()
if 'with_workflow' in self.request.query_params:
with_workflow = self.request.query_params['with_workflow']
filters &= Q(workflow__isnull=bool(with_workflow and with_workflow.lower() in ('false', '0')))
if 'corpus' in self.request.query_params:
corpus_id = self.request.query_params['corpus']
try:
......@@ -166,14 +162,23 @@ class DataImportsList(ProcessACLMixin, ListAPIView):
# No supplementary validation is required on the corpus ID filter
filters &= Q(corpus=corpus_id)
# Default import_mode variable for compatibility later
import_mode = None
if 'mode' in self.request.query_params:
try:
filters &= Q(mode=DataImportMode(self.request.query_params['mode']))
import_mode = DataImportMode(self.request.query_params['mode'])
filters &= Q(mode=import_mode)
except ValueError:
raise ValidationError({
'mode': ["Mode '{}' does not exist".format(self.request.query_params['mode'])]
})
# When listing template processes, the configuration filters makes no sense
if import_mode != DataImportMode.Template:
if 'with_workflow' in self.request.query_params:
with_workflow = self.request.query_params['with_workflow']
filters &= Q(workflow__isnull=bool(with_workflow and with_workflow.lower() in ('false', '0')))
if 'created' in self.request.query_params:
created = self.request.query_params['created']
creator_filter = Q(creator_id=self.request.user.id)
......
......@@ -299,3 +299,16 @@ class TestTemplates(FixtureAPITestCase):
# Check that every new worker_run is the same as one of the template's
self.assertTrue(self.template.worker_runs.filter(version=parent_run.version).exists())
self.assertTrue(self.template.worker_runs.filter(version=child_run.version).exists())
def test_list_templates_ignores_configuration_filter(self):
self.client.force_login(self.user)
with self.assertNumQueries(7):
response = self.client.get(
reverse('api:import-list'),
data={"mode": 'template', "with_workflow": True},
content_type='application/json',
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
# The 'with_workflow' filter should be ignored and some templates should be returned
# If it wasn't, no template are returned because none are configured
self.assertTrue(len(response.json()) > 0)
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