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 committed Jan 2, 2024
1 parent 963405f commit ef4b5bc
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 @@ -12,6 +12,7 @@
from taggit.serializers import TaggitSerializer, TagListSerializerField

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 @@ -591,6 +592,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 @@ -674,6 +683,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 @@ -126,6 +126,7 @@ class ProjectsViewSetBase(
"active_versions.last_build",
"active_versions.last_build.config",
"organization",
"permissions",
"teams",
]

Expand Down

0 comments on commit ef4b5bc

Please sign in to comment.