forked from github/plane
dev: project invite workflow
This commit is contained in:
parent
34bccd7e06
commit
112c418047
@ -361,20 +361,37 @@ class InviteProjectEndpoint(BaseAPIView):
|
|||||||
)
|
)
|
||||||
|
|
||||||
validate_email(email)
|
validate_email(email)
|
||||||
# Check if user is already a member of workspace
|
|
||||||
|
# If the user is also part of workspace directly add him to project
|
||||||
|
if WorkspaceMember.objects.filter(
|
||||||
|
project_id=project_id,
|
||||||
|
member__email=email,
|
||||||
|
member__is_bot=False,
|
||||||
|
member__is_deactivated=False,
|
||||||
|
).exists():
|
||||||
|
# Check if user is already a member of project
|
||||||
if ProjectMember.objects.filter(
|
if ProjectMember.objects.filter(
|
||||||
project_id=project_id,
|
project_id=project_id,
|
||||||
member__email=email,
|
member__email=email,
|
||||||
member__is_bot=False,
|
member__is_bot=False,
|
||||||
).exists():
|
).exists():
|
||||||
return Response(
|
return Response(
|
||||||
{"error": "User is already member of workspace"},
|
{"error": "User is already member of project"},
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
)
|
)
|
||||||
|
|
||||||
user = User.objects.filter(email=email).first()
|
# Add that user
|
||||||
|
user = User.objects.get(emai=email)
|
||||||
|
# Else create the user and return
|
||||||
|
project_member = ProjectMember.objects.create(
|
||||||
|
member=user, project_id=project_id, role=role
|
||||||
|
)
|
||||||
|
_ = IssueProperty.objects.create(user=user, project_id=project_id)
|
||||||
|
return Response(
|
||||||
|
ProjectMemberSerializer(project_member).data, status=status.HTTP_200_OK
|
||||||
|
)
|
||||||
|
|
||||||
if user is None:
|
# If the user doesn't exist
|
||||||
token = jwt.encode(
|
token = jwt.encode(
|
||||||
{"email": email, "timestamp": datetime.now().timestamp()},
|
{"email": email, "timestamp": datetime.now().timestamp()},
|
||||||
settings.SECRET_KEY,
|
settings.SECRET_KEY,
|
||||||
@ -397,15 +414,6 @@ class InviteProjectEndpoint(BaseAPIView):
|
|||||||
status=status.HTTP_200_OK,
|
status=status.HTTP_200_OK,
|
||||||
)
|
)
|
||||||
|
|
||||||
project_member = ProjectMember.objects.create(
|
|
||||||
member=user, project_id=project_id, role=role
|
|
||||||
)
|
|
||||||
|
|
||||||
_ = IssueProperty.objects.create(user=user, project_id=project_id)
|
|
||||||
|
|
||||||
return Response(
|
|
||||||
ProjectMemberSerializer(project_member).data, status=status.HTTP_200_OK
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class UserProjectInvitationsViewset(BaseViewSet):
|
class UserProjectInvitationsViewset(BaseViewSet):
|
||||||
|
Loading…
Reference in New Issue
Block a user