dev: project invite workflow

This commit is contained in:
pablohashescobar 2023-11-09 18:28:12 +05:30
parent 34bccd7e06
commit 112c418047

View File

@ -361,20 +361,37 @@ class InviteProjectEndpoint(BaseAPIView):
)
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(
project_id=project_id,
member__email=email,
member__is_bot=False,
).exists():
return Response(
{"error": "User is already member of workspace"},
{"error": "User is already member of project"},
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(
{"email": email, "timestamp": datetime.now().timestamp()},
settings.SECRET_KEY,
@ -397,15 +414,6 @@ class InviteProjectEndpoint(BaseAPIView):
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):