From 9721bd41d577c4ebe9e2e5067a10081f0a64919c Mon Sep 17 00:00:00 2001 From: Untone Date: Fri, 27 Aug 2021 11:42:01 +0300 Subject: [PATCH] wip: org to community --- orm/__init__.py | 2 +- orm/community.py | 2 +- orm/rbac.py | 2 +- resolvers/zine.py | 21 ++++++++------------- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/orm/__init__.py b/orm/__init__.py index b3b2de2a..2d0bbc53 100644 --- a/orm/__init__.py +++ b/orm/__init__.py @@ -1,4 +1,4 @@ -from orm.rbac import Organization, Operation, Resource, Permission, Role +from orm.rbac import Community, Operation, Resource, Permission, Role from orm.user import User from orm.message import Message from orm.topic import Topic diff --git a/orm/community.py b/orm/community.py index 25f27755..e95df8eb 100644 --- a/orm/community.py +++ b/orm/community.py @@ -11,7 +11,7 @@ class Community(Base): 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) + # 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") \ No newline at end of file diff --git a/orm/rbac.py b/orm/rbac.py index e205f233..e6094027 100644 --- a/orm/rbac.py +++ b/orm/rbac.py @@ -33,7 +33,7 @@ class Role(Base): # id is auto field name: str = Column(String, nullable=False, comment="Role Name") - desc: str = Colulm(String, nullable=True, comment="Role Description") + 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) diff --git a/resolvers/zine.py b/resolvers/zine.py index fd354c6a..f8f268d1 100644 --- a/resolvers/zine.py +++ b/resolvers/zine.py @@ -1,4 +1,4 @@ -from orm import Shout, User, Organization, Resource +from orm import Shout, User, Community, Resource from orm.base import local_session from resolvers.base import mutation, query @@ -18,7 +18,7 @@ class GitTask: def __init__(self, input, org, username, user_email, comment): self.slug = input["slug"]; self.shout_body = input["body"]; - self.org = org; + self.org = org; #FIXME self.username = username; self.user_email = user_email; self.comment = comment; @@ -84,19 +84,14 @@ async def create_shout(_, info, input): auth = info.context["request"].auth user_id = auth.user_id - org_id = org = input["org_id"] + # org_id = org = input["org_id"] with local_session() as session: user = session.query(User).filter(User.id == user_id).first() - org = session.query(Organization).filter(Organization.id == org_id).first() - - if not org: - return { - "error" : "invalid organization" - } - + # org = session.query(Organization).filter(Organization.id == org_id).first() + new_shout = Shout.create( slug = input["slug"], - org_id = org_id, + # org_id = org_id, authors = [user_id, ], body = input["body"], replyTo = input.get("replyTo"), @@ -124,11 +119,11 @@ async def update_shout(_, info, input): user_id = auth.user_id slug = input["slug"] - org_id = org = input["org_id"] + # org_id = org = input["org_id"] with local_session() as session: user = session.query(User).filter(User.id == user_id).first() shout = session.query(Shout).filter(Shout.slug == slug).first() - org = session.query(Organization).filter(Organization.id == org_id).first() + # org = session.query(Organization).filter(Organization.id == org_id).first() if not shout: return {