diff --git a/backup/backupManager.py b/backup/backupManager.py index f4ebe7f5d..c3a6e2c16 100755 --- a/backup/backupManager.py +++ b/backup/backupManager.py @@ -2341,10 +2341,9 @@ class BackupManager: def ReconfigureSubscription(self, request=None, userID=None, data=None): try: - userID = request.session['userID'] - admin = Administrator.objects.get(pk=userID) - - data = json.loads(request.body) + if not data: + return JsonResponse({'status': 0, 'error_message': 'No data provided'}) + subscription_id = data['subscription_id'] customer_id = data['customer_id'] plan_name = data['plan_name'] @@ -2372,13 +2371,13 @@ class BackupManager: # Create OneClickBackups record from IncBackups.models import OneClickBackups backup_plan = OneClickBackups( - owner=admin, + owner=Administrator.objects.get(pk=userID), planName=plan_name, months='1' if interval == 'month' else '12', price=amount, customer=customer_id, subscription=subscription_id, - sftpUser=response_data.get('sftpUser'), # Get username from platform response + sftpUser=response_data.get('sftpUser'), state=1 # Set as active since SFTP is already configured ) backup_plan.save() @@ -2388,10 +2387,10 @@ class BackupManager: 'IPAddress': response_data.get('ipAddress'), 'password': 'NOT-NEEDED', 'backupSSHPort': '22', - 'userName': response_data.get('sftpUser'), # Use username from platform + 'userName': response_data.get('sftpUser'), 'type': 'SFTP', 'path': 'cpbackups', - 'name': response_data.get('sftpUser') # Use username from platform + 'name': response_data.get('sftpUser') } wm = BackupManager() @@ -2407,7 +2406,7 @@ class BackupManager: else: return JsonResponse({'status': 0, 'error_message': f'Platform API error: {response.text}'}) - except BaseException as msg: - return JsonResponse({'status': 0, 'error_message': str(msg)}) + except Exception as e: + return JsonResponse({'status': 0, 'error_message': str(e)}) diff --git a/backup/views.py b/backup/views.py index 6e7e30eb1..284e72540 100755 --- a/backup/views.py +++ b/backup/views.py @@ -548,7 +548,8 @@ def ReconfigureSubscription(request): userID = request.session['userID'] admin = Administrator.objects.get(pk=userID) bm = BackupManager() - return bm.ReconfigureSubscription(request, userID) + data = json.loads(request.body) + return bm.ReconfigureSubscription(request, userID, data) except BaseException as msg: data_ret = {'status': 0, 'error_message': str(msg)} json_data = json.dumps(data_ret)