forked from github/plane
dev: project invite workflow
This commit is contained in:
parent
34bccd7e06
commit
112c418047
@ -361,53 +361,61 @@ class InviteProjectEndpoint(BaseAPIView):
|
|||||||
)
|
)
|
||||||
|
|
||||||
validate_email(email)
|
validate_email(email)
|
||||||
# Check if user is already a member of workspace
|
|
||||||
if ProjectMember.objects.filter(
|
# If the user is also part of workspace directly add him to project
|
||||||
|
if WorkspaceMember.objects.filter(
|
||||||
project_id=project_id,
|
project_id=project_id,
|
||||||
member__email=email,
|
member__email=email,
|
||||||
member__is_bot=False,
|
member__is_bot=False,
|
||||||
|
member__is_deactivated=False,
|
||||||
).exists():
|
).exists():
|
||||||
return Response(
|
# Check if user is already a member of project
|
||||||
{"error": "User is already member of workspace"},
|
if ProjectMember.objects.filter(
|
||||||
status=status.HTTP_400_BAD_REQUEST,
|
|
||||||
)
|
|
||||||
|
|
||||||
user = User.objects.filter(email=email).first()
|
|
||||||
|
|
||||||
if user is None:
|
|
||||||
token = jwt.encode(
|
|
||||||
{"email": email, "timestamp": datetime.now().timestamp()},
|
|
||||||
settings.SECRET_KEY,
|
|
||||||
algorithm="HS256",
|
|
||||||
)
|
|
||||||
project_invitation_obj = ProjectMemberInvite.objects.create(
|
|
||||||
email=email.strip().lower(),
|
|
||||||
project_id=project_id,
|
project_id=project_id,
|
||||||
token=token,
|
member__email=email,
|
||||||
role=role,
|
member__is_bot=False,
|
||||||
)
|
).exists():
|
||||||
domain = settings.WEB_URL
|
return Response(
|
||||||
project_invitation.delay(email, project_id, token, domain)
|
{"error": "User is already member of project"},
|
||||||
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
|
)
|
||||||
|
|
||||||
|
# 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(
|
return Response(
|
||||||
{
|
ProjectMemberSerializer(project_member).data, status=status.HTTP_200_OK
|
||||||
"message": "Email sent successfully",
|
|
||||||
"id": project_invitation_obj.id,
|
|
||||||
},
|
|
||||||
status=status.HTTP_200_OK,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
project_member = ProjectMember.objects.create(
|
# If the user doesn't exist
|
||||||
member=user, project_id=project_id, role=role
|
token = jwt.encode(
|
||||||
|
{"email": email, "timestamp": datetime.now().timestamp()},
|
||||||
|
settings.SECRET_KEY,
|
||||||
|
algorithm="HS256",
|
||||||
)
|
)
|
||||||
|
project_invitation_obj = ProjectMemberInvite.objects.create(
|
||||||
_ = IssueProperty.objects.create(user=user, project_id=project_id)
|
email=email.strip().lower(),
|
||||||
|
project_id=project_id,
|
||||||
|
token=token,
|
||||||
|
role=role,
|
||||||
|
)
|
||||||
|
domain = settings.WEB_URL
|
||||||
|
project_invitation.delay(email, project_id, token, domain)
|
||||||
|
|
||||||
return Response(
|
return Response(
|
||||||
ProjectMemberSerializer(project_member).data, status=status.HTTP_200_OK
|
{
|
||||||
|
"message": "Email sent successfully",
|
||||||
|
"id": project_invitation_obj.id,
|
||||||
|
},
|
||||||
|
status=status.HTTP_200_OK,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class UserProjectInvitationsViewset(BaseViewSet):
|
class UserProjectInvitationsViewset(BaseViewSet):
|
||||||
serializer_class = ProjectMemberInviteSerializer
|
serializer_class = ProjectMemberInviteSerializer
|
||||||
model = ProjectMemberInvite
|
model = ProjectMemberInvite
|
||||||
|
Loading…
Reference in New Issue
Block a user