-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Remove privacy app #2954
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
Remove privacy app #2954
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
"""Build and Version class model Managers""" | ||
|
||
from __future__ import absolute_import | ||
|
||
from django.db import models | ||
|
||
from .constants import (BRANCH, TAG, LATEST, LATEST_VERBOSE_NAME, STABLE, | ||
STABLE_VERBOSE_NAME) | ||
from .querysets import VersionQuerySet | ||
from readthedocs.core.utils.extend import (SettingsOverrideObject, | ||
get_override_class) | ||
|
||
|
||
__all__ = ['VersionManager'] | ||
|
||
|
||
class VersionManagerBase(models.Manager): | ||
|
||
"""Version manager for manager only queries | ||
|
||
For queries not suitable for the :py:cls:`VersionQuerySet`, such as create | ||
queries. | ||
""" | ||
|
||
@classmethod | ||
def from_queryset(cls, queryset_class, class_name=None): | ||
# This is overridden because :py:meth:`models.Manager.from_queryset` | ||
# uses `inspect` to retrieve the class methods, and the proxy class has | ||
# no direct members. | ||
queryset_class = get_override_class( | ||
VersionQuerySet, | ||
VersionQuerySet._default_class # pylint: disable=protected-access | ||
) | ||
return super(VersionManagerBase, cls).from_queryset(queryset_class, class_name) | ||
|
||
def create_stable(self, **kwargs): | ||
defaults = { | ||
'slug': STABLE, | ||
'verbose_name': STABLE_VERBOSE_NAME, | ||
'machine': True, | ||
'active': True, | ||
'identifier': STABLE, | ||
'type': TAG, | ||
} | ||
defaults.update(kwargs) | ||
return self.create(**defaults) | ||
|
||
def create_latest(self, **kwargs): | ||
defaults = { | ||
'slug': LATEST, | ||
'verbose_name': LATEST_VERBOSE_NAME, | ||
'machine': True, | ||
'active': True, | ||
'identifier': LATEST, | ||
'type': BRANCH, | ||
} | ||
defaults.update(kwargs) | ||
return self.create(**defaults) | ||
|
||
|
||
class VersionManager(SettingsOverrideObject): | ||
_default_class = VersionManagerBase | ||
_override_setting = 'VERSION_MANAGER' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
"""Build and Version QuerySet classes""" | ||
|
||
from __future__ import absolute_import | ||
|
||
from django.db import models | ||
from guardian.shortcuts import get_objects_for_user | ||
|
||
from readthedocs.core.utils.extend import SettingsOverrideObject | ||
from readthedocs.projects import constants | ||
|
||
|
||
__all__ = ['VersionQuerySet', 'BuildQuerySet', 'RelatedBuildQuerySet'] | ||
|
||
|
||
class VersionQuerySetBase(models.QuerySet): | ||
|
||
"""Versions take into account their own privacy_level setting.""" | ||
|
||
use_for_related_fields = True | ||
|
||
def _add_user_repos(self, queryset, user): | ||
if user.has_perm('builds.view_version'): | ||
return self.all().distinct() | ||
if user.is_authenticated(): | ||
user_queryset = get_objects_for_user(user, 'builds.view_version') | ||
queryset = user_queryset | queryset | ||
return queryset.distinct() | ||
|
||
def public(self, user=None, project=None, only_active=True): | ||
queryset = self.filter(privacy_level=constants.PUBLIC) | ||
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 | ||
|
||
def protected(self, user=None, project=None, only_active=True): | ||
queryset = self.filter(privacy_level__in=[constants.PUBLIC, constants.PROTECTED]) | ||
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 | ||
|
||
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 | ||
|
||
def api(self, user=None): | ||
return self.public(user, only_active=False) | ||
|
||
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 | ||
|
||
|
||
class BuildQuerySetBase(models.QuerySet): | ||
|
||
""" | ||
Build objects that are privacy aware. | ||
|
||
i.e. they take into account the privacy of the Version that they relate to. | ||
""" | ||
|
||
use_for_related_fields = True | ||
|
||
def _add_user_repos(self, queryset, user=None): | ||
if user.has_perm('builds.view_version'): | ||
return self.all().distinct() | ||
if user.is_authenticated(): | ||
user_queryset = get_objects_for_user(user, 'builds.view_version') | ||
pks = [p.pk for p in user_queryset] | ||
queryset = self.filter(version__pk__in=pks) | queryset | ||
return queryset.distinct() | ||
|
||
def public(self, user=None, project=None): | ||
queryset = self.filter(version__privacy_level=constants.PUBLIC) | ||
if user: | ||
queryset = self._add_user_repos(queryset, user) | ||
if project: | ||
queryset = queryset.filter(project=project) | ||
return queryset | ||
|
||
def api(self, user=None): | ||
return self.public(user) | ||
|
||
|
||
class BuildQuerySet(SettingsOverrideObject): | ||
_default_class = BuildQuerySetBase | ||
_override_setting = 'BUILD_MANAGER' | ||
|
||
|
||
class RelatedBuildQuerySetBase(models.QuerySet): | ||
|
||
"""For models with association to a project through :py:class:`Build`""" | ||
|
||
use_for_related_fields = True | ||
|
||
def _add_user_repos(self, queryset, user=None): | ||
if user.has_perm('builds.view_version'): | ||
return self.all().distinct() | ||
if user.is_authenticated(): | ||
user_queryset = get_objects_for_user(user, 'builds.view_version') | ||
pks = [p.pk for p in user_queryset] | ||
queryset = self.filter( | ||
build__version__pk__in=pks) | queryset | ||
return queryset.distinct() | ||
|
||
def public(self, user=None, project=None): | ||
queryset = self.filter(build__version__privacy_level=constants.PUBLIC) | ||
if user: | ||
queryset = self._add_user_repos(queryset, user) | ||
if project: | ||
queryset = queryset.filter(build__project=project) | ||
return queryset | ||
|
||
def api(self, user=None): | ||
return self.public(user) | ||
|
||
|
||
class RelatedBuildQuerySet(SettingsOverrideObject): | ||
_default_class = RelatedBuildQuerySetBase | ||
_override_setting = 'RELATED_BUILD_MANAGER' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
"""Objects for User permission checks""" | ||
|
||
from __future__ import absolute_import | ||
|
||
from readthedocs.core.utils.extend import SettingsOverrideObject | ||
|
||
|
||
class AdminPermissionBase(object): | ||
|
||
@classmethod | ||
def is_admin(cls, user, project): | ||
return user in project.users.all() | ||
|
||
@classmethod | ||
def is_member(cls, user, obj): | ||
return user in obj.users.all() | ||
|
||
|
||
class AdminPermission(SettingsOverrideObject): | ||
_default_class = AdminPermissionBase | ||
_override_setting = 'ADMIN_PERMISSION' |
5 changes: 3 additions & 2 deletions
5
...docs/privacy/templatetags/privacy_tags.py → ...thedocs/core/templatetags/privacy_tags.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"""Managers for OAuth models""" | ||
|
||
from __future__ import absolute_import | ||
|
||
from django.db import models | ||
|
||
from readthedocs.core.utils.extend import SettingsOverrideObject | ||
|
||
|
||
class RelatedUserQuerySetBase(models.QuerySet): | ||
|
||
"""For models with relations through :py:class:`User`""" | ||
|
||
def api(self, user=None): | ||
"""Return objects for user""" | ||
if not user.is_authenticated(): | ||
return self.none() | ||
return self.filter(users=user) | ||
|
||
|
||
class RelatedUserQuerySet(SettingsOverrideObject): | ||
_default_class = RelatedUserQuerySetBase | ||
_override_setting = 'RELATED_USER_MANAGER' | ||
|
||
|
||
class RemoteRepositoryQuerySet(RelatedUserQuerySet): | ||
pass | ||
|
||
|
||
class RemoteOrganizationQuerySet(RelatedUserQuerySet): | ||
pass |
Empty file.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Believe this file rename will need to change in our prod settings too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup! I got a PR on ops, but it needs to be updated as it's conflicting with the other PR you opened around Syncers