-
Notifications
You must be signed in to change notification settings - Fork 2.9k
[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 3 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,35 @@ | ||
| # 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 | ||
|
|
||
|
|
||
| class ProjectMemberSerializer(BaseSerializer): | ||
| """ | ||
| Serializer for project members. | ||
| """ | ||
|
|
||
| member = serializers.PrimaryKeyRelatedField( | ||
| queryset=User.objects.all(), | ||
| required=True, | ||
| ) | ||
|
|
||
| def validate_member(self, value): | ||
| slug = self.context["slug"] | ||
|
|
||
| if not value: | ||
| raise serializers.ValidationError("Member is required", code="INVALID_MEMBER") | ||
|
|
||
| if not User.objects.filter(id=value).exists(): | ||
| raise serializers.ValidationError("Member not found", 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 | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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.
Uh oh!
There was an error while loading. Please reload this page.