model upgrade
This commit is contained in:
42
orm/user.py
42
orm/user.py
@@ -1,27 +1,35 @@
|
||||
from typing import List
|
||||
|
||||
from sqlalchemy import Column, Integer, String, ForeignKey, Boolean, DateTime, JSON as JSONType
|
||||
from sqlalchemy import Table, Column, Integer, String, ForeignKey, Boolean, DateTime, JSON as JSONType
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from orm import Permission
|
||||
from orm.base import Base, local_session
|
||||
from orm.notification import UserNotification
|
||||
from orm.rating import Rating
|
||||
from orm.rbac import Role
|
||||
|
||||
class UserRating(Base):
|
||||
__tablename__ = 'user_rating'
|
||||
class UserNotifications(Base):
|
||||
__tablename__ = 'user_notifications'
|
||||
|
||||
createdBy: int = Column(Integer, ForeignKey("user.id"), primary_key = True)
|
||||
value: int = Column(Integer, nullable=False)
|
||||
|
||||
class UserRole(Base):
|
||||
__tablename__ = 'user_role'
|
||||
|
||||
id: int = Column(Integer, primary_key = True)
|
||||
user_id: int = Column(Integer, ForeignKey("user.id"))
|
||||
role_id str = Column(String, ForeignKey("role.name"))
|
||||
kind: str = Column(String, ForeignKey("notification.kind"))
|
||||
values: JSONType = Column(JSONType, nullable = True) # [ <var1>, .. ]
|
||||
|
||||
UserRatings = Table("user_ratings",
|
||||
Base.metadata,
|
||||
Column('user_id', Integer, ForeignKey('user.id')),
|
||||
Column('rater_id', Integer, ForeignKey('rating.createdBy'))
|
||||
)
|
||||
|
||||
UserRoles = Table("user_roles",
|
||||
Base.metadata,
|
||||
Column('user_id', Integer, ForeignKey('user.id')),
|
||||
Column('role', String, ForeignKey('role.name'))
|
||||
)
|
||||
|
||||
class User(Base):
|
||||
__tablename__ = 'user'
|
||||
__tablename__ = "user"
|
||||
|
||||
email: str = Column(String, unique=True, nullable=False, comment="Email")
|
||||
username: str = Column(String, nullable=False, comment="Login")
|
||||
@@ -30,16 +38,16 @@ class User(Base):
|
||||
userpic: str = Column(String, nullable=True, comment="Userpic")
|
||||
viewname: str = Column(String, nullable=True, comment="Display name")
|
||||
rating: int = Column(Integer, nullable=True, comment="Rating")
|
||||
slug: str = Column(String, unique=True, nullable=True, comment="Slug")
|
||||
slug: str = Column(String, unique=True, comment="Author's slug")
|
||||
muted: bool = Column(Boolean, default=False)
|
||||
emailConfirmed: bool = Column(Boolean, default=False)
|
||||
createdAt: DateTime = Column(DateTime, nullable=False, comment="Created at")
|
||||
wasOnlineAt: DateTime = Column(DateTime, nullable=False, comment="Was online at")
|
||||
links: JSONType = Column(JSONType, nullable=True, comment="Links")
|
||||
oauth: str = Column(String, nullable=True)
|
||||
notifications = relationship(lambda: UserNotification)
|
||||
ratings = relationship(lambda: UserRating)
|
||||
roles = relationship(lambda: UserRole)
|
||||
notifications = relationship(lambda: UserNotifications)
|
||||
ratings = relationship(lambda: Rating, secondary=UserRatings)
|
||||
roles = relationship(lambda: Role, secondary=UserRoles)
|
||||
|
||||
@classmethod
|
||||
def get_permission(cls, user_id):
|
||||
@@ -54,5 +62,5 @@ class User(Base):
|
||||
return scope
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
print(User.get_permission(user_id=1))
|
||||
|
Reference in New Issue
Block a user