Spaces:
Running
Running
axeronis commited on
Commit Β·
a78d47f
1
Parent(s): c56f47b
fix: Register Order models in init and add admin grant script
Browse files- backend/app/models/__init__.py +6 -0
- backend/grant_admin.py +59 -0
backend/app/models/__init__.py
CHANGED
|
@@ -17,6 +17,7 @@ from app.models.notification import Notification, NotificationSettings
|
|
| 17 |
from app.models.booking import Service, Availability, Appointment, AppointmentStatus
|
| 18 |
from app.models.ai_training import AIFeedback, AITrainingExample, AILearningRule, FeedbackType, TrainingStatus
|
| 19 |
from app.models.crm_integration import CRMIntegration, CRMSyncLog, CRMFieldMapping, LeadCRMLink, CRMType, SyncDirection, SyncStatus
|
|
|
|
| 20 |
|
| 21 |
__all__ = [
|
| 22 |
# Tenant
|
|
@@ -52,6 +53,11 @@ __all__ = [
|
|
| 52 |
# Products
|
| 53 |
"Product",
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
# Booking
|
| 56 |
"Service",
|
| 57 |
"Availability",
|
|
|
|
| 17 |
from app.models.booking import Service, Availability, Appointment, AppointmentStatus
|
| 18 |
from app.models.ai_training import AIFeedback, AITrainingExample, AILearningRule, FeedbackType, TrainingStatus
|
| 19 |
from app.models.crm_integration import CRMIntegration, CRMSyncLog, CRMFieldMapping, LeadCRMLink, CRMType, SyncDirection, SyncStatus
|
| 20 |
+
from app.models.order import Order, OrderItem, OrderStatus
|
| 21 |
|
| 22 |
__all__ = [
|
| 23 |
# Tenant
|
|
|
|
| 53 |
# Products
|
| 54 |
"Product",
|
| 55 |
|
| 56 |
+
# Orders
|
| 57 |
+
"Order",
|
| 58 |
+
"OrderItem",
|
| 59 |
+
"OrderStatus",
|
| 60 |
+
|
| 61 |
# Booking
|
| 62 |
"Service",
|
| 63 |
"Availability",
|
backend/grant_admin.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
+
from sqlmodel import select
|
| 3 |
+
from app.core.database import async_session_maker
|
| 4 |
+
from app.models.user import User
|
| 5 |
+
from app.models.tenant import Tenant
|
| 6 |
+
|
| 7 |
+
TARGET_EMAIL = "axeroni.s2@gmail.com"
|
| 8 |
+
DEFAULT_PASSWORD = "ChangeMe123!"
|
| 9 |
+
|
| 10 |
+
async def grant_admin():
|
| 11 |
+
print(f"π Granting Admin Access to {TARGET_EMAIL}...")
|
| 12 |
+
|
| 13 |
+
async with async_session_maker() as session:
|
| 14 |
+
try:
|
| 15 |
+
# 1. Check if user exists
|
| 16 |
+
result = await session.execute(select(User).where(User.email == TARGET_EMAIL))
|
| 17 |
+
user = result.scalar_one_or_none()
|
| 18 |
+
|
| 19 |
+
if user:
|
| 20 |
+
print(f"β
User found: {user.id}")
|
| 21 |
+
user.is_superuser = True
|
| 22 |
+
user.role = "OWNER"
|
| 23 |
+
session.add(user)
|
| 24 |
+
await session.commit()
|
| 25 |
+
print("π User promoted to SUPERUSER!")
|
| 26 |
+
else:
|
| 27 |
+
print("β οΈ User not found. Creating new...")
|
| 28 |
+
|
| 29 |
+
# 2. Find a tenant to link to
|
| 30 |
+
t_result = await session.execute(select(Tenant))
|
| 31 |
+
tenant = t_result.scalars().first()
|
| 32 |
+
|
| 33 |
+
if not tenant:
|
| 34 |
+
print("β No Tenants found! Cannot create user without a tenant.")
|
| 35 |
+
return
|
| 36 |
+
|
| 37 |
+
print(f"π Linking to Tenant: {tenant.name} ({tenant.id})")
|
| 38 |
+
|
| 39 |
+
# 3. Create User
|
| 40 |
+
hashed = User.get_password_hash(DEFAULT_PASSWORD)
|
| 41 |
+
new_user = User(
|
| 42 |
+
email=TARGET_EMAIL,
|
| 43 |
+
hashed_password=hashed,
|
| 44 |
+
tenant_id=tenant.id,
|
| 45 |
+
role="OWNER",
|
| 46 |
+
is_superuser=True,
|
| 47 |
+
full_name="Admin User"
|
| 48 |
+
)
|
| 49 |
+
session.add(new_user)
|
| 50 |
+
await session.commit()
|
| 51 |
+
print(f"π Created new Admin User. Password: {DEFAULT_PASSWORD}")
|
| 52 |
+
|
| 53 |
+
except Exception as e:
|
| 54 |
+
print(f"β Error: {e}")
|
| 55 |
+
import traceback
|
| 56 |
+
traceback.print_exc()
|
| 57 |
+
|
| 58 |
+
if __name__ == "__main__":
|
| 59 |
+
asyncio.run(grant_admin())
|