Support activating/reinstating customer account from CRM
All checks were successful
Deploy Beta (NATIVE) / deploy (push) Successful in 21s

This commit is contained in:
vickytechkey 2026-08-16 11:24:43 +05:30
parent 28044398dd
commit 6ccacf7ad3

View file

@ -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])