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:
parent
1fc6178b97
commit
b4e14cce93
|
@ -33,7 +33,6 @@ async def users_handle(storage):
|
||||||
user = migrateUser(entry)
|
user = migrateUser(entry)
|
||||||
storage["users"]["by_oid"][oid] = user # full
|
storage["users"]["by_oid"][oid] = user # full
|
||||||
del user["password"]
|
del user["password"]
|
||||||
del user["notifications"]
|
|
||||||
del user["emailConfirmed"]
|
del user["emailConfirmed"]
|
||||||
del user["username"]
|
del user["username"]
|
||||||
del user["email"]
|
del user["email"]
|
||||||
|
|
|
@ -22,7 +22,6 @@ def migrate(entry):
|
||||||
"emailConfirmed": ("@discours.io" in email) or bool(entry["emails"][0]["verified"]),
|
"emailConfirmed": ("@discours.io" in email) or bool(entry["emails"][0]["verified"]),
|
||||||
"muted": False, # amnesty
|
"muted": False, # amnesty
|
||||||
"bio": entry["profile"].get("bio", ""),
|
"bio": entry["profile"].get("bio", ""),
|
||||||
"notifications": [],
|
|
||||||
"links": [],
|
"links": [],
|
||||||
"name": "anonymous",
|
"name": "anonymous",
|
||||||
"password": entry["services"]["password"].get("bcrypt")
|
"password": entry["services"]["password"].get("bcrypt")
|
||||||
|
|
|
@ -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
|
from base.orm import Base
|
||||||
|
|
||||||
|
|
||||||
class Notification(Base):
|
class Notification(Base):
|
||||||
__tablename__ = "notification"
|
__tablename__ = "notification"
|
||||||
|
|
||||||
kind = Column(String, unique=True, primary_key=True)
|
user = Column(ForeignKey("user.id"), index=True)
|
||||||
template = Column(String, nullable=False)
|
createdAt = Column(DateTime, nullable=False, default=datetime.now, index=True)
|
||||||
variables = Column(JSONType, nullable=True) # [ <var1>, .. ]
|
seen = Column(Boolean, nullable=False, default=False, index=True)
|
||||||
|
type = Column(String, nullable=False)
|
||||||
# looks like frontend code
|
data = Column(JSON, nullable=True)
|
||||||
|
|
|
@ -53,6 +53,7 @@ class Shout(Base):
|
||||||
|
|
||||||
slug = Column(String, unique=True)
|
slug = Column(String, unique=True)
|
||||||
cover = Column(String, nullable=True, comment="Cover image url")
|
cover = Column(String, nullable=True, comment="Cover image url")
|
||||||
|
lead = Column(String, nullable=True)
|
||||||
body = Column(String, nullable=False, comment="Body")
|
body = Column(String, nullable=False, comment="Body")
|
||||||
title = Column(String, nullable=True)
|
title = Column(String, nullable=True)
|
||||||
subtitle = Column(String, nullable=True)
|
subtitle = Column(String, nullable=True)
|
||||||
|
|
10
orm/user.py
10
orm/user.py
|
@ -3,19 +3,10 @@ from datetime import datetime
|
||||||
from sqlalchemy import JSON as JSONType
|
from sqlalchemy import JSON as JSONType
|
||||||
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer, String
|
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer, String
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
|
|
||||||
from base.orm import Base, local_session
|
from base.orm import Base, local_session
|
||||||
from orm.rbac import Role
|
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):
|
class UserRating(Base):
|
||||||
__tablename__ = "user_rating"
|
__tablename__ = "user_rating"
|
||||||
|
|
||||||
|
@ -72,7 +63,6 @@ class User(Base):
|
||||||
deletedAt = Column(DateTime, nullable=True, comment="Deleted at")
|
deletedAt = Column(DateTime, nullable=True, comment="Deleted at")
|
||||||
links = Column(JSONType, nullable=True, comment="Links")
|
links = Column(JSONType, nullable=True, comment="Links")
|
||||||
oauth = Column(String, nullable=True)
|
oauth = Column(String, nullable=True)
|
||||||
notifications = relationship(lambda: UserNotifications)
|
|
||||||
ratings = relationship(UserRating, foreign_keys=UserRating.user)
|
ratings = relationship(UserRating, foreign_keys=UserRating.user)
|
||||||
roles = relationship(lambda: Role, secondary=UserRole.__tablename__)
|
roles = relationship(lambda: Role, secondary=UserRole.__tablename__)
|
||||||
oid = Column(String, nullable=True)
|
oid = Column(String, nullable=True)
|
||||||
|
|
|
@ -90,13 +90,6 @@ __all__ = [
|
||||||
"update_shout",
|
"update_shout",
|
||||||
"delete_shout",
|
"delete_shout",
|
||||||
"markdown_body",
|
"markdown_body",
|
||||||
"load_drafts",
|
|
||||||
"create_draft",
|
|
||||||
"update_draft",
|
|
||||||
"delete_draft",
|
|
||||||
"invite_coauthor",
|
|
||||||
"accept_coauthor",
|
|
||||||
"draft_to_shout",
|
|
||||||
# zine.topics
|
# zine.topics
|
||||||
"topics_all",
|
"topics_all",
|
||||||
"topics_by_community",
|
"topics_by_community",
|
||||||
|
|
|
@ -110,6 +110,7 @@ def generate_unique_slug(src):
|
||||||
|
|
||||||
@mutation.field("registerUser")
|
@mutation.field("registerUser")
|
||||||
async def register_by_email(_, _info, email: str, password: str = "", name: str = ""):
|
async def register_by_email(_, _info, email: str, password: str = "", name: str = ""):
|
||||||
|
email = email.lower()
|
||||||
"""creates new user account"""
|
"""creates new user account"""
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
user = session.query(User).filter(User.email == email).first()
|
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")
|
@mutation.field("sendLink")
|
||||||
async def auth_send_link(_, _info, email, lang="ru", template="email_confirmation"):
|
async def auth_send_link(_, _info, email, lang="ru", template="email_confirmation"):
|
||||||
|
email = email.lower()
|
||||||
"""send link with confirm code to email"""
|
"""send link with confirm code to email"""
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
user = session.query(User).filter(User.email == email).first()
|
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")
|
@query.field("signIn")
|
||||||
async def login(_, info, email: str, password: str = "", lang: str = "ru"):
|
async def login(_, info, email: str, password: str = "", lang: str = "ru"):
|
||||||
|
email = email.lower()
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
orm_user = session.query(User).filter(User.email == email).first()
|
orm_user = session.query(User).filter(User.email == email).first()
|
||||||
if orm_user is None:
|
if orm_user is None:
|
||||||
|
@ -193,6 +196,7 @@ async def sign_out(_, info: GraphQLResolveInfo):
|
||||||
|
|
||||||
@query.field("isEmailUsed")
|
@query.field("isEmailUsed")
|
||||||
async def is_email_used(_, _info, email):
|
async def is_email_used(_, _info, email):
|
||||||
|
email = email.lower()
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
user = session.query(User).filter(User.email == email).first()
|
user = session.query(User).filter(User.email == email).first()
|
||||||
return user is not None
|
return user is not None
|
||||||
|
|
|
@ -336,19 +336,6 @@ type Rating {
|
||||||
value: Int!
|
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 {
|
type User {
|
||||||
id: Int!
|
id: Int!
|
||||||
username: String! # to login, ex. email, phone
|
username: String! # to login, ex. email, phone
|
||||||
|
@ -367,7 +354,6 @@ type User {
|
||||||
ratings: [Rating]
|
ratings: [Rating]
|
||||||
bio: String
|
bio: String
|
||||||
about: String
|
about: String
|
||||||
notifications: [Int]
|
|
||||||
communities: [Int] # user participating communities
|
communities: [Int] # user participating communities
|
||||||
oid: String
|
oid: String
|
||||||
}
|
}
|
||||||
|
@ -417,6 +403,7 @@ type Shout {
|
||||||
id: Int!
|
id: Int!
|
||||||
slug: String!
|
slug: String!
|
||||||
body: String!
|
body: String!
|
||||||
|
lead: String
|
||||||
createdAt: DateTime!
|
createdAt: DateTime!
|
||||||
topics: [Topic]
|
topics: [Topic]
|
||||||
mainTopic: String
|
mainTopic: String
|
||||||
|
|
Loading…
Reference in New Issue
Block a user