added lead field to shout, new table event (#71)

* added lead field to shout, new table event

* repurposed unused notifications table
This commit is contained in:
Igor Lobanov 2023-08-06 22:01:40 +02:00 committed by GitHub
parent 1fc6178b97
commit b4e14cce93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 13 additions and 40 deletions

View File

@ -33,7 +33,6 @@ async def users_handle(storage):
user = migrateUser(entry)
storage["users"]["by_oid"][oid] = user # full
del user["password"]
del user["notifications"]
del user["emailConfirmed"]
del user["username"]
del user["email"]

View File

@ -22,7 +22,6 @@ def migrate(entry):
"emailConfirmed": ("@discours.io" in email) or bool(entry["emails"][0]["verified"]),
"muted": False, # amnesty
"bio": entry["profile"].get("bio", ""),
"notifications": [],
"links": [],
"name": "anonymous",
"password": entry["services"]["password"].get("bcrypt")

View File

@ -1,13 +1,13 @@
from sqlalchemy import Column, String, JSON as JSONType
from datetime import datetime
from sqlalchemy import Column, String, JSON, ForeignKey, DateTime, Boolean
from base.orm import Base
class Notification(Base):
__tablename__ = "notification"
kind = Column(String, unique=True, primary_key=True)
template = Column(String, nullable=False)
variables = Column(JSONType, nullable=True) # [ <var1>, .. ]
# looks like frontend code
user = Column(ForeignKey("user.id"), index=True)
createdAt = Column(DateTime, nullable=False, default=datetime.now, index=True)
seen = Column(Boolean, nullable=False, default=False, index=True)
type = Column(String, nullable=False)
data = Column(JSON, nullable=True)

View File

@ -53,6 +53,7 @@ class Shout(Base):
slug = Column(String, unique=True)
cover = Column(String, nullable=True, comment="Cover image url")
lead = Column(String, nullable=True)
body = Column(String, nullable=False, comment="Body")
title = Column(String, nullable=True)
subtitle = Column(String, nullable=True)

View File

@ -3,19 +3,10 @@ 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 orm.rbac import Role
class UserNotifications(Base):
__tablename__ = "user_notifications"
# id auto
user = Column(Integer, ForeignKey("user.id"))
kind = Column(String, ForeignKey("notification.kind"))
values = Column(JSONType, nullable=True) # [ <var1>, .. ]
class UserRating(Base):
__tablename__ = "user_rating"
@ -72,7 +63,6 @@ class User(Base):
deletedAt = Column(DateTime, nullable=True, comment="Deleted at")
links = Column(JSONType, nullable=True, comment="Links")
oauth = Column(String, nullable=True)
notifications = relationship(lambda: UserNotifications)
ratings = relationship(UserRating, foreign_keys=UserRating.user)
roles = relationship(lambda: Role, secondary=UserRole.__tablename__)
oid = Column(String, nullable=True)

View File

@ -90,13 +90,6 @@ __all__ = [
"update_shout",
"delete_shout",
"markdown_body",
"load_drafts",
"create_draft",
"update_draft",
"delete_draft",
"invite_coauthor",
"accept_coauthor",
"draft_to_shout",
# zine.topics
"topics_all",
"topics_by_community",

View File

@ -110,6 +110,7 @@ def generate_unique_slug(src):
@mutation.field("registerUser")
async def register_by_email(_, _info, email: str, password: str = "", name: str = ""):
email = email.lower()
"""creates new user account"""
with local_session() as session:
user = session.query(User).filter(User.email == email).first()
@ -135,6 +136,7 @@ async def register_by_email(_, _info, email: str, password: str = "", name: str
@mutation.field("sendLink")
async def auth_send_link(_, _info, email, lang="ru", template="email_confirmation"):
email = email.lower()
"""send link with confirm code to email"""
with local_session() as session:
user = session.query(User).filter(User.email == email).first()
@ -148,6 +150,7 @@ async def auth_send_link(_, _info, email, lang="ru", template="email_confirmatio
@query.field("signIn")
async def login(_, info, email: str, password: str = "", lang: str = "ru"):
email = email.lower()
with local_session() as session:
orm_user = session.query(User).filter(User.email == email).first()
if orm_user is None:
@ -193,6 +196,7 @@ async def sign_out(_, info: GraphQLResolveInfo):
@query.field("isEmailUsed")
async def is_email_used(_, _info, email):
email = email.lower()
with local_session() as session:
user = session.query(User).filter(User.email == email).first()
return user is not None

View File

@ -336,19 +336,6 @@ type Rating {
value: Int!
}
type Notification {
kind: String! # unique primary key
template: String!
variables: [String]
}
type UserNotification {
id: Int! # primary key
user: Int!
kind: String! # NotificationTemplate.name
values: [String]
}
type User {
id: Int!
username: String! # to login, ex. email, phone
@ -367,7 +354,6 @@ type User {
ratings: [Rating]
bio: String
about: String
notifications: [Int]
communities: [Int] # user participating communities
oid: String
}
@ -417,6 +403,7 @@ type Shout {
id: Int!
slug: String!
body: String!
lead: String
createdAt: DateTime!
topics: [Topic]
mainTopic: String