restructured,inbox-removed
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from base.orm import Base, engine
|
||||
from services.db import Base, engine
|
||||
from orm.community import Community
|
||||
from orm.notification import Notification
|
||||
from orm.rbac import Operation, Resource, Permission, Role
|
||||
|
@@ -2,7 +2,7 @@ from datetime import datetime
|
||||
|
||||
from sqlalchemy import Column, DateTime, ForeignKey, String
|
||||
|
||||
from base.orm import Base
|
||||
from services.db import Base
|
||||
|
||||
|
||||
class ShoutCollection(Base):
|
||||
|
@@ -1,7 +1,7 @@
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import Column, String, ForeignKey, DateTime
|
||||
from base.orm import Base, local_session
|
||||
from services.db import Base, local_session
|
||||
|
||||
|
||||
class CommunityFollower(Base):
|
||||
@@ -30,12 +30,10 @@ class Community(Base):
|
||||
@staticmethod
|
||||
def init_table():
|
||||
with local_session() as session:
|
||||
d = (
|
||||
session.query(Community).filter(Community.slug == "discours").first()
|
||||
)
|
||||
d = session.query(Community).filter(Community.slug == "discours").first()
|
||||
if not d:
|
||||
d = Community.create(name="Дискурс", slug="discours")
|
||||
session.add(d)
|
||||
session.commit()
|
||||
Community.default_community = d
|
||||
print('[orm] default community id: %s' % d.id)
|
||||
print("[orm] default community id: %s" % d.id)
|
||||
|
@@ -1,6 +1,6 @@
|
||||
from datetime import datetime
|
||||
from sqlalchemy import Column, String, JSON, ForeignKey, DateTime, Boolean
|
||||
from base.orm import Base
|
||||
from services.db import Base
|
||||
|
||||
|
||||
class Notification(Base):
|
||||
|
13
orm/rbac.py
13
orm/rbac.py
@@ -3,7 +3,7 @@ import warnings
|
||||
from sqlalchemy import String, Column, ForeignKey, UniqueConstraint, TypeDecorator
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
from base.orm import Base, REGISTRY, engine, local_session
|
||||
from services.db import Base, REGISTRY, engine, local_session
|
||||
|
||||
# Role Based Access Control #
|
||||
|
||||
@@ -130,7 +130,16 @@ class Resource(Base):
|
||||
@staticmethod
|
||||
def init_table():
|
||||
with local_session() as session:
|
||||
for res in ["shout", "topic", "reaction", "chat", "message", "invite", "community", "user"]:
|
||||
for res in [
|
||||
"shout",
|
||||
"topic",
|
||||
"reaction",
|
||||
"chat",
|
||||
"message",
|
||||
"invite",
|
||||
"community",
|
||||
"user",
|
||||
]:
|
||||
r = session.query(Resource).filter(Resource.name == res).first()
|
||||
if not r:
|
||||
r = Resource.create(name=res, resourceClass=res)
|
||||
|
@@ -3,7 +3,7 @@ from enum import Enum as Enumeration
|
||||
|
||||
from sqlalchemy import Column, DateTime, Enum, ForeignKey, String
|
||||
|
||||
from base.orm import Base
|
||||
from services.db import Base
|
||||
|
||||
|
||||
class ReactionKind(Enumeration):
|
||||
@@ -30,11 +30,17 @@ class Reaction(Base):
|
||||
createdAt = Column(
|
||||
DateTime, nullable=False, default=datetime.now, comment="Created at"
|
||||
)
|
||||
createdBy = Column(ForeignKey("user.id"), nullable=False, index=True, comment="Sender")
|
||||
createdBy = Column(
|
||||
ForeignKey("user.id"), nullable=False, index=True, comment="Sender"
|
||||
)
|
||||
updatedAt = Column(DateTime, nullable=True, comment="Updated at")
|
||||
updatedBy = Column(ForeignKey("user.id"), nullable=True, index=True, comment="Last Editor")
|
||||
updatedBy = Column(
|
||||
ForeignKey("user.id"), nullable=True, index=True, comment="Last Editor"
|
||||
)
|
||||
deletedAt = Column(DateTime, nullable=True, comment="Deleted at")
|
||||
deletedBy = Column(ForeignKey("user.id"), nullable=True, index=True, comment="Deleted by")
|
||||
deletedBy = Column(
|
||||
ForeignKey("user.id"), nullable=True, index=True, comment="Deleted by"
|
||||
)
|
||||
shout = Column(ForeignKey("shout.id"), nullable=False, index=True)
|
||||
replyTo = Column(
|
||||
ForeignKey("reaction.id"), nullable=True, comment="Reply to reaction ID"
|
||||
|
10
orm/shout.py
10
orm/shout.py
@@ -3,7 +3,7 @@ from datetime import datetime
|
||||
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer, String, JSON
|
||||
from sqlalchemy.orm import column_property, relationship
|
||||
|
||||
from base.orm import Base, local_session
|
||||
from services.db import Base, local_session
|
||||
from orm.reaction import Reaction
|
||||
from orm.topic import Topic
|
||||
from orm.user import User
|
||||
@@ -43,7 +43,9 @@ class Shout(Base):
|
||||
__tablename__ = "shout"
|
||||
|
||||
# timestamps
|
||||
createdAt = Column(DateTime, nullable=False, default=datetime.now, comment="Created at")
|
||||
createdAt = Column(
|
||||
DateTime, nullable=False, default=datetime.now, comment="Created at"
|
||||
)
|
||||
updatedAt = Column(DateTime, nullable=True, comment="Updated at")
|
||||
publishedAt = Column(DateTime, nullable=True)
|
||||
deletedAt = Column(DateTime, nullable=True)
|
||||
@@ -72,7 +74,7 @@ class Shout(Base):
|
||||
|
||||
# TODO: these field should be used or modified
|
||||
community = Column(ForeignKey("community.id"), default=1)
|
||||
lang = Column(String, nullable=False, default='ru', comment="Language")
|
||||
lang = Column(String, nullable=False, default="ru", comment="Language")
|
||||
mainTopic = Column(ForeignKey("topic.slug"), nullable=True)
|
||||
visibility = Column(String, nullable=True) # owner authors community public
|
||||
versionOf = Column(ForeignKey("shout.id"), nullable=True)
|
||||
@@ -87,7 +89,7 @@ class Shout(Base):
|
||||
"slug": "genesis-block",
|
||||
"body": "",
|
||||
"title": "Ничего",
|
||||
"lang": "ru"
|
||||
"lang": "ru",
|
||||
}
|
||||
s = Shout.create(**entry)
|
||||
session.add(s)
|
||||
|
@@ -2,7 +2,7 @@ from datetime import datetime
|
||||
|
||||
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, String
|
||||
|
||||
from base.orm import Base
|
||||
from services.db import Base
|
||||
|
||||
|
||||
class TopicFollower(Base):
|
||||
@@ -24,7 +24,5 @@ class Topic(Base):
|
||||
title = Column(String, nullable=False, comment="Title")
|
||||
body = Column(String, nullable=True, comment="Body")
|
||||
pic = Column(String, nullable=True, comment="Picture")
|
||||
community = Column(
|
||||
ForeignKey("community.id"), default=1, comment="Community"
|
||||
)
|
||||
community = Column(ForeignKey("community.id"), default=1, comment="Community")
|
||||
oid = Column(String, nullable=True, comment="Old ID")
|
||||
|
@@ -3,7 +3,7 @@ from datetime import datetime
|
||||
from sqlalchemy import JSON as JSONType
|
||||
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer, String
|
||||
from sqlalchemy.orm import relationship
|
||||
from base.orm import Base, local_session
|
||||
from services.db import Base, local_session
|
||||
from orm.rbac import Role
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user