larxius commited on
Commit
725ca89
·
verified ·
1 Parent(s): 335a9ba

Update backend/__init__.py

Browse files
Files changed (1) hide show
  1. backend/__init__.py +14 -6
backend/__init__.py CHANGED
@@ -43,21 +43,15 @@ def create_app():
43
  with app.app_context():
44
  # Import routes to register blueprints
45
  from .routes import api_bp, auth_bp, scans_bp, vuln_bp, reports_bp
46
- from .billing import billing_bp, ensure_billing_schema, seed_billing_tiers
47
  app.register_blueprint(api_bp)
48
  app.register_blueprint(auth_bp, url_prefix='/api/auth')
49
  app.register_blueprint(scans_bp, url_prefix='/api/scans')
50
  app.register_blueprint(vuln_bp, url_prefix='/api/vulnerabilities')
51
  app.register_blueprint(reports_bp, url_prefix='/api/reports')
52
- app.register_blueprint(billing_bp, url_prefix='/api/billing')
53
 
54
  # Create tables
55
  db.create_all()
56
 
57
- # Billing migrations + plan seed (Razorpay pricing)
58
- ensure_billing_schema()
59
- seed_billing_tiers()
60
-
61
  # Seed superadmin user (created once, never overwritten)
62
  from .models import User
63
  import os
@@ -67,6 +61,20 @@ def create_app():
67
  db.session.add(sa)
68
  db.session.commit()
69
  print("[System] Superadmin user seeded (superadmin@gmail.com)")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
 
71
  # Cleanup stale scans that were truly abandoned/interrupted (> 10 mins old)
72
  from .models import Scan
 
43
  with app.app_context():
44
  # Import routes to register blueprints
45
  from .routes import api_bp, auth_bp, scans_bp, vuln_bp, reports_bp
 
46
  app.register_blueprint(api_bp)
47
  app.register_blueprint(auth_bp, url_prefix='/api/auth')
48
  app.register_blueprint(scans_bp, url_prefix='/api/scans')
49
  app.register_blueprint(vuln_bp, url_prefix='/api/vulnerabilities')
50
  app.register_blueprint(reports_bp, url_prefix='/api/reports')
 
51
 
52
  # Create tables
53
  db.create_all()
54
 
 
 
 
 
55
  # Seed superadmin user (created once, never overwritten)
56
  from .models import User
57
  import os
 
61
  db.session.add(sa)
62
  db.session.commit()
63
  print("[System] Superadmin user seeded (superadmin@gmail.com)")
64
+
65
+ # Ensure all org_admins have an organization
66
+ from .models import Organization
67
+ import uuid
68
+ orphan_admins = User.query.filter_by(role='org_admin').all()
69
+ for oa in orphan_admins:
70
+ if not oa.org_id or not db.session.get(Organization, oa.org_id):
71
+ org_name = (oa.email.split('@')[0].capitalize() if oa.email else 'LarShield') + ' Organization'
72
+ new_org = Organization(id=str(uuid.uuid4()), name=org_name)
73
+ db.session.add(new_org)
74
+ db.session.flush()
75
+ oa.org_id = new_org.id
76
+ print(f"[System] Auto-assigned organization '{org_name}' to org_admin {oa.email}")
77
+ db.session.commit()
78
 
79
  # Cleanup stale scans that were truly abandoned/interrupted (> 10 mins old)
80
  from .models import Scan