community added, like removed
This commit is contained in:
17
orm/community.py
Normal file
17
orm/community.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from datetime import datetime
|
||||
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime
|
||||
from sqlalchemy.orm import relationship, backref
|
||||
from orm.base import Base
|
||||
|
||||
|
||||
class Community(Base):
|
||||
__tablename__ = 'community'
|
||||
# id is auto number
|
||||
name: str = Column(String, nullable=False, comment="Name")
|
||||
slug: str = Column(String, unique = True, nullable = False)
|
||||
desc: str = Column(String, nullable=False, default='')
|
||||
pic: str = Column(String, nullable=False, default='')
|
||||
org_id: str = Column(ForeignKey("organization.id"), nullable=True)
|
||||
createdAt: str = Column(DateTime, nullable=False, default = datetime.now, comment="Created at")
|
||||
createdBy: str = Column(ForeignKey("user.id"), nullable=False, comment="Creator")
|
||||
|
17
orm/like.py
17
orm/like.py
@@ -1,17 +0,0 @@
|
||||
from typing import List
|
||||
|
||||
from sqlalchemy import Column, Integer, String, ForeignKey, Datetime
|
||||
|
||||
from orm import Permission
|
||||
from orm.base import Base
|
||||
|
||||
|
||||
class Like(Base):
|
||||
__tablename__ = 'like'
|
||||
|
||||
id: int = None
|
||||
user_id: str = Column(ForeignKey("user.id"), comment="Author", primary_key = True)
|
||||
shout_id: int = Column(Integer, ForeignKey("shout.id"), comment="Liked shout id", primary_key = True)
|
||||
value: int = Column(Integer, nullable=False, comment="Value")
|
||||
|
||||
# TODO: add resolvers, debug, etc.
|
12
orm/rbac.py
12
orm/rbac.py
@@ -27,18 +27,14 @@ class ClassType(TypeDecorator):
|
||||
warnings.warn(f"Can't find class <{value}>,find it yourself!", stacklevel=2)
|
||||
return class_
|
||||
|
||||
class Organization(Base):
|
||||
__tablename__ = 'organization'
|
||||
name: str = Column(String, nullable=False, unique=True, comment="Organization Name")
|
||||
|
||||
class Role(Base):
|
||||
__tablename__ = 'role'
|
||||
|
||||
id: int = Column(Integer, primary_key=True)
|
||||
|
||||
# id is auto field
|
||||
|
||||
name: str = Column(String, nullable=False, comment="Role Name")
|
||||
org_id: int = Column(ForeignKey("organization.id", ondelete="CASCADE"), nullable=False, comment="Organization")
|
||||
|
||||
desc: str = Colulm(String, nullable=True, comment="Role Description")
|
||||
community: int = Column(ForeignKey("community.id", ondelete="CASCADE"), nullable=False, comment="Community")
|
||||
permissions = relationship(lambda: Permission)
|
||||
|
||||
class Operation(Base):
|
||||
|
@@ -31,7 +31,7 @@ class Shout(Base):
|
||||
# NOTE: automatic ID here
|
||||
|
||||
slug: str = Column(String, nullable=False, unique=True)
|
||||
org_id: int = Column(Integer, ForeignKey("organization.id"), nullable=False, comment="Organization")
|
||||
community: int = Column(Integer, ForeignKey("community.id"), nullable=True, comment="Community")
|
||||
body: str = Column(String, nullable=False, comment="Body")
|
||||
createdAt: str = Column(DateTime, nullable=False, default = datetime.now, comment="Created at")
|
||||
updatedAt: str = Column(DateTime, nullable=True, comment="Updated at")
|
||||
|
@@ -1,8 +1,6 @@
|
||||
from typing import List
|
||||
from datetime import datetime
|
||||
from sqlalchemy import Table, Column, Integer, String, ForeignKey, DateTime, UniqueConstraint
|
||||
from sqlalchemy.orm import relationship, backref
|
||||
from orm import Permission
|
||||
from sqlalchemy.orm import relationship
|
||||
from orm.base import Base
|
||||
|
||||
|
||||
@@ -18,7 +16,6 @@ class Topic(Base):
|
||||
__tablename__ = 'topic'
|
||||
|
||||
slug: str = Column(String, unique = True, nullable = False)
|
||||
org_id: str = Column(ForeignKey("organization.id"), nullable=False)
|
||||
createdAt: str = Column(DateTime, nullable=False, default = datetime.now, comment="Created at")
|
||||
createdBy: str = Column(ForeignKey("user.id"), nullable=False, comment="Author")
|
||||
value: str = Column(String, nullable=False, comment="Value")
|
||||
|
@@ -30,6 +30,12 @@ UserRoles = Table("user_roles",
|
||||
Column('role_id', Integer, ForeignKey('role.id'))
|
||||
)
|
||||
|
||||
UserTopics = Table("user_topics",
|
||||
Base.metadata,
|
||||
Column('user_id', Integer, ForeignKey('user.id')),
|
||||
Column('topic_id', Integer, ForeignKey('topic.id'))
|
||||
)
|
||||
|
||||
class User(Base):
|
||||
__tablename__ = "user"
|
||||
|
||||
@@ -50,6 +56,7 @@ class User(Base):
|
||||
notifications = relationship(lambda: UserNotifications)
|
||||
ratings = relationship(UserRatings, foreign_keys=UserRatings.user_id)
|
||||
roles = relationship(lambda: Role, secondary=UserRoles)
|
||||
topics = relationship(lambda: Topic, secondary=UserTopics)
|
||||
|
||||
@classmethod
|
||||
def get_permission(cls, user_id):
|
||||
|
Reference in New Issue
Block a user