Revert "Feature/lint"
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from base.orm import Base, engine
|
||||
from orm.community import Community
|
||||
from orm.notification import Notification
|
||||
from orm.rbac import Operation, Permission, Resource, Role
|
||||
from orm.rbac import Operation, Resource, Permission, Role
|
||||
from orm.reaction import Reaction
|
||||
from orm.shout import Shout
|
||||
from orm.topic import Topic, TopicFollower
|
||||
@@ -32,5 +32,5 @@ __all__ = [
|
||||
"Notification",
|
||||
"Reaction",
|
||||
"UserRating",
|
||||
"init_tables",
|
||||
"init_tables"
|
||||
]
|
||||
|
@@ -1,7 +1,9 @@
|
||||
from base.orm import Base
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import Column, DateTime, ForeignKey, String
|
||||
|
||||
from base.orm import Base
|
||||
|
||||
|
||||
class ShoutCollection(Base):
|
||||
__tablename__ = "shout_collection"
|
||||
|
@@ -1,6 +1,7 @@
|
||||
from base.orm import Base, local_session
|
||||
from datetime import datetime
|
||||
from sqlalchemy import Column, DateTime, ForeignKey, String
|
||||
|
||||
from sqlalchemy import Column, String, ForeignKey, DateTime
|
||||
from base.orm import Base, local_session
|
||||
|
||||
|
||||
class CommunityFollower(Base):
|
||||
@@ -9,7 +10,9 @@ class CommunityFollower(Base):
|
||||
id = None # type: ignore
|
||||
follower = Column(ForeignKey("user.id"), primary_key=True)
|
||||
community = Column(ForeignKey("community.id"), primary_key=True)
|
||||
joinedAt = Column(DateTime, nullable=False, default=datetime.now, comment="Created at")
|
||||
joinedAt = Column(
|
||||
DateTime, nullable=False, default=datetime.now, comment="Created at"
|
||||
)
|
||||
# role = Column(ForeignKey(Role.id), nullable=False, comment="Role for member")
|
||||
|
||||
|
||||
@@ -20,15 +23,19 @@ class Community(Base):
|
||||
slug = Column(String, nullable=False, unique=True, comment="Slug")
|
||||
desc = Column(String, nullable=False, default="")
|
||||
pic = Column(String, nullable=False, default="")
|
||||
createdAt = Column(DateTime, nullable=False, default=datetime.now, comment="Created at")
|
||||
createdAt = Column(
|
||||
DateTime, nullable=False, default=datetime.now, comment="Created at"
|
||||
)
|
||||
|
||||
@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,9 +1,10 @@
|
||||
from base.orm import Base
|
||||
from datetime import datetime
|
||||
from enum import Enum as Enumeration
|
||||
from sqlalchemy import Boolean, Column, DateTime, Enum, ForeignKey, Integer
|
||||
from sqlalchemy import Column, Enum, ForeignKey, DateTime, Boolean, Integer
|
||||
from sqlalchemy.dialects.postgresql import JSONB
|
||||
|
||||
from base.orm import Base
|
||||
from enum import Enum as Enumeration
|
||||
|
||||
|
||||
class NotificationType(Enumeration):
|
||||
NEW_COMMENT = 1
|
||||
|
48
orm/rbac.py
48
orm/rbac.py
@@ -1,8 +1,9 @@
|
||||
from base.orm import Base, local_session, REGISTRY
|
||||
from sqlalchemy import Column, ForeignKey, String, TypeDecorator, UniqueConstraint
|
||||
import warnings
|
||||
|
||||
from sqlalchemy import String, Column, ForeignKey, UniqueConstraint, TypeDecorator
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
import warnings
|
||||
from base.orm import Base, REGISTRY, engine, local_session
|
||||
|
||||
# Role Based Access Control #
|
||||
|
||||
@@ -120,23 +121,16 @@ class Operation(Base):
|
||||
|
||||
class Resource(Base):
|
||||
__tablename__ = "resource"
|
||||
resourceClass = Column(String, nullable=False, unique=True, comment="Resource class")
|
||||
resourceClass = Column(
|
||||
String, nullable=False, unique=True, comment="Resource class"
|
||||
)
|
||||
name = Column(String, nullable=False, unique=True, comment="Resource name")
|
||||
# TODO: community = Column(ForeignKey())
|
||||
|
||||
@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)
|
||||
@@ -151,7 +145,9 @@ class Permission(Base):
|
||||
{"extend_existing": True},
|
||||
)
|
||||
|
||||
role = Column(ForeignKey("role.id", ondelete="CASCADE"), nullable=False, comment="Role")
|
||||
role = Column(
|
||||
ForeignKey("role.id", ondelete="CASCADE"), nullable=False, comment="Role"
|
||||
)
|
||||
operation = Column(
|
||||
ForeignKey("operation.id", ondelete="CASCADE"),
|
||||
nullable=False,
|
||||
@@ -164,14 +160,14 @@ class Permission(Base):
|
||||
)
|
||||
|
||||
|
||||
# if __name__ == "__main__":
|
||||
# Base.metadata.create_all(engine)
|
||||
# ops = [
|
||||
# Permission(role=1, operation=1, resource=1),
|
||||
# Permission(role=1, operation=2, resource=1),
|
||||
# Permission(role=1, operation=3, resource=1),
|
||||
# Permission(role=1, operation=4, resource=1),
|
||||
# Permission(role=2, operation=4, resource=1),
|
||||
# ]
|
||||
# global_session.add_all(ops)
|
||||
# global_session.commit()
|
||||
if __name__ == "__main__":
|
||||
Base.metadata.create_all(engine)
|
||||
ops = [
|
||||
Permission(role=1, operation=1, resource=1),
|
||||
Permission(role=1, operation=2, resource=1),
|
||||
Permission(role=1, operation=3, resource=1),
|
||||
Permission(role=1, operation=4, resource=1),
|
||||
Permission(role=2, operation=4, resource=1),
|
||||
]
|
||||
global_session.add_all(ops)
|
||||
global_session.commit()
|
||||
|
@@ -1,8 +1,10 @@
|
||||
from base.orm import Base
|
||||
from datetime import datetime
|
||||
from enum import Enum as Enumeration
|
||||
|
||||
from sqlalchemy import Column, DateTime, Enum, ForeignKey, String
|
||||
|
||||
from base.orm import Base
|
||||
|
||||
|
||||
class ReactionKind(Enumeration):
|
||||
AGREE = 1 # +1
|
||||
@@ -25,14 +27,18 @@ class ReactionKind(Enumeration):
|
||||
class Reaction(Base):
|
||||
__tablename__ = "reaction"
|
||||
body = Column(String, nullable=True, comment="Reaction Body")
|
||||
createdAt = Column(DateTime, nullable=False, default=datetime.now, comment="Created at")
|
||||
createdAt = Column(
|
||||
DateTime, nullable=False, default=datetime.now, comment="Created at"
|
||||
)
|
||||
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")
|
||||
deletedAt = Column(DateTime, nullable=True, comment="Deleted at")
|
||||
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")
|
||||
replyTo = Column(
|
||||
ForeignKey("reaction.id"), nullable=True, comment="Reply to reaction ID"
|
||||
)
|
||||
range = Column(String, nullable=True, comment="Range in format <start index>:<end>")
|
||||
kind = Column(Enum(ReactionKind), nullable=False, comment="Reaction kind")
|
||||
oid = Column(String, nullable=True, comment="Old ID")
|
||||
|
16
orm/shout.py
16
orm/shout.py
@@ -1,10 +1,12 @@
|
||||
from base.orm import Base, local_session
|
||||
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 orm.reaction import Reaction
|
||||
from orm.topic import Topic
|
||||
from orm.user import User
|
||||
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer, JSON, String
|
||||
from sqlalchemy.orm import column_property, relationship
|
||||
|
||||
|
||||
class ShoutTopic(Base):
|
||||
@@ -22,7 +24,9 @@ class ShoutReactionsFollower(Base):
|
||||
follower = Column(ForeignKey("user.id"), primary_key=True, index=True)
|
||||
shout = Column(ForeignKey("shout.id"), primary_key=True, index=True)
|
||||
auto = Column(Boolean, nullable=False, default=False)
|
||||
createdAt = Column(DateTime, nullable=False, default=datetime.now, comment="Created at")
|
||||
createdAt = Column(
|
||||
DateTime, nullable=False, default=datetime.now, comment="Created at"
|
||||
)
|
||||
deletedAt = Column(DateTime, nullable=True)
|
||||
|
||||
|
||||
@@ -68,7 +72,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)
|
||||
@@ -83,7 +87,7 @@ class Shout(Base):
|
||||
"slug": "genesis-block",
|
||||
"body": "",
|
||||
"title": "Ничего",
|
||||
"lang": "ru",
|
||||
"lang": "ru"
|
||||
}
|
||||
s = Shout.create(**entry)
|
||||
session.add(s)
|
||||
|
12
orm/topic.py
12
orm/topic.py
@@ -1,7 +1,9 @@
|
||||
from base.orm import Base
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, String
|
||||
|
||||
from base.orm import Base
|
||||
|
||||
|
||||
class TopicFollower(Base):
|
||||
__tablename__ = "topic_followers"
|
||||
@@ -9,7 +11,9 @@ class TopicFollower(Base):
|
||||
id = None # type: ignore
|
||||
follower = Column(ForeignKey("user.id"), primary_key=True, index=True)
|
||||
topic = Column(ForeignKey("topic.id"), primary_key=True, index=True)
|
||||
createdAt = Column(DateTime, nullable=False, default=datetime.now, comment="Created at")
|
||||
createdAt = Column(
|
||||
DateTime, nullable=False, default=datetime.now, comment="Created at"
|
||||
)
|
||||
auto = Column(Boolean, nullable=False, default=False)
|
||||
|
||||
|
||||
@@ -20,5 +24,7 @@ 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")
|
||||
|
20
orm/user.py
20
orm/user.py
@@ -1,10 +1,10 @@
|
||||
from base.orm import Base, local_session
|
||||
from datetime import datetime
|
||||
from orm.rbac import Role
|
||||
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer
|
||||
|
||||
from sqlalchemy import JSON as JSONType
|
||||
from sqlalchemy import String
|
||||
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer, String
|
||||
from sqlalchemy.orm import relationship
|
||||
from base.orm import Base, local_session
|
||||
from orm.rbac import Role
|
||||
|
||||
|
||||
class UserRating(Base):
|
||||
@@ -34,7 +34,9 @@ class AuthorFollower(Base):
|
||||
id = None # type: ignore
|
||||
follower = Column(ForeignKey("user.id"), primary_key=True, index=True)
|
||||
author = Column(ForeignKey("user.id"), primary_key=True, index=True)
|
||||
createdAt = Column(DateTime, nullable=False, default=datetime.now, comment="Created at")
|
||||
createdAt = Column(
|
||||
DateTime, nullable=False, default=datetime.now, comment="Created at"
|
||||
)
|
||||
auto = Column(Boolean, nullable=False, default=False)
|
||||
|
||||
|
||||
@@ -52,8 +54,12 @@ class User(Base):
|
||||
slug = Column(String, unique=True, comment="User's slug")
|
||||
muted = Column(Boolean, default=False)
|
||||
emailConfirmed = Column(Boolean, default=False)
|
||||
createdAt = Column(DateTime, nullable=False, default=datetime.now, comment="Created at")
|
||||
lastSeen = Column(DateTime, nullable=False, default=datetime.now, comment="Was online at")
|
||||
createdAt = Column(
|
||||
DateTime, nullable=False, default=datetime.now, comment="Created at"
|
||||
)
|
||||
lastSeen = Column(
|
||||
DateTime, nullable=False, default=datetime.now, comment="Was online at"
|
||||
)
|
||||
deletedAt = Column(DateTime, nullable=True, comment="Deleted at")
|
||||
links = Column(JSONType, nullable=True, comment="Links")
|
||||
oauth = Column(String, nullable=True)
|
||||
|
Reference in New Issue
Block a user