some fixes
This commit is contained in:
parent
cb798dc554
commit
910f8f59e6
|
@ -1,5 +1,4 @@
|
||||||
from graphql import GraphQLResolveInfo
|
from graphql import GraphQLResolveInfo
|
||||||
from datetime import datetime, timedelta
|
|
||||||
from transliterate import translit
|
from transliterate import translit
|
||||||
from urllib.parse import quote_plus
|
from urllib.parse import quote_plus
|
||||||
|
|
||||||
|
@ -8,7 +7,7 @@ from auth.authorize import Authorize
|
||||||
from auth.identity import Identity
|
from auth.identity import Identity
|
||||||
from auth.password import Password
|
from auth.password import Password
|
||||||
from auth.email import send_confirm_email, send_auth_email, send_reset_password_email
|
from auth.email import send_confirm_email, send_auth_email, send_reset_password_email
|
||||||
from orm import User, UserStorage, Role, UserRole
|
from orm import User, Role
|
||||||
from orm.base import local_session
|
from orm.base import local_session
|
||||||
from resolvers.base import mutation, query
|
from resolvers.base import mutation, query
|
||||||
from resolvers.profile import get_user_info
|
from resolvers.profile import get_user_info
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
|
import asyncio
|
||||||
from orm import Proposal, ProposalRating, UserStorage
|
from orm import Proposal, ProposalRating, UserStorage
|
||||||
from orm.base import local_session
|
from orm.base import local_session
|
||||||
from resolvers.base import mutation, query, subscription
|
from orm.shout import Shout
|
||||||
|
from sqlalchemy.orm import selectinload
|
||||||
|
from orm.user import User
|
||||||
|
from resolvers.base import mutation, query
|
||||||
from auth.authenticate import login_required
|
from auth.authenticate import login_required
|
||||||
import asyncio
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,6 +14,29 @@ class ProposalResult:
|
||||||
self.status = status
|
self.status = status
|
||||||
self.proposal = proposal
|
self.proposal = proposal
|
||||||
|
|
||||||
|
class ProposalStorage:
|
||||||
|
lock = asyncio.Lock()
|
||||||
|
subscriptions = []
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
async def register_subscription(subs):
|
||||||
|
async with ProposalStorage.lock:
|
||||||
|
ProposalStorage.subscriptions.append(subs)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
async def del_subscription(subs):
|
||||||
|
async with ProposalStorage.lock:
|
||||||
|
ProposalStorage.subscriptions.remove(subs)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
async def put(message_result):
|
||||||
|
async with ProposalStorage.lock:
|
||||||
|
for subs in ProposalStorage.subscriptions:
|
||||||
|
if message_result.message["chatId"] == subs.chat_id:
|
||||||
|
subs.queue.put_nowait(message_result)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@query.field("getShoutProposals")
|
@query.field("getShoutProposals")
|
||||||
@login_required
|
@login_required
|
||||||
async def get_shout_proposals(_, info, slug):
|
async def get_shout_proposals(_, info, slug):
|
||||||
|
@ -193,7 +219,7 @@ async def decline_proposal(_, info, id):
|
||||||
|
|
||||||
@mutation.field("inviteAuthor")
|
@mutation.field("inviteAuthor")
|
||||||
@login_required
|
@login_required
|
||||||
async def invite_author(_, author_slug, shout):
|
async def invite_author(_, info, author, shout):
|
||||||
auth = info.context["request"].auth
|
auth = info.context["request"].auth
|
||||||
user_id = auth.user_id
|
user_id = auth.user_id
|
||||||
|
|
||||||
|
@ -201,10 +227,10 @@ async def invite_author(_, author_slug, shout):
|
||||||
shout = session.query(Shout).filter(Shout.slug == shout).first()
|
shout = session.query(Shout).filter(Shout.slug == shout).first()
|
||||||
if not shout:
|
if not shout:
|
||||||
return {"error": "invalid shout slug"}
|
return {"error": "invalid shout slug"}
|
||||||
authors = [author.id for author in shout.authors]
|
authors = [a.id for a in shout.authors]
|
||||||
if user_id not in authors:
|
if user_id not in authors:
|
||||||
return {"error": "access denied"}
|
return {"error": "access denied"}
|
||||||
author = session.query(User).filter(User.slug == author_slug).first()
|
author = session.query(User).filter(User.slug == author).first()
|
||||||
if author.id in authors:
|
if author.id in authors:
|
||||||
return {"error": "already added"}
|
return {"error": "already added"}
|
||||||
shout.authors.append(author)
|
shout.authors.append(author)
|
||||||
|
@ -219,7 +245,7 @@ async def invite_author(_, author_slug, shout):
|
||||||
|
|
||||||
@mutation.field("removeAuthor")
|
@mutation.field("removeAuthor")
|
||||||
@login_required
|
@login_required
|
||||||
async def remove_author(_, author_slug, shout):
|
async def remove_author(_, info, author, shout):
|
||||||
auth = info.context["request"].auth
|
auth = info.context["request"].auth
|
||||||
user_id = auth.user_id
|
user_id = auth.user_id
|
||||||
|
|
||||||
|
@ -230,7 +256,7 @@ async def remove_author(_, author_slug, shout):
|
||||||
authors = [author.id for author in shout.authors]
|
authors = [author.id for author in shout.authors]
|
||||||
if user_id not in authors:
|
if user_id not in authors:
|
||||||
return {"error": "access denied"}
|
return {"error": "access denied"}
|
||||||
author = session.query(User).filter(User.slug == author_slug).first()
|
author = session.query(User).filter(User.slug == author).first()
|
||||||
if author.id not in authors:
|
if author.id not in authors:
|
||||||
return {"error": "not in authors"}
|
return {"error": "not in authors"}
|
||||||
shout.authors.remove(author)
|
shout.authors.remove(author)
|
||||||
|
|
|
@ -2,9 +2,8 @@ from orm import Comment, CommentRating
|
||||||
from orm.base import local_session
|
from orm.base import local_session
|
||||||
from orm.shout import ShoutCommentsSubscription
|
from orm.shout import ShoutCommentsSubscription
|
||||||
from orm.user import User
|
from orm.user import User
|
||||||
from resolvers.base import mutation, query, subscription
|
from resolvers.base import mutation
|
||||||
from auth.authenticate import login_required
|
from auth.authenticate import login_required
|
||||||
import asyncio
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
def comments_subscribe(user, slug, auto = False):
|
def comments_subscribe(user, slug, auto = False):
|
||||||
|
@ -46,7 +45,7 @@ async def create_comment(_, info, body, shout, replyTo = None):
|
||||||
user = info.context["request"].user
|
user = info.context["request"].user
|
||||||
|
|
||||||
comment = Comment.create(
|
comment = Comment.create(
|
||||||
author = user.id,
|
createdBy = user.slug,
|
||||||
body = body,
|
body = body,
|
||||||
shout = shout,
|
shout = shout,
|
||||||
replyTo = replyTo
|
replyTo = replyTo
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
from orm import Community, CommunitySubscription
|
from orm import Community, CommunitySubscription
|
||||||
from orm.base import local_session
|
from orm.base import local_session
|
||||||
from resolvers.base import mutation, query, subscription
|
from resolvers.base import mutation, query
|
||||||
from auth.authenticate import login_required
|
from auth.authenticate import login_required
|
||||||
import asyncio
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from sqlalchemy import and_
|
from sqlalchemy import and_
|
||||||
|
@ -29,7 +28,7 @@ async def update_community(_, info, input):
|
||||||
user_id = auth.user_id
|
user_id = auth.user_id
|
||||||
|
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
community = session.query(Community).filter(Community.slug == inpit.get('slug', '')).first()
|
community = session.query(Community).filter(Community.slug == input.get('slug', '')).first()
|
||||||
if not community:
|
if not community:
|
||||||
return {"error": "invalid community id"}
|
return {"error": "invalid community id"}
|
||||||
if community.createdBy != user_id:
|
if community.createdBy != user_id:
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
from orm import Shout, ShoutRating, ShoutRatingStorage
|
from orm import Shout
|
||||||
from orm.base import local_session
|
from orm.base import local_session
|
||||||
from resolvers.base import mutation, query, subscription
|
from orm.rbac import Resource
|
||||||
|
from orm.shout import ShoutAuthor, ShoutTopic
|
||||||
|
from orm.user import User
|
||||||
|
from resolvers.base import mutation
|
||||||
from resolvers.comments import comments_subscribe
|
from resolvers.comments import comments_subscribe
|
||||||
from auth.authenticate import login_required
|
from auth.authenticate import login_required
|
||||||
import asyncio
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
from resolvers.zine import GitTask
|
||||||
|
|
||||||
|
|
||||||
@mutation.field("createShout")
|
@mutation.field("createShout")
|
||||||
@login_required
|
@login_required
|
||||||
|
@ -19,7 +23,8 @@ async def create_shout(_, info, input):
|
||||||
new_shout = Shout.create(**input)
|
new_shout = Shout.create(**input)
|
||||||
ShoutAuthor.create(
|
ShoutAuthor.create(
|
||||||
shout = new_shout.slug,
|
shout = new_shout.slug,
|
||||||
user = user.slug)
|
user = user.slug
|
||||||
|
)
|
||||||
|
|
||||||
comments_subscribe(user, new_shout.slug, True)
|
comments_subscribe(user, new_shout.slug, True)
|
||||||
|
|
||||||
|
@ -39,7 +44,7 @@ async def create_shout(_, info, input):
|
||||||
"new shout %s" % (new_shout.slug)
|
"new shout %s" % (new_shout.slug)
|
||||||
)
|
)
|
||||||
|
|
||||||
await ShoutCommentsStorage.send_shout(new_shout)
|
# await ShoutCommentsStorage.send_shout(new_shout)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"shout" : new_shout
|
"shout" : new_shout
|
||||||
|
@ -100,8 +105,8 @@ async def delete_shout(_, info, slug):
|
||||||
|
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
shout = session.query(Shout).filter(Shout.slug == slug).first()
|
shout = session.query(Shout).filter(Shout.slug == slug).first()
|
||||||
authors = [author.id for author in shout.authors]
|
authors = [a.id for a in shout.authors]
|
||||||
if not comment:
|
if not shout:
|
||||||
return {"error": "invalid shout slug"}
|
return {"error": "invalid shout slug"}
|
||||||
if user_id not in authors:
|
if user_id not in authors:
|
||||||
return {"error": "access denied"}
|
return {"error": "access denied"}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import asyncio
|
||||||
|
|
||||||
from sqlalchemy import func, and_
|
from sqlalchemy import func, and_
|
||||||
|
|
||||||
@query.field("topicsBySlugs")
|
@query.field("topicsAll")
|
||||||
async def topics_by_slugs(_, info, slugs = None):
|
async def topics_by_slugs(_, info, slugs = None):
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
topics = await TopicStorage.get_topics(slugs)
|
topics = await TopicStorage.get_topics(slugs)
|
||||||
|
|
|
@ -197,7 +197,7 @@ type Query {
|
||||||
recentAll(page: Int!, size: Int!): [Shout]!
|
recentAll(page: Int!, size: Int!): [Shout]!
|
||||||
|
|
||||||
# topics
|
# topics
|
||||||
topicsBySlugs(slugs: [String]): [Topic]!
|
topicsAll(slugs: [String]): [Topic]!
|
||||||
topicsByCommunity(community: String!): [Topic]!
|
topicsByCommunity(community: String!): [Topic]!
|
||||||
topicsByAuthor(author: String!): [Topic]!
|
topicsByAuthor(author: String!): [Topic]!
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user