collab-appear
This commit is contained in:
parent
fe13488584
commit
85892a88bc
22
orm/collab.py
Normal file
22
orm/collab.py
Normal 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")
|
||||||
|
|
|
@ -1,10 +1,23 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from base.orm import local_session
|
from base.orm import local_session
|
||||||
|
from orm.collab import Collab
|
||||||
from orm.shout import Shout
|
from orm.shout import Shout
|
||||||
from orm.user import User
|
from orm.user import User
|
||||||
from base.resolvers import mutation
|
from base.resolvers import query, mutation
|
||||||
from auth.authenticate import login_required
|
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")
|
@mutation.field("inviteAuthor")
|
||||||
@login_required
|
@login_required
|
||||||
async def invite_author(_, info, author, shout):
|
async def invite_author(_, info, author, shout):
|
||||||
|
@ -23,7 +36,7 @@ async def invite_author(_, info, author, shout):
|
||||||
return {"error": "already added"}
|
return {"error": "already added"}
|
||||||
shout.authors.append(author)
|
shout.authors.append(author)
|
||||||
shout.updated_at = datetime.now()
|
shout.updated_at = datetime.now()
|
||||||
shout.save()
|
shout.save()
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
# TODO: email notify
|
# TODO: email notify
|
||||||
|
@ -48,7 +61,7 @@ async def remove_author(_, info, author, shout):
|
||||||
return {"error": "not in authors"}
|
return {"error": "not in authors"}
|
||||||
shout.authors.remove(author)
|
shout.authors.remove(author)
|
||||||
shout.updated_at = datetime.now()
|
shout.updated_at = datetime.now()
|
||||||
shout.save()
|
shout.save()
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
# result = Result("INVITED")
|
# result = Result("INVITED")
|
||||||
|
|
|
@ -245,8 +245,7 @@ type Query {
|
||||||
reactionsForSlugs(slugs: [String]!, page: Int!, size: Int!): [Reaction]!
|
reactionsForSlugs(slugs: [String]!, page: Int!, size: Int!): [Reaction]!
|
||||||
|
|
||||||
# collab
|
# collab
|
||||||
inviteAuthor(slug: String!, author: String!): Result!
|
getCollabs: [Collab]!
|
||||||
removeAuthor(slug: String!, author: String!): Result
|
|
||||||
|
|
||||||
# topics
|
# topics
|
||||||
topicsAll(page: Int!, size: Int!): [Topic]!
|
topicsAll(page: Int!, size: Int!): [Topic]!
|
||||||
|
@ -339,6 +338,14 @@ type User {
|
||||||
oid: String
|
oid: String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Collab {
|
||||||
|
authors: [String]!
|
||||||
|
invites: [String]
|
||||||
|
createdAt: DateTime!
|
||||||
|
title: String
|
||||||
|
body: String
|
||||||
|
}
|
||||||
|
|
||||||
enum ReactionKind {
|
enum ReactionKind {
|
||||||
LIKE
|
LIKE
|
||||||
DISLIKE
|
DISLIKE
|
||||||
|
@ -392,7 +399,7 @@ type Shout {
|
||||||
body: String!
|
body: String!
|
||||||
createdAt: DateTime!
|
createdAt: DateTime!
|
||||||
authors: [Author]
|
authors: [Author]
|
||||||
# ratings: [Rating]
|
lang: String
|
||||||
community: String
|
community: String
|
||||||
cover: String
|
cover: String
|
||||||
layout: String
|
layout: String
|
||||||
|
|
64
settings.py
64
settings.py
|
@ -1,32 +1,32 @@
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from os import environ
|
from os import environ
|
||||||
|
|
||||||
PORT = 8080
|
PORT = 8080
|
||||||
INBOX_SERVICE_PORT = 8081
|
INBOX_SERVICE_PORT = 8081
|
||||||
|
|
||||||
BACKEND_URL = environ.get("BACKEND_URL") or "https://localhost:8080"
|
BACKEND_URL = environ.get("BACKEND_URL") or "https://localhost:8080"
|
||||||
OAUTH_CALLBACK_URL = environ.get("OAUTH_CALLBACK_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"
|
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"
|
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"
|
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"
|
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_ALGORITHM = "HS256"
|
||||||
JWT_SECRET_KEY = "8f1bd7696ffb482d8486dfbc6e7d16dd-secret-key"
|
JWT_SECRET_KEY = "8f1bd7696ffb482d8486dfbc6e7d16dd-secret-key"
|
||||||
JWT_LIFE_SPAN = 24 * 60 * 60 # seconds
|
JWT_LIFE_SPAN = 24 * 60 * 60 # seconds
|
||||||
JWT_AUTH_HEADER = "Auth"
|
JWT_AUTH_HEADER = "Auth"
|
||||||
EMAIL_TOKEN_LIFE_SPAN = 1 * 60 * 60 # seconds
|
EMAIL_TOKEN_LIFE_SPAN = 1 * 60 * 60 # seconds
|
||||||
REDIS_URL = environ.get("REDIS_URL") or "redis://127.0.0.1"
|
REDIS_URL = environ.get("REDIS_URL") or "redis://127.0.0.1"
|
||||||
|
|
||||||
MAILGUN_API_KEY = environ.get("MAILGUN_API_KEY")
|
MAILGUN_API_KEY = environ.get("MAILGUN_API_KEY")
|
||||||
MAILGUN_DOMAIN = environ.get("MAILGUN_DOMAIN")
|
MAILGUN_DOMAIN = environ.get("MAILGUN_DOMAIN")
|
||||||
|
|
||||||
OAUTH_PROVIDERS = ("GITHUB", "FACEBOOK", "GOOGLE")
|
OAUTH_PROVIDERS = ("GITHUB", "FACEBOOK", "GOOGLE")
|
||||||
OAUTH_CLIENTS = {}
|
OAUTH_CLIENTS = {}
|
||||||
for provider in OAUTH_PROVIDERS:
|
for provider in OAUTH_PROVIDERS:
|
||||||
OAUTH_CLIENTS[provider] = {
|
OAUTH_CLIENTS[provider] = {
|
||||||
"id" : environ.get(provider + "_OAUTH_ID"),
|
"id" : environ.get(provider + "_OAUTH_ID"),
|
||||||
"key" : environ.get(provider + "_OAUTH_KEY")
|
"key" : environ.get(provider + "_OAUTH_KEY")
|
||||||
}
|
}
|
||||||
|
|
||||||
SHOUTS_REPO = "content"
|
SHOUTS_REPO = "content"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user