-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_all_role_users.py
More file actions
83 lines (74 loc) · 2.99 KB
/
create_all_role_users.py
File metadata and controls
83 lines (74 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
"""
Create test users for all 3 admin roles
"""
import uuid
from sqlalchemy.orm import Session
from app.db import SessionLocal
from app.models.users.models import User, UserRole
from app.auth.password import hash_password
def create_all_role_users():
"""Create test users for all 3 admin roles"""
with SessionLocal() as db:
users_to_create = [
{
"email": "system-admin@example.com",
"password": "SystemAdmin123!",
"first_name": "System",
"last_name": "Admin",
"role": UserRole.SYSTEM_ADMIN.value,
"description": "System Admin Dashboard - manages tenants, plans, quotas, billing"
},
{
"email": "tenant-admin@example.com",
"password": "TenantAdmin123!",
"first_name": "Tenant",
"last_name": "Admin",
"role": UserRole.TENANT_ADMIN.value,
"description": "Tenant Admin Dashboard - bank/SME admins manage users, API keys, settings, usage"
},
{
"email": "tenant-user@example.com",
"password": "TenantUser123!",
"first_name": "Tenant",
"last_name": "User",
"role": UserRole.TENANT_USER.value,
"description": "Tenant User Dashboard - individual users run validations, view logs, docs, support"
}
]
created_users = []
for user_data in users_to_create:
# Check if user already exists
existing_user = db.query(User).filter(User.email == user_data["email"]).first()
if existing_user:
print(f"User already exists: {existing_user.email} (role: {existing_user.role})")
continue
# Create new user
new_user = User(
id=str(uuid.uuid4()),
email=user_data["email"],
password_hash=hash_password(user_data["password"]),
first_name=user_data["first_name"],
last_name=user_data["last_name"],
role=user_data["role"],
tenant_id="default",
is_active=True,
email_verified=True
)
db.add(new_user)
created_users.append(user_data)
if created_users:
db.commit()
print("Successfully created test users:")
for user_data in created_users:
print(f"✅ {user_data['email']} / {user_data['password']} (role: {user_data['role']})")
print(f" {user_data['description']}")
print()
else:
print("All test users already exist.")
# Show all current users
print("Current test users:")
all_users = db.query(User).filter(User.email.like('%example.com')).all()
for user in all_users:
print(f" {user.email} - {user.role}")
if __name__ == "__main__":
create_all_role_users()