Skip to content

Commit 7b7bcbc

Browse files
authored
Permissions: avoid using project.users, use proper permissions instead (#8458)
One step further to fully depreate the signals in .com that add owners to a project.
1 parent 74e594c commit 7b7bcbc

File tree

5 files changed

+11
-13
lines changed

5 files changed

+11
-13
lines changed

readthedocs/builds/tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ def send_build_status(build_pk, commit, status, link_to_build=False):
376376
if provider_name in [GITHUB_BRAND, GITLAB_BRAND]:
377377
# get the service class for the project e.g: GitHubService.
378378
service_class = build.project.git_service_class()
379-
users = build.project.users.all()
379+
users = AdminPermission.admins(build.project)
380380

381381
if build.project.remote_repository:
382382
remote_repository = build.project.remote_repository

readthedocs/notifications/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def get_object_recipients(self, obj):
7878
7979
For example, this could be made to return project owners with::
8080
81-
for owner in project.users.all():
81+
for owner in AdminPermission.members(project):
8282
yield owner
8383
8484
:param obj: object from queryset, type is dependent on model class

readthedocs/oauth/services/github.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from allauth.socialaccount.models import SocialToken
88
from allauth.socialaccount.providers.github.views import GitHubOAuth2Adapter
9-
109
from django.conf import settings
1110
from django.urls import reverse
1211
from requests.exceptions import RequestException
@@ -17,13 +16,11 @@
1716
BUILD_STATUS_SUCCESS,
1817
SELECT_BUILD_STATUS,
1918
)
19+
from readthedocs.core.permissions import AdminPermission
2020
from readthedocs.integrations.models import Integration
2121

2222
from ..constants import GITHUB
23-
from ..models import (
24-
RemoteOrganization,
25-
RemoteRepository,
26-
)
23+
from ..models import RemoteOrganization, RemoteRepository
2724
from .base import Service, SyncServiceError
2825

2926
log = logging.getLogger(__name__)
@@ -547,7 +544,7 @@ def get_token_for_project(cls, project, force_local=False):
547544
if settings.DONT_HIT_DB and not force_local:
548545
token = api.project(project.pk).token().get()['token']
549546
else:
550-
for user in project.users.all():
547+
for user in AdminPermission.admins(project):
551548
tokens = SocialToken.objects.filter(
552549
account__user=user,
553550
app__provider=cls.adapter.provider_id,

readthedocs/projects/notifications.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from django.http import HttpRequest
77
from django.utils.translation import ugettext_lazy as _
88
from messages_extends.constants import ERROR_PERSISTENT
9+
from readthedocs.core.permissions import AdminPermission
910

1011
from readthedocs.notifications import Notification, SiteNotification
1112
from readthedocs.notifications.constants import REQUIREMENT
@@ -50,8 +51,8 @@ def notify_project_users(cls, projects):
5051
:type projects: [:py:class:`Project`]
5152
"""
5253
for project in projects:
53-
# Send one notification to each owner of the project
54-
for user in project.users.all():
54+
# Send one notification to each admin of the project
55+
for user in AdminPermission.admins(project):
5556
notification = cls(
5657
context_object=project,
5758
request=HttpRequest(),

readthedocs/projects/templatetags/projects_tags.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
from django import template
44

5+
from readthedocs.core.permissions import AdminPermission
56
from readthedocs.projects.version_handling import comparable_version
67

7-
88
register = template.Library()
99

1010

@@ -23,5 +23,5 @@ def sort_version_aware(versions):
2323

2424
@register.filter
2525
def is_project_user(user, project):
26-
"""Return if user is a member of project.users."""
27-
return user in project.users.all()
26+
"""Checks if the user has access to the project."""
27+
return user in AdminPermission.members(project)

0 commit comments

Comments
 (0)