-
Notifications
You must be signed in to change notification settings - Fork 3k
[WEB-5237] feat: add workspace invitation and project member management endpoints #8059
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
65d8520
feat: add workspace invitation and project member management endpoints
pablohashescobar 5500e50
refactor: simplify invitation URL routing with DefaultRouter
pablohashescobar c72688b
refactor: reorganize permission imports and introduce new permission …
pablohashescobar 78f8c33
refactor: update project member API endpoints for improved functionality
pablohashescobar 5275e21
refactor: enhance member validation and permission checks in serializ…
pablohashescobar f0e9ac4
refactor: remove unused methods and clean up project member detail en…
pablohashescobar f823a89
feat: add additional project member API endpoints for improved access
pablohashescobar 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,56 @@ | ||
| # Django imports | ||
| from django.core.exceptions import ValidationError | ||
| from django.core.validators import validate_email | ||
| from rest_framework import serializers | ||
|
|
||
| # Module imports | ||
| from plane.db.models import WorkspaceMemberInvite | ||
| from .base import BaseSerializer | ||
| from plane.app.permissions.base import ROLE | ||
|
|
||
|
|
||
| class WorkspaceInviteSerializer(BaseSerializer): | ||
| """ | ||
| Serializer for workspace invites. | ||
| """ | ||
|
|
||
| class Meta: | ||
| model = WorkspaceMemberInvite | ||
| fields = [ | ||
| "id", | ||
| "email", | ||
| "role", | ||
| "created_at", | ||
| "updated_at", | ||
| "responded_at", | ||
| "accepted", | ||
| ] | ||
| read_only_fields = [ | ||
| "id", | ||
| "workspace", | ||
| "created_at", | ||
| "updated_at", | ||
| "responded_at", | ||
| "accepted", | ||
| ] | ||
|
|
||
| def validate_email(self, value): | ||
| try: | ||
| validate_email(value) | ||
| except ValidationError: | ||
| raise serializers.ValidationError("Invalid email address", code="INVALID_EMAIL_ADDRESS") | ||
| return value | ||
|
|
||
| def validate_role(self, value): | ||
| if value not in [ROLE.ADMIN.value, ROLE.MEMBER.value, ROLE.GUEST.value]: | ||
| raise serializers.ValidationError("Invalid role", code="INVALID_WORKSPACE_MEMBER_ROLE") | ||
| return value | ||
|
|
||
| def validate(self, data): | ||
| slug = self.context["slug"] | ||
| if ( | ||
| data.get("email") | ||
| and WorkspaceMemberInvite.objects.filter(email=data["email"], workspace__slug=slug).exists() | ||
| ): | ||
| raise serializers.ValidationError("Email already invited", code="EMAIL_ALREADY_INVITED") | ||
| return data |
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,39 @@ | ||
| # Third party imports | ||
| from rest_framework import serializers | ||
|
|
||
| # Module imports | ||
| from plane.db.models import ProjectMember, WorkspaceMember | ||
| from .base import BaseSerializer | ||
| from plane.db.models import User | ||
| from plane.utils.permissions import ROLE | ||
|
|
||
|
|
||
| class ProjectMemberSerializer(BaseSerializer): | ||
| """ | ||
| Serializer for project members. | ||
| """ | ||
|
|
||
| member = serializers.PrimaryKeyRelatedField( | ||
| queryset=User.objects.all(), | ||
| required=True, | ||
| ) | ||
|
|
||
| def validate_member(self, value): | ||
| slug = self.context.get("slug") | ||
| if not slug: | ||
| raise serializers.ValidationError("Slug is required", code="INVALID_SLUG") | ||
| if not value: | ||
| raise serializers.ValidationError("Member is required", code="INVALID_MEMBER") | ||
| if not WorkspaceMember.objects.filter(workspace__slug=slug, member=value).exists(): | ||
| raise serializers.ValidationError("Member not found in workspace", code="INVALID_MEMBER") | ||
| return value | ||
|
|
||
| def validate_role(self, value): | ||
| if value not in [ROLE.ADMIN.value, ROLE.MEMBER.value, ROLE.GUEST.value]: | ||
| raise serializers.ValidationError("Invalid role", code="INVALID_ROLE") | ||
| return value | ||
|
|
||
| class Meta: | ||
| model = ProjectMember | ||
| fields = ["id", "member", "role"] | ||
| read_only_fields = ["id"] |
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,18 @@ | ||
| # Django imports | ||
| from django.urls import path, include | ||
|
|
||
| # Third party imports | ||
| from rest_framework.routers import DefaultRouter | ||
|
|
||
| # Module imports | ||
| from plane.api.views import WorkspaceInvitationsViewset | ||
|
|
||
|
|
||
| # Create router with just the invitations prefix (no workspace slug) | ||
| router = DefaultRouter() | ||
| router.register(r"invitations", WorkspaceInvitationsViewset, basename="workspace-invitations") | ||
|
|
||
| # Wrap the router URLs with the workspace slug path | ||
| urlpatterns = [ | ||
| path("workspaces/<str:slug>/", include(router.urls)), | ||
| ] |
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
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.
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.
🧩 Analysis chain
Duplicate URL pattern names and redundant routes.
These routes introduce two critical issues:
Duplicate URL pattern names: The names
"project-members"(line 20) and"project-member"(line 25) conflict with the names at lines 10 and 15. Django'sreverse()function will not be able to resolve these names unambiguously.Redundant API endpoints: The
/project-members/routes (lines 17-26) appear functionally identical to the/members/routes (lines 7-16)—they use the same view classes, HTTP methods, and provide the same functionality. Having two different URL paths for the same resource violates RESTful API design principles and creates confusion for API consumers.Questions:
/members/and/project-members/endpoints?If both endpoints are truly required, apply this diff to fix the naming conflict:
path( "workspaces/<str:slug>/projects/<uuid:project_id>/project-members/", ProjectMemberListCreateAPIEndpoint.as_view(http_method_names=["get", "post"]), - name="project-members", + name="project-members-alt", ), path( "workspaces/<str:slug>/projects/<uuid:project_id>/project-members/<uuid:pk>/", ProjectMemberDetailAPIEndpoint.as_view(http_method_names=["patch", "delete", "get"]), - name="project-member", + name="project-member-alt", ),However, the recommended solution is to remove the duplicate routes entirely unless there is a documented justification for maintaining both.
I'll verify the concerns in the review comment by examining the full URL configuration and checking for references throughout the codebase.
Length of output: 1225
🏁 Script executed:
Length of output: 0
🏁 Script executed:
Length of output: 68
Let me search more broadly for references and test usage:
Length of output: 0
🏁 Script executed:
Length of output: 2834
🏁 Script executed:
Length of output: 634
🏁 Script executed:
Length of output: 0
Remove duplicate URL pattern names and resolve redundant routes.
The codebase has confirmed duplicate URL pattern names in
member.py:name="project-members"name="project-member"Django's
reverse()function cannot resolve duplicate names unambiguously. A test file comment intest_project_app.py(line 19-20) explicitly acknowledges this problem: "unreliable due to duplicate 'name' values in URL patterns."Additionally, both
/members/and/project-members/route pairs use identical views and HTTP methods, creating redundant API endpoints for the same resource.Fix required:
Either:
name="project-members-alt"andname="project-member-alt"as a temporary measureDetermine which path (
/members/or/project-members/) should be the canonical endpoint and remove or deprecate the other.🤖 Prompt for AI Agents