Commit a73f7e89 authored by John Red Medrano's avatar John Red Medrano

Merge pull request #743 in RMS/api-main-service from core-dev-red-develop to RMSv2

* commit '715951e0':
  Correct Display for Deleting a User http://54.169.104.100:27015/rms/rms-backend/issues/6 replace raise parser error to response error to easily fetch by frontend
parents a58e13e0 715951e0
......@@ -146,6 +146,8 @@ class UserViewSet(viewsets.ModelViewSet):
@transaction.atomic
def destroy(self, request, *args, **kwargs):
try:
instance = self.get_object()
new_instance = model_to_dict(instance)
UserHistory.objects.filter(username=instance.username).update(deleted=True)
......@@ -162,6 +164,16 @@ class UserViewSet(viewsets.ModelViewSet):
return Response(status=status.HTTP_204_NO_CONTENT)
except IntegrityError as e:
error = f'Cant delete {instance.name} it has an existing transactions on either change request or change request template'
message = {
'code': 400,
'status': 'failed',
'message': error,
}
return Response(message,
status=status.HTTP_400_BAD_REQUEST)
@rms.user_create
@transaction.atomic
def update(self, request, *args, **kwargs):
......@@ -185,9 +197,18 @@ class UserViewSet(viewsets.ModelViewSet):
if cms_form.count() > 0 or cms_template.count() > 0:
raise ParseError(
'Cannot update this record the user has a record on change request it might cause a data error'
)
# raise ParseError(
# 'Cannot update this record the user has a record on change request it might cause a data error'
# )
error = 'Cannot update this record the user has a record on change request it might cause a data error'
message = {
'code': 400,
'status': 'failed',
'message': error,
}
return Response(message,
status=status.HTTP_400_BAD_REQUEST)
serializer = self.get_serializer(
instance, data=request.data, partial=partial
......@@ -272,7 +293,15 @@ class UserViewSet(viewsets.ModelViewSet):
else:
raise Exception('User not found')
# raise Exception('User not found')
error = 'User not found'
message = {
'code': 400,
'status': 'failed',
'message': error,
}
return Response(message,
status=status.HTTP_400_BAD_REQUEST)
return Response(
{"detail": "Success"},
......@@ -296,7 +325,16 @@ class UserViewSet(viewsets.ModelViewSet):
form = request.data
if form['new_password'] != form['new_password_confirm']:
raise Exception('Passwords must match')
# raise Exception('Passwords must match')
error = 'Passwords must match'
message = {
'code': 400,
'status': 'failed',
'message': error,
}
return Response(message,
status=status.HTTP_400_BAD_REQUEST)
existingUser = User.objects.filter(code=code)
pk = existingUser.values().first()['id']
......@@ -322,7 +360,15 @@ class UserViewSet(viewsets.ModelViewSet):
status=status.HTTP_200_OK
)
else:
raise Exception('User not found')
# raise Exception('User not found')
error = 'User not found'
message = {
'code': 400,
'status': 'failed',
'message': error,
}
return Response(message,
status=status.HTTP_400_BAD_REQUEST)
else:
serialized.is_valid(raise_exception=True)
......@@ -373,7 +419,15 @@ class UserViewSet(viewsets.ModelViewSet):
status=status.HTTP_200_OK
)
else:
raise Exception('User not found')
# raise Exception('User not found')
error = 'User not found'
message = {
'code': 400,
'status': 'failed',
'message': error,
}
return Response(message,
status=status.HTTP_400_BAD_REQUEST)
else:
serialized.is_valid(raise_exception=True)
......@@ -412,5 +466,13 @@ class UserViewSet(viewsets.ModelViewSet):
status=status.HTTP_201_CREATED,
headers=headers)
else:
raise ParseError('User not found')
# raise ParseError('User not found')
error = 'User not found'
message = {
'code': 400,
'status': 'failed',
'message': error,
}
return Response(message,
status=status.HTTP_400_BAD_REQUEST)
return Response(data={"detail": "Success"})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment