Skip to content

Commit

Permalink
do not return suppressed study/samples etc
Browse files Browse the repository at this point in the history
  • Loading branch information
SandyRogers committed Jan 15, 2024
1 parent 4f2a203 commit bdfe892
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
37 changes: 21 additions & 16 deletions emgapi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,73 +300,78 @@ 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),
],
},
}

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__)

Expand Down
2 changes: 0 additions & 2 deletions tests/ena/test_sync_samples_with_ena.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions tests/ena/test_sync_studies_with_ena.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bdfe892

Please sign in to comment.