41 lines
1.6 KiB
Python
41 lines
1.6 KiB
Python
from sqlalchemy import Column, Integer, String, Boolean, ForeignKey, DateTime
|
|
from sqlalchemy.orm import relationship
|
|
from datetime import datetime
|
|
from .database import Base
|
|
|
|
class User(Base):
|
|
__tablename__ = "users"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
username = Column(String, unique=True, index=True)
|
|
email = Column(String, unique=True, index=True)
|
|
hashed_password = Column(String)
|
|
is_active = Column(Boolean, default=True)
|
|
is_admin = Column(Boolean, default=False)
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
|
|
|
applications = relationship("UserApplication", back_populates="user")
|
|
|
|
class Application(Base):
|
|
__tablename__ = "applications"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
name = Column(String, unique=True, index=True)
|
|
api_key = Column(String, unique=True, index=True) # Secret key for the app to talk to SSO
|
|
url = Column(String)
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
|
|
users = relationship("UserApplication", back_populates="application")
|
|
|
|
class UserApplication(Base):
|
|
__tablename__ = "user_applications"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
user_id = Column(Integer, ForeignKey("users.id"))
|
|
application_id = Column(Integer, ForeignKey("applications.id"))
|
|
assigned_at = Column(DateTime, default=datetime.utcnow)
|
|
|
|
user = relationship("User", back_populates="applications")
|
|
application = relationship("Application", back_populates="users")
|