diff --git a/emgapi/models.py b/emgapi/models.py index efb074d78..127b3ed10 100644 --- a/emgapi/models.py +++ b/emgapi/models.py @@ -300,39 +300,39 @@ def available(self, request=None): """ _query_filters = { 'StudyQuerySet': { - 'all': [Q(is_private=False),], + 'all': [Q(is_private=False, is_suppressed=False),], }, 'StudyDownloadQuerySet': { - 'all': [Q(study__is_private=False),], + 'all': [Q(study__is_private=False, study__is_suppressed=False),], }, 'SampleQuerySet': { - 'all': [Q(is_private=False),], + 'all': [Q(is_private=False, is_suppressed=False),], }, 'RunQuerySet': { 'all': [ - Q(is_private=False), + Q(is_private=False, is_suppressed=False), ], }, 'AssemblyQuerySet': { 'all': [ - Q(is_private=False), + Q(is_private=False, is_suppressed=False), ], }, 'AnalysisJobDownloadQuerySet': { 'all': [ - Q(job__study__is_private=False), + Q(job__study__is_private=False, job__study__is_suppressed=False), Q(job__run__is_private=False) | Q(job__assembly__is_private=False), Q(job__analysis_status_id=AnalysisStatus.COMPLETED) | Q(job__analysis_status_id=AnalysisStatus.QC_NOT_PASSED) ], }, 'AssemblyExtraAnnotationQuerySet': { 'all': [ - Q(assembly__is_private=False), + Q(assembly__is_private=False, assembly__is_suppressed=False), ], }, 'RunExtraAnnotationQuerySet': { 'all': [ - Q(run__is_private=False), + Q(run__is_private=False, run__is_suppressed=False), ], }, } @@ -340,33 +340,38 @@ def available(self, request=None): if request is not None and request.user.is_authenticated: _username = request.user.username _query_filters['StudyQuerySet']['authenticated'] = \ - [Q(submission_account_id__iexact=_username) | Q(is_private=False)] + [Q(submission_account_id__iexact=_username) | Q(is_private=False, is_suppressed=False)] _query_filters['StudyDownloadQuerySet']['authenticated'] = \ [Q(study__submission_account_id__iexact=_username) | - Q(study__is_private=False)] + Q(study__is_private=False, study__is_suppressed=False)] _query_filters['SampleQuerySet']['authenticated'] = \ - [Q(submission_account_id__iexact=_username) | Q(is_private=False)] + [Q(submission_account_id__iexact=_username) | Q(is_private=False), Q(is_suppressed=False)] _query_filters['RunQuerySet']['authenticated'] = \ [Q(study__submission_account_id__iexact=_username, is_private=True) | - Q(is_private=False)] + Q(is_private=False), + Q(is_suppressed=False)] _query_filters['AssemblyQuerySet']['authenticated'] = \ [Q(samples__studies__submission_account_id__iexact=_username, is_private=True) | - Q(is_private=False)] + Q(is_private=False), + Q(is_suppressed=False)] _query_filters['AnalysisJobDownloadQuerySet']['authenticated'] = \ [Q(job__study__submission_account_id__iexact=_username, job__is_private=True) | Q(job__study__submission_account_id__iexact=_username, job__assembly__is_private=True) | - Q(job__run__is_private=False) | Q(job__assembly__is_private=False)] + Q(job__run__is_private=False) | Q(job__assembly__is_private=False), + Q(job_is_suppressed=False)] _query_filters['AssemblyExtraAnnotationQuerySet']['authenticated'] = \ [Q(assembly__samples__studies__submission_account_id__iexact=_username, is_private=True) | - Q(assembly__is_private=False)] + Q(assembly__is_private=False), + Q(assembly__is_suppressed=False)] _query_filters['RunExtraAnnotationQuerySet']['authenticated'] = \ [Q(run__samples__studies__submission_account_id__iexact=_username, is_private=True) | - Q(run__is_private=False)] + Q(run__is_private=False), + Q(run__is_suppressed=False)] filters = _query_filters.get(self.__class__.__name__) diff --git a/tests/ena/test_sync_samples_with_ena.py b/tests/ena/test_sync_samples_with_ena.py index 9c2d539b0..122e8fc34 100644 --- a/tests/ena/test_sync_samples_with_ena.py +++ b/tests/ena/test_sync_samples_with_ena.py @@ -15,11 +15,9 @@ # limitations under the License. import pytest -import os from unittest.mock import patch -from django.urls import reverse from django.core.management import call_command from emgapi.models import Sample, Assembly, AnalysisJob, Run diff --git a/tests/ena/test_sync_studies_with_ena.py b/tests/ena/test_sync_studies_with_ena.py index 392a32df6..cadef3e15 100644 --- a/tests/ena/test_sync_studies_with_ena.py +++ b/tests/ena/test_sync_studies_with_ena.py @@ -47,6 +47,9 @@ def test_make_studies_private(self, ena_study_objs_mock, ena_private_studies): if study in public_studies: assert study.is_private == True + assert Study.objects.available(None).count() == 0 + + @patch("emgena.models.Study.objects") def test_make_studies_public(self, ena_study_objs_mock, ena_public_studies): ena_study_objs_mock.using("era").filter.return_value = ena_public_studies @@ -67,6 +70,8 @@ def test_make_studies_public(self, ena_study_objs_mock, ena_public_studies): if study in private_studies: assert study.is_private == False + assert Study.objects.available(None).count() == all_studies.count() + @patch("emgena.models.Study.objects") def test_suppress_studies(self, ena_study_objs_mock, ena_suppressed_studies): ena_study_objs_mock.using("era").filter.return_value = ena_suppressed_studies @@ -94,6 +99,8 @@ def test_suppress_studies(self, ena_study_objs_mock, ena_suppressed_studies): == study.get_suppression_reason_display().lower() ) + assert Study.objects.available(None).count() == 0 + @patch("emgena.models.Study.objects") def test_suppress_studies_propagation(self, ena_study_objs_mock, ena_suppression_propagation_studies): ena_study_objs_mock.using("era").filter.return_value = ena_suppression_propagation_studies