Skip to content

Commit 9ae0f1a

Browse files
committed
Use AdminPermission class for Organization (.users and .members)
With this pattern we can override them from Corporate using the same method we already have, without confusions. Note that .users and .members are exactly the same logic.
1 parent bab2b7f commit 9ae0f1a

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

readthedocs/core/permissions.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,23 @@
77

88
class AdminPermissionBase:
99

10+
@classmethod
11+
def admins(cls, project):
12+
return project.users.all()
13+
14+
@classmethod
15+
def members(cls, project):
16+
return project.users.all()
17+
1018
@classmethod
1119
def is_admin(cls, user, project):
1220
# This explicitly uses "user in project.users.all" so that
1321
# users on projects can be cached using prefetch_related or prefetch_related_objects
14-
return user in project.users.all() or user.is_superuser
22+
return user in cls.admins() or user.is_superuser
1523

1624
@classmethod
17-
def is_member(cls, user, obj):
18-
return user in obj.users.all() or user.is_superuser
25+
def is_member(cls, user, project):
26+
return user in cls.members(project) or user.is_superuser
1927

2028

2129
class AdminPermission(SettingsOverrideObject):

readthedocs/organizations/models.py

+9
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from django.utils.translation import ugettext_lazy as _
1010

1111
from readthedocs.core.utils import slugify
12+
from readthedocs.core.permissions import AdminPermission
1213

1314
from . import constants
1415
from .managers import TeamManager, TeamMemberManager
@@ -88,6 +89,14 @@ class Meta:
8889
def __str__(self):
8990
return self.name
9091

92+
@property
93+
def users(self):
94+
return AdminPermission.members(self)
95+
96+
@property
97+
def members(self):
98+
return AdminPermission.members(self)
99+
91100
def get_absolute_url(self):
92101
return reverse('organization_detail', args=(self.slug,))
93102

0 commit comments

Comments
 (0)