2021-06-28 09:08:09 +00:00
|
|
|
from typing import List
|
|
|
|
|
2021-07-29 19:42:45 +00:00
|
|
|
from sqlalchemy import Column, Integer, String, ForeignKey #, relationship
|
2021-06-28 09:08:09 +00:00
|
|
|
|
|
|
|
from orm import Permission
|
|
|
|
from orm.base import Base
|
|
|
|
|
|
|
|
|
|
|
|
class User(Base):
|
|
|
|
__tablename__ = 'user'
|
|
|
|
|
2021-06-29 10:26:46 +00:00
|
|
|
email: str = Column(String, nullable=False)
|
2021-07-30 07:18:04 +00:00
|
|
|
username: str = Column(String, nullable=False, comment="Name")
|
2021-07-09 07:14:16 +00:00
|
|
|
password: str = Column(String, nullable=True, comment="Password")
|
2021-06-29 10:26:46 +00:00
|
|
|
|
2021-07-29 19:39:41 +00:00
|
|
|
role_id: list = Column(ForeignKey("role.id"), nullable=True, comment="Role")
|
2021-07-29 17:26:15 +00:00
|
|
|
# roles = relationship("Role") TODO: one to many, see schema.graphql
|
2021-07-09 07:14:16 +00:00
|
|
|
oauth_id: str = Column(String, nullable=True)
|
2021-06-28 09:08:09 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def get_permission(cls, user_id):
|
|
|
|
perms: List[Permission] = cls.session.query(Permission).join(User, User.role_id == Permission.role_id).filter(
|
|
|
|
User.id == user_id).all()
|
|
|
|
return {f"{p.operation_id}-{p.resource_id}" for p in perms}
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
print(User.get_permission(user_id=1))
|