Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Update backend_structured/routes.py
Browse files- backend_structured/routes.py +16 -2
backend_structured/routes.py
CHANGED
|
@@ -1490,10 +1490,24 @@ def create_scan(current_user):
|
|
| 1490 |
if not is_valid_target_url(target_url):
|
| 1491 |
return jsonify({"message": "Invalid target URL. Please enter a valid public domain or IP address."}), 400
|
| 1492 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1493 |
try:
|
| 1494 |
new_scan = Scan(
|
| 1495 |
user_id=current_user.id,
|
| 1496 |
-
org_id=
|
| 1497 |
target_url=target_url,
|
| 1498 |
scan_type=scan_type,
|
| 1499 |
status="queued",
|
|
@@ -1506,7 +1520,7 @@ def create_scan(current_user):
|
|
| 1506 |
if quota and not is_unlimited:
|
| 1507 |
quota.used_count += 1
|
| 1508 |
|
| 1509 |
-
log = AuditLog(admin_id=current_user.id, action=f"Initiated manual {scan_type} scan for {target_url}", target_id=
|
| 1510 |
db.session.add(log)
|
| 1511 |
|
| 1512 |
db.session.commit()
|
|
|
|
| 1490 |
if not is_valid_target_url(target_url):
|
| 1491 |
return jsonify({"message": "Invalid target URL. Please enter a valid public domain or IP address."}), 400
|
| 1492 |
|
| 1493 |
+
effective_org_id = current_user.org_id
|
| 1494 |
+
if not effective_org_id:
|
| 1495 |
+
first_org = Organization.query.first()
|
| 1496 |
+
if not first_org:
|
| 1497 |
+
first_org = Organization(name="Default System Tenant", subscription_tier="enterprise")
|
| 1498 |
+
db.session.add(first_org)
|
| 1499 |
+
db.session.commit()
|
| 1500 |
+
effective_org_id = first_org.id
|
| 1501 |
+
current_user.org_id = effective_org_id
|
| 1502 |
+
try:
|
| 1503 |
+
db.session.commit()
|
| 1504 |
+
except Exception:
|
| 1505 |
+
db.session.rollback()
|
| 1506 |
+
|
| 1507 |
try:
|
| 1508 |
new_scan = Scan(
|
| 1509 |
user_id=current_user.id,
|
| 1510 |
+
org_id=effective_org_id,
|
| 1511 |
target_url=target_url,
|
| 1512 |
scan_type=scan_type,
|
| 1513 |
status="queued",
|
|
|
|
| 1520 |
if quota and not is_unlimited:
|
| 1521 |
quota.used_count += 1
|
| 1522 |
|
| 1523 |
+
log = AuditLog(admin_id=current_user.id, action=f"Initiated manual {scan_type} scan for {target_url}", target_id=effective_org_id)
|
| 1524 |
db.session.add(log)
|
| 1525 |
|
| 1526 |
db.session.commit()
|