-
Notifications
You must be signed in to change notification settings - Fork 4.4k
feat(api): expose project pages in the public REST API #9020
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Ojajajajaja
wants to merge
2
commits into
makeplane:preview
Choose a base branch
from
Ojajajajaja:feat/public-api-pages
base: preview
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| # Copyright (c) 2023-present Plane Software, Inc. and contributors | ||
| # SPDX-License-Identifier: AGPL-3.0-only | ||
| # See the LICENSE file for details. | ||
|
|
||
| # Module imports | ||
| from .base import BaseSerializer | ||
| from plane.db.models import Page, ProjectPage, Project | ||
|
|
||
|
|
||
| class PageSerializer(BaseSerializer): | ||
| """ | ||
| Serializer for project pages. | ||
|
|
||
| Handles creation of a Page along with its ProjectPage join row so the | ||
| public API can create, list, retrieve and update pages scoped to a | ||
| project. Labels and revisions are not exposed in the MVP serializer. | ||
| """ | ||
|
|
||
| class Meta: | ||
| model = Page | ||
| fields = [ | ||
| "id", | ||
| "name", | ||
| "description_html", | ||
| "description_json", | ||
| "owned_by", | ||
| "access", | ||
| "color", | ||
| "parent", | ||
| "is_locked", | ||
| "archived_at", | ||
| "view_props", | ||
| "logo_props", | ||
| "sort_order", | ||
| "external_id", | ||
| "external_source", | ||
| "workspace", | ||
| "created_at", | ||
| "updated_at", | ||
| "created_by", | ||
| "updated_by", | ||
| ] | ||
| read_only_fields = [ | ||
| "id", | ||
| "owned_by", | ||
| "workspace", | ||
| "created_at", | ||
| "updated_at", | ||
| "created_by", | ||
| "updated_by", | ||
| ] | ||
|
|
||
| def create(self, validated_data): | ||
| project_id = self.context["project_id"] | ||
| owned_by_id = self.context["owned_by_id"] | ||
|
|
||
| project = Project.objects.get(pk=project_id) | ||
|
|
||
| page = Page.objects.create( | ||
| **validated_data, | ||
| owned_by_id=owned_by_id, | ||
| workspace_id=project.workspace_id, | ||
| ) | ||
|
|
||
| ProjectPage.objects.create( | ||
| workspace_id=page.workspace_id, | ||
| project_id=project_id, | ||
| page_id=page.id, | ||
| created_by_id=page.created_by_id, | ||
| updated_by_id=page.updated_by_id, | ||
| ) | ||
|
|
||
| return page | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| # Copyright (c) 2023-present Plane Software, Inc. and contributors | ||
| # SPDX-License-Identifier: AGPL-3.0-only | ||
| # See the LICENSE file for details. | ||
|
|
||
| from django.urls import path | ||
|
|
||
| from plane.api.views import ( | ||
| ProjectPageListCreateAPIEndpoint, | ||
| ProjectPageDetailAPIEndpoint, | ||
| ProjectPageArchiveAPIEndpoint, | ||
| ProjectPageLockAPIEndpoint, | ||
| ProjectPageAccessAPIEndpoint, | ||
| ProjectPageDuplicateAPIEndpoint, | ||
| ProjectPageSummaryAPIEndpoint, | ||
| ) | ||
|
|
||
| urlpatterns = [ | ||
| # CRUD | ||
| path( | ||
| "workspaces/<str:slug>/projects/<uuid:project_id>/pages/", | ||
| ProjectPageListCreateAPIEndpoint.as_view(http_method_names=["get", "post"]), | ||
| name="project-pages", | ||
| ), | ||
| path( | ||
| "workspaces/<str:slug>/projects/<uuid:project_id>/pages/<uuid:page_id>/", | ||
| ProjectPageDetailAPIEndpoint.as_view(http_method_names=["get", "patch", "delete"]), | ||
| name="project-pages", | ||
| ), | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| # Summary | ||
| path( | ||
| "workspaces/<str:slug>/projects/<uuid:project_id>/pages-summary/", | ||
| ProjectPageSummaryAPIEndpoint.as_view(http_method_names=["get"]), | ||
| name="project-pages-summary", | ||
| ), | ||
| # Archive / unarchive | ||
| path( | ||
| "workspaces/<str:slug>/projects/<uuid:project_id>/pages/<uuid:page_id>/archive/", | ||
| ProjectPageArchiveAPIEndpoint.as_view(http_method_names=["post", "delete"]), | ||
| name="project-page-archive-unarchive", | ||
| ), | ||
| path( | ||
| "workspaces/<str:slug>/projects/<uuid:project_id>/archived-pages/", | ||
| ProjectPageArchiveAPIEndpoint.as_view(http_method_names=["get"]), | ||
| name="project-archived-pages", | ||
| ), | ||
| # Lock / unlock | ||
| path( | ||
| "workspaces/<str:slug>/projects/<uuid:project_id>/pages/<uuid:page_id>/lock/", | ||
| ProjectPageLockAPIEndpoint.as_view(http_method_names=["post", "delete"]), | ||
| name="project-pages-lock-unlock", | ||
| ), | ||
| # Access toggle | ||
| path( | ||
| "workspaces/<str:slug>/projects/<uuid:project_id>/pages/<uuid:page_id>/access/", | ||
| ProjectPageAccessAPIEndpoint.as_view(http_method_names=["post"]), | ||
| name="project-pages-access", | ||
| ), | ||
| # Duplicate | ||
| path( | ||
| "workspaces/<str:slug>/projects/<uuid:project_id>/pages/<uuid:page_id>/duplicate/", | ||
| ProjectPageDuplicateAPIEndpoint.as_view(http_method_names=["post"]), | ||
| name="project-pages-duplicate", | ||
| ), | ||
| ] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is_lockedandarchived_atshould be read-only.Both fields are managed exclusively by the dedicated
/lock/and/archive/endpoints (which enforce ownership checks, recursive cascade, etc.). Exposing them as writable in the serializer lets a client silently setis_locked=trueorarchived_at=<timestamp>on aPOST /pages/orPATCH /pages/<id>/call, completely bypassing that business logic.🛡️ Proposed fix
read_only_fields = [ "id", "owned_by", "workspace", "created_at", "updated_at", "created_by", "updated_by", + "is_locked", + "archived_at", ]🤖 Prompt for AI Agents