diff --git a/migration/__init__.py b/migration/__init__.py index 9532c5a9..468fa886 100644 --- a/migration/__init__.py +++ b/migration/__init__.py @@ -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"] diff --git a/migration/tables/users.py b/migration/tables/users.py index 3404dd7c..4e34b7eb 100644 --- a/migration/tables/users.py +++ b/migration/tables/users.py @@ -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") diff --git a/orm/notification.py b/orm/notification.py index 75468802..41914983 100644 --- a/orm/notification.py +++ b/orm/notification.py @@ -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) # [ , .. ] - - # 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) diff --git a/orm/shout.py b/orm/shout.py index dfe9d749..ea8f1bed 100644 --- a/orm/shout.py +++ b/orm/shout.py @@ -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) diff --git a/orm/user.py b/orm/user.py index 40d04799..5aeab90e 100644 --- a/orm/user.py +++ b/orm/user.py @@ -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) # [ , .. ] - - 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) diff --git a/resolvers/__init__.py b/resolvers/__init__.py index ab919515..b7ba1e1e 100644 --- a/resolvers/__init__.py +++ b/resolvers/__init__.py @@ -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", diff --git a/resolvers/auth.py b/resolvers/auth.py index ea42f409..669a56d1 100644 --- a/resolvers/auth.py +++ b/resolvers/auth.py @@ -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 diff --git a/schema.graphql b/schema.graphql index d130b558..8eaa11e6 100644 --- a/schema.graphql +++ b/schema.graphql @@ -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