default user role; updateProfile method

This commit is contained in:
knst-kotov
2021-12-08 15:51:30 +03:00
parent 8092d8a262
commit 6e939f43db
9 changed files with 70 additions and 15 deletions

View File

@@ -7,6 +7,7 @@ from sqlalchemy import String, Integer, Column, ForeignKey, UniqueConstraint, Ty
from sqlalchemy.orm import relationship, selectinload
from orm.base import Base, REGISTRY, engine, local_session
from orm.community import Community
class ClassType(TypeDecorator):
@@ -31,13 +32,27 @@ class ClassType(TypeDecorator):
class Role(Base):
__tablename__ = 'role'
# id is auto field
name: str = Column(String, nullable=False, comment="Role Name")
desc: str = Column(String, nullable=True, comment="Role Description")
community: int = Column(ForeignKey("community.id", ondelete="CASCADE"), nullable=False, comment="Community")
permissions = relationship(lambda: Permission)
@staticmethod
def init_table():
with local_session() as session:
default = session.query(Role).filter(Role.name == "author").first()
if default:
Role.default_role = default
return
default = Role.create(
name = "author",
desc = "Role for author",
community = Community.default_community.id
)
Role.default_role = default
class Operation(Base):
__tablename__ = 'operation'
name: str = Column(String, nullable=False, unique=True, comment="Operation Name")