Skip to content

Commit 4d83138

Browse files
authored
QuerySets: check for .is_superuser instead of has_perm (#8181)
We use the is_superuser check in .com, while we check for has_perm in .org. These checks are only for the api user, and has_perm always returns true for superusers. I have checked and our api users are superusers, so all good.
1 parent 130b6b4 commit 4d83138

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

readthedocs/builds/querysets.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
from django.db.models import Q
77
from django.utils import timezone
88

9+
from readthedocs.builds.constants import (
10+
BUILD_STATE_FINISHED,
11+
BUILD_STATE_TRIGGERED,
12+
)
913
from readthedocs.core.utils.extend import SettingsOverrideObject
1014
from readthedocs.projects import constants
1115
from readthedocs.projects.models import Project
1216

13-
from .constants import BUILD_STATE_FINISHED, BUILD_STATE_TRIGGERED
14-
1517
log = logging.getLogger(__name__)
1618

1719

@@ -25,7 +27,7 @@ class VersionQuerySetBase(models.QuerySet):
2527
use_for_related_fields = True
2628

2729
def _add_user_repos(self, queryset, user):
28-
if user.has_perm('builds.view_version'):
30+
if user.is_superuser:
2931
return self.all()
3032
if user.is_authenticated:
3133
projects_pk = user.projects.all().values_list('pk', flat=True)
@@ -72,8 +74,8 @@ class BuildQuerySetBase(models.QuerySet):
7274

7375
use_for_related_fields = True
7476

75-
def _add_user_repos(self, queryset, user=None):
76-
if user.has_perm('builds.view_version'):
77+
def _add_user_repos(self, queryset, user):
78+
if user.is_superuser:
7779
return self.all()
7880
if user.is_authenticated:
7981
projects_pk = user.projects.all().values_list('pk', flat=True)
@@ -163,8 +165,8 @@ class RelatedBuildQuerySetBase(models.QuerySet):
163165

164166
use_for_related_fields = True
165167

166-
def _add_user_repos(self, queryset, user=None):
167-
if user.has_perm('builds.view_version'):
168+
def _add_user_repos(self, queryset, user):
169+
if user.is_superuser:
168170
return self.all()
169171
if user.is_authenticated:
170172
projects_pk = user.projects.all().values_list('pk', flat=True)

readthedocs/projects/querysets.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66

77
from readthedocs.builds.constants import EXTERNAL
88
from readthedocs.core.utils.extend import SettingsOverrideObject
9-
10-
from . import constants
9+
from readthedocs.projects import constants
1110

1211

1312
class ProjectQuerySetBase(models.QuerySet):
@@ -17,7 +16,7 @@ class ProjectQuerySetBase(models.QuerySet):
1716
use_for_related_fields = True
1817

1918
def _add_user_repos(self, queryset, user):
20-
if user.has_perm('projects.view_project'):
19+
if user.is_superuser:
2120
return self.all()
2221
if user.is_authenticated:
2322
user_queryset = user.projects.all()
@@ -157,8 +156,8 @@ class RelatedProjectQuerySetBase(models.QuerySet):
157156
use_for_related_fields = True
158157
project_field = 'project'
159158

160-
def _add_user_repos(self, queryset, user=None):
161-
if user.has_perm('projects.view_project'):
159+
def _add_user_repos(self, queryset, user):
160+
if user.is_superuser:
162161
return self.all()
163162
if user.is_authenticated:
164163
projects_pk = user.projects.all().values_list('pk', flat=True)

0 commit comments

Comments
 (0)