Support activating/reinstating customer account from CRM
All checks were successful
Deploy Beta (NATIVE) / deploy (push) Successful in 21s
All checks were successful
Deploy Beta (NATIVE) / deploy (push) Successful in 21s
This commit is contained in:
parent
28044398dd
commit
6ccacf7ad3
1 changed files with 10 additions and 4 deletions
|
|
@ -53,16 +53,22 @@ def suspend_customer(request, pk):
|
|||
except CustomerProfile.DoesNotExist:
|
||||
return Response({"detail": "Customer not found"}, status=404)
|
||||
|
||||
# Update is_active to False in customerwebsite database to block logins
|
||||
# If status payload is active, reinstate the customer account
|
||||
target_status = request.data.get('status', 'suspended')
|
||||
is_active_val = True if target_status == 'active' else False
|
||||
action_name = 'reinstate_customer' if is_active_val else 'suspend_customer'
|
||||
message_val = 'Customer account reinstated' if is_active_val else 'Customer account suspended'
|
||||
|
||||
# Update is_active in customerwebsite database to enable/disable logins
|
||||
from django.db import connections
|
||||
try:
|
||||
with connections['customer_db'].cursor() as cursor:
|
||||
cursor.execute("UPDATE auth_user SET is_active = False WHERE id = %s", [customer.user_id])
|
||||
cursor.execute("UPDATE auth_user SET is_active = %s WHERE id = %s", [is_active_val, customer.user_id])
|
||||
except Exception as e:
|
||||
return Response({"detail": f"Database update failed: {str(e)}"}, status=500)
|
||||
|
||||
log_customer_action(request.user, 'suspend_customer', customer.id, {"reason": request.data.get('reason')})
|
||||
return Response({"message": "Customer account suspended"})
|
||||
log_customer_action(request.user, action_name, customer.id, {"reason": request.data.get('reason')})
|
||||
return Response({"message": message_val})
|
||||
|
||||
@api_view(['POST'])
|
||||
@permission_classes([IsCRMAdmin])
|
||||
|
|
|
|||
Loading…
Reference in a new issue