collab-appear

This commit is contained in:
tonyrewin 2022-09-02 13:23:33 +03:00
parent fe13488584
commit 85892a88bc
4 changed files with 80 additions and 38 deletions

22
orm/collab.py Normal file
View File

@ -0,0 +1,22 @@
from datetime import datetime
from sqlalchemy import Boolean, Column, String, ForeignKey, DateTime
from base.orm import Base
class CollabAuthor(Base):
__tablename__ = 'collab_author'
id = None
collab = Column(ForeignKey('collab.id'), primary_key = True)
author = Column(ForeignKey('user.slug'), primary_key = True)
accepted = Column(Boolean, default=False)
class Collab(Base):
__tablename__ = 'collab'
authors = Column()
title: str = Column(String, nullable=True, comment="Title")
body: str = Column(String, nullable=True, comment="Body")
pic: str = Column(String, nullable=True, comment="Picture")
createdAt: datetime = Column(DateTime, default=datetime.now, comment="Created At")
createdBy: str = Column(ForeignKey('user.id'), comment="Created By")

View File

@ -1,10 +1,23 @@
from datetime import datetime
from base.orm import local_session
from orm.collab import Collab
from orm.shout import Shout
from orm.user import User
from base.resolvers import mutation
from base.resolvers import query, mutation
from auth.authenticate import login_required
@query.field("getCollabs")
@login_required
async def get_collabs(_, info):
auth = info.context["request"].auth
user_id = auth.user_id
collabs = []
with local_session() as session:
user = session.query(User).where(User.id == user_id).first()
collabs = session.query(Collab).filter(user.slug in Collab.authors)
return collabs
@mutation.field("inviteAuthor")
@login_required
async def invite_author(_, info, author, shout):
@ -23,7 +36,7 @@ async def invite_author(_, info, author, shout):
return {"error": "already added"}
shout.authors.append(author)
shout.updated_at = datetime.now()
shout.save()
shout.save()
session.commit()
# TODO: email notify
@ -48,7 +61,7 @@ async def remove_author(_, info, author, shout):
return {"error": "not in authors"}
shout.authors.remove(author)
shout.updated_at = datetime.now()
shout.save()
shout.save()
session.commit()
# result = Result("INVITED")

View File

@ -245,8 +245,7 @@ type Query {
reactionsForSlugs(slugs: [String]!, page: Int!, size: Int!): [Reaction]!
# collab
inviteAuthor(slug: String!, author: String!): Result!
removeAuthor(slug: String!, author: String!): Result
getCollabs: [Collab]!
# topics
topicsAll(page: Int!, size: Int!): [Topic]!
@ -339,6 +338,14 @@ type User {
oid: String
}
type Collab {
authors: [String]!
invites: [String]
createdAt: DateTime!
title: String
body: String
}
enum ReactionKind {
LIKE
DISLIKE
@ -392,7 +399,7 @@ type Shout {
body: String!
createdAt: DateTime!
authors: [Author]
# ratings: [Rating]
lang: String
community: String
cover: String
layout: String

View File

@ -1,32 +1,32 @@
from pathlib import Path
from os import environ
PORT = 8080
INBOX_SERVICE_PORT = 8081
BACKEND_URL = environ.get("BACKEND_URL") or "https://localhost:8080"
OAUTH_CALLBACK_URL = environ.get("OAUTH_CALLBACK_URL") or "https://localhost:8080"
RESET_PWD_URL = environ.get("RESET_PWD_URL") or "https://localhost:8080/reset_pwd"
CONFIRM_EMAIL_URL = environ.get("CONFIRM_EMAIL_URL") or "https://new.discours.io"
ERROR_URL_ON_FRONTEND = environ.get("ERROR_URL_ON_FRONTEND") or "https://new.discours.io"
DB_URL = environ.get("DATABASE_URL") or environ.get("DB_URL") or "postgresql://postgres@localhost:5432/discoursio" or "sqlite:///db.sqlite3"
JWT_ALGORITHM = "HS256"
JWT_SECRET_KEY = "8f1bd7696ffb482d8486dfbc6e7d16dd-secret-key"
JWT_LIFE_SPAN = 24 * 60 * 60 # seconds
JWT_AUTH_HEADER = "Auth"
EMAIL_TOKEN_LIFE_SPAN = 1 * 60 * 60 # seconds
REDIS_URL = environ.get("REDIS_URL") or "redis://127.0.0.1"
MAILGUN_API_KEY = environ.get("MAILGUN_API_KEY")
MAILGUN_DOMAIN = environ.get("MAILGUN_DOMAIN")
OAUTH_PROVIDERS = ("GITHUB", "FACEBOOK", "GOOGLE")
OAUTH_CLIENTS = {}
for provider in OAUTH_PROVIDERS:
OAUTH_CLIENTS[provider] = {
"id" : environ.get(provider + "_OAUTH_ID"),
"key" : environ.get(provider + "_OAUTH_KEY")
}
SHOUTS_REPO = "content"
from pathlib import Path
from os import environ
PORT = 8080
INBOX_SERVICE_PORT = 8081
BACKEND_URL = environ.get("BACKEND_URL") or "https://localhost:8080"
OAUTH_CALLBACK_URL = environ.get("OAUTH_CALLBACK_URL") or "https://localhost:8080"
RESET_PWD_URL = environ.get("RESET_PWD_URL") or "https://localhost:8080/reset_pwd"
CONFIRM_EMAIL_URL = environ.get("CONFIRM_EMAIL_URL") or "https://new.discours.io"
ERROR_URL_ON_FRONTEND = environ.get("ERROR_URL_ON_FRONTEND") or "https://new.discours.io"
DB_URL = environ.get("DATABASE_URL") or environ.get("DB_URL") or "postgresql://postgres@localhost:5432/discoursio" or "sqlite:///db.sqlite3"
JWT_ALGORITHM = "HS256"
JWT_SECRET_KEY = "8f1bd7696ffb482d8486dfbc6e7d16dd-secret-key"
JWT_LIFE_SPAN = 24 * 60 * 60 # seconds
JWT_AUTH_HEADER = "Auth"
EMAIL_TOKEN_LIFE_SPAN = 1 * 60 * 60 # seconds
REDIS_URL = environ.get("REDIS_URL") or "redis://127.0.0.1"
MAILGUN_API_KEY = environ.get("MAILGUN_API_KEY")
MAILGUN_DOMAIN = environ.get("MAILGUN_DOMAIN")
OAUTH_PROVIDERS = ("GITHUB", "FACEBOOK", "GOOGLE")
OAUTH_CLIENTS = {}
for provider in OAUTH_PROVIDERS:
OAUTH_CLIENTS[provider] = {
"id" : environ.get(provider + "_OAUTH_ID"),
"key" : environ.get(provider + "_OAUTH_KEY")
}
SHOUTS_REPO = "content"