Skip to content

Querysets: remove private and for_project #8158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions readthedocs/builds/querysets.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,6 @@ def public(self, user=None, project=None, only_active=True,
queryset = queryset.filter(hidden=False)
return queryset.distinct()

def private(self, user=None, project=None, only_active=True):
queryset = self.filter(privacy_level__in=[constants.PRIVATE])
if user:
queryset = self._add_user_repos(queryset, user)
if project:
queryset = queryset.filter(project=project)
if only_active:
queryset = queryset.filter(active=True)
return queryset.distinct()

def api(self, user=None, detail=True):
if detail:
return self.public(user, only_active=False)
Expand All @@ -67,13 +57,6 @@ def api(self, user=None, detail=True):
queryset = self._add_user_repos(queryset, user)
return queryset.distinct()

def for_project(self, project):
"""Return all versions for a project, including translations."""
return self.filter(
models.Q(project=project) |
models.Q(project__main_language_project=project),
)


class VersionQuerySet(SettingsOverrideObject):
_default_class = VersionQuerySetBase
Expand Down
13 changes: 1 addition & 12 deletions readthedocs/projects/querysets.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,7 @@ def _add_user_repos(self, queryset, user=None):
return queryset

def public(self, user=None, project=None):
kwargs = {'%s__privacy_level' % self.project_field: constants.PUBLIC}
queryset = self.filter(**kwargs)
if user:
queryset = self._add_user_repos(queryset, user)
if project:
queryset = queryset.filter(project=project)
return queryset.distinct()

def private(self, user=None, project=None):
kwargs = {
'%s__privacy_level' % self.project_field: constants.PRIVATE,
}
kwargs = {f'{self.project_field}__privacy_level': constants.PUBLIC}
queryset = self.filter(**kwargs)
if user:
queryset = self._add_user_repos(queryset, user)
Expand Down
13 changes: 2 additions & 11 deletions readthedocs/rtd_tests/tests/test_privacy.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

from unittest import mock

from django.contrib.auth.models import User
from django.test import TestCase
from django.test.utils import override_settings
Expand All @@ -10,7 +10,6 @@
from readthedocs.projects.forms import UpdateProjectForm
from readthedocs.projects.models import Project


log = logging.getLogger(__name__)


Expand Down Expand Up @@ -309,7 +308,7 @@ def test_public_download_filename(self):
self.assertEqual(r._headers['x-accel-redirect'][1], '/proxito/media/htmlzip/django-kong/latest/django-kong.zip')
self.assertEqual(r._headers['content-disposition'][1], 'filename=django-kong-readthedocs-io-en-latest.zip')

# Build Filtering
# Build Filtering

def test_build_filtering(self):
kong = self._create_kong('public', 'private')
Expand All @@ -331,11 +330,3 @@ def test_build_filtering(self):
self.client.login(username='tester', password='test')
r = self.client.get('/projects/django-kong/builds/')
self.assertNotContains(r, 'test-slug')

def test_queryset_chaining(self):
"""Test that manager methods get set on related querysets."""
kong = self._create_kong('public', 'private')
self.assertEqual(
kong.versions.private().get(slug='latest').slug,
'latest',
)
135 changes: 0 additions & 135 deletions readthedocs/rtd_tests/tests/test_version_querysets.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,35 +130,6 @@ def test_public_project(self):
self.assertEqual(query.count(), len(versions))
self.assertEqual(set(query), versions)

def test_private(self):
query = Version.objects.private()
versions = {
self.version_private,
self.another_version_private,
self.shared_version_private,
}
self.assertEqual(query.count(), len(versions))
self.assertEqual(set(query), versions)

def test_private_user(self):
query = Version.objects.private(user=self.user)
versions = (
self.user_versions |
{self.another_version_private}
)
self.assertEqual(query.count(), len(versions))
self.assertEqual(set(query), versions)

def test_private_project(self):
query = Version.objects.private(user=self.user, project=self.project)
versions = {
self.version,
self.version_latest,
self.version_private,
}
self.assertEqual(query.count(), len(versions))
self.assertEqual(set(query), versions)

def test_api(self):
query = Version.objects.api()
versions = {
Expand All @@ -178,22 +149,6 @@ def test_api_user(self):
self.assertEqual(query.count(), len(versions))
self.assertEqual(set(query), versions)

def test_for_project(self):
self.another_project.main_language_project = self.project
self.another_project.save()

query = Version.objects.for_project(self.project)
versions = {
self.version,
self.version_latest,
self.version_private,
self.another_version,
self.another_version_latest,
self.another_version_private,
}
self.assertEqual(query.count(), len(versions))
self.assertEqual(set(query), versions)


class TestVersionQuerySetWithManagerBase(TestVersionQuerySetBase):

Expand Down Expand Up @@ -303,35 +258,6 @@ def test_public_project(self):
self.assertEqual(query.count(), len(versions))
self.assertEqual(set(query), versions)

def test_private(self):
query = Version.internal.private()
versions = {
self.version_private,
self.another_version_private,
self.shared_version_private,
}
self.assertEqual(query.count(), len(versions))
self.assertEqual(set(query), versions)

def test_private_user(self):
query = Version.internal.private(user=self.user)
versions = (
self.user_versions |
{self.another_version_private}
)
self.assertEqual(query.count(), len(versions))
self.assertEqual(set(query), versions)

def test_private_project(self):
query = Version.internal.private(user=self.user, project=self.project)
versions = {
self.version,
self.version_latest,
self.version_private,
}
self.assertEqual(query.count(), len(versions))
self.assertEqual(set(query), versions)

def test_api(self):
query = Version.internal.api()
versions = {
Expand All @@ -351,22 +277,6 @@ def test_api_user(self):
self.assertEqual(query.count(), len(versions))
self.assertEqual(set(query), versions)

def test_for_project(self):
self.another_project.main_language_project = self.project
self.another_project.save()

query = Version.internal.for_project(self.project)
versions = {
self.version,
self.version_latest,
self.version_private,
self.another_version,
self.another_version_latest,
self.another_version_private,
}
self.assertEqual(query.count(), len(versions))
self.assertEqual(set(query), versions)


class VersionQuerySetWithExternalManagerTest(TestVersionQuerySetWithManagerBase):

Expand Down Expand Up @@ -420,37 +330,6 @@ def test_public_project(self):
self.assertEqual(query.count(), len(versions))
self.assertEqual(set(query), versions)

def test_private(self):
query = Version.external.private()
versions = {
self.external_version_private,
self.another_external_version_private,
self.shared_external_version_private,
}
self.assertEqual(query.count(), len(versions))
self.assertEqual(set(query), versions)

def test_private_user(self):
query = Version.external.private(user=self.user)
versions = {
self.external_version_public,
self.external_version_private,
self.another_external_version_private,
self.shared_external_version_public,
self.shared_external_version_private,
}
self.assertEqual(query.count(), len(versions))
self.assertEqual(set(query), versions)

def test_private_project(self):
query = Version.external.private(user=self.user, project=self.project)
versions = {
self.external_version_public,
self.external_version_private,
}
self.assertEqual(query.count(), len(versions))
self.assertEqual(set(query), versions)

def test_api(self):
query = Version.external.api()
versions = {
Expand All @@ -471,17 +350,3 @@ def test_api_user(self):
}
self.assertEqual(query.count(), len(versions))
self.assertEqual(set(query), versions)

def test_for_project(self):
self.another_project.main_language_project = self.project
self.another_project.save()

query = Version.external.for_project(self.project)
versions = {
self.external_version_public,
self.external_version_private,
self.another_external_version_public,
self.another_external_version_private,
}
self.assertEqual(query.count(), len(versions))
self.assertEqual(set(query), versions)