Skip to content

Commit

Permalink
Refactored usage of BasePrivacyFilter. Reusable between models
Browse files Browse the repository at this point in the history
  • Loading branch information
MGS-sails committed Jan 7, 2025
1 parent 8576827 commit 62f4dc2
Showing 1 changed file with 4 additions and 24 deletions.
28 changes: 4 additions & 24 deletions analyses/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def lineage_to_path(lineage: str) -> str:
return re.sub(r"[^a-zA-Z0-9._]", "", underscore_punctuated)


class BasePublicStudyManager:
class BasePrivacyFilterManager:
"""
Base mixin providing common privacy filtering methods for studies
"""
Expand Down Expand Up @@ -106,7 +106,7 @@ async def get_or_create_for_ena_study(self, ena_study_accession):
return study


class PublicStudyManager(BasePublicStudyManager, StudyManager):
class PublicStudyManager(BasePrivacyFilterManager, StudyManager):
"""
A custom manager that filters out private studies by default.
"""
Expand Down Expand Up @@ -441,28 +441,8 @@ def get_queryset(self):
return super().get_queryset()


class BasePublicAnalysisManager:
"""
Base mixin providing common privacy filtering methods
"""

def get_queryset(self, include_private=False, private_only=False):
qs = super().get_queryset()
if private_only:
return qs.filter(is_private=True)
if not include_private:
return qs.filter(is_private=False)
return qs

def private_only(self):
"""
Returns only private analyses
"""
return self.get_queryset(private_only=True)


class PublicAnalysisManager(
BasePublicAnalysisManager, AnalysisManagerDeferringAnnotations
BasePrivacyFilterManager, AnalysisManagerDeferringAnnotations
):
"""
A custom manager that filters out private analyses by default.
Expand All @@ -472,7 +452,7 @@ class PublicAnalysisManager(


class PublicAnalysisManagerIncludingAnnotations(
BasePublicAnalysisManager, AnalysisManagerIncludingAnnotations
BasePrivacyFilterManager, AnalysisManagerIncludingAnnotations
):
"""
A custom manager that includes annotations but still filters out private analyses by default.
Expand Down

0 comments on commit 62f4dc2

Please sign in to comment.