Skip to content

Commit

Permalink
APIv3: return permissions expandable field on projects
Browse files Browse the repository at this point in the history
Add `?expand=permissions` to project list/detail API endpoints.

Related readthedocs/ext-theme#128
  • Loading branch information
humitos authored and agjohnson committed Jul 1, 2024
1 parent d2ad47b commit ec87791
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
15 changes: 15 additions & 0 deletions readthedocs/api/v3/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from readthedocs.builds.constants import LATEST, STABLE
from readthedocs.builds.models import Build, Version
from readthedocs.core.permissions import AdminPermission
from readthedocs.core.resolver import Resolver
from readthedocs.core.utils import slugify
from readthedocs.core.utils.extend import SettingsOverrideObject
Expand Down Expand Up @@ -715,6 +716,14 @@ class ProjectUpdateSerializer(SettingsOverrideObject):
_default_class = ProjectUpdateSerializerBase


class ProjectPermissionSerializer(serializers.Serializer):
admin = serializers.SerializerMethodField()

def get_admin(self, obj):
user = self.context.get("request").user
return AdminPermission.is_admin(user, obj)


class ProjectSerializer(FlexFieldsModelSerializer):

"""
Expand Down Expand Up @@ -798,6 +807,12 @@ class Meta:
"read_only": True,
},
),
"permissions": (
ProjectPermissionSerializer,
{
"source": "*",
},
),
}

def __init__(self, *args, **kwargs):
Expand Down
1 change: 1 addition & 0 deletions readthedocs/api/v3/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class ProjectsViewSetBase(
"active_versions.last_build",
"active_versions.last_build.config",
"organization",
"permissions",
"teams",
]

Expand Down

0 comments on commit ec87791

Please sign in to comment.