some fixes
This commit is contained in:
parent
cb798dc554
commit
910f8f59e6
|
@ -1,5 +1,4 @@
|
|||
from graphql import GraphQLResolveInfo
|
||||
from datetime import datetime, timedelta
|
||||
from transliterate import translit
|
||||
from urllib.parse import quote_plus
|
||||
|
||||
|
@ -8,7 +7,7 @@ from auth.authorize import Authorize
|
|||
from auth.identity import Identity
|
||||
from auth.password import Password
|
||||
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 resolvers.base import mutation, query
|
||||
from resolvers.profile import get_user_info
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
import asyncio
|
||||
from orm import Proposal, ProposalRating, UserStorage
|
||||
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
|
||||
import asyncio
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
|
@ -11,6 +14,29 @@ class ProposalResult:
|
|||
self.status = status
|
||||
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")
|
||||
@login_required
|
||||
async def get_shout_proposals(_, info, slug):
|
||||
|
@ -193,7 +219,7 @@ async def decline_proposal(_, info, id):
|
|||
|
||||
@mutation.field("inviteAuthor")
|
||||
@login_required
|
||||
async def invite_author(_, author_slug, shout):
|
||||
async def invite_author(_, info, author, shout):
|
||||
auth = info.context["request"].auth
|
||||
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()
|
||||
if not shout:
|
||||
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:
|
||||
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:
|
||||
return {"error": "already added"}
|
||||
shout.authors.append(author)
|
||||
|
@ -219,7 +245,7 @@ async def invite_author(_, author_slug, shout):
|
|||
|
||||
@mutation.field("removeAuthor")
|
||||
@login_required
|
||||
async def remove_author(_, author_slug, shout):
|
||||
async def remove_author(_, info, author, shout):
|
||||
auth = info.context["request"].auth
|
||||
user_id = auth.user_id
|
||||
|
||||
|
@ -230,7 +256,7 @@ async def remove_author(_, author_slug, shout):
|
|||
authors = [author.id for author in shout.authors]
|
||||
if user_id not in authors:
|
||||
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:
|
||||
return {"error": "not in authors"}
|
||||
shout.authors.remove(author)
|
||||
|
|
|
@ -2,9 +2,8 @@ from orm import Comment, CommentRating
|
|||
from orm.base import local_session
|
||||
from orm.shout import ShoutCommentsSubscription
|
||||
from orm.user import User
|
||||
from resolvers.base import mutation, query, subscription
|
||||
from resolvers.base import mutation
|
||||
from auth.authenticate import login_required
|
||||
import asyncio
|
||||
from datetime import datetime
|
||||
|
||||
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
|
||||
|
||||
comment = Comment.create(
|
||||
author = user.id,
|
||||
createdBy = user.slug,
|
||||
body = body,
|
||||
shout = shout,
|
||||
replyTo = replyTo
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
from orm import Community, CommunitySubscription
|
||||
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
|
||||
import asyncio
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy import and_
|
||||
|
@ -29,7 +28,7 @@ async def update_community(_, info, input):
|
|||
user_id = auth.user_id
|
||||
|
||||
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:
|
||||
return {"error": "invalid community 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 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 auth.authenticate import login_required
|
||||
import asyncio
|
||||
from datetime import datetime
|
||||
|
||||
from resolvers.zine import GitTask
|
||||
|
||||
|
||||
@mutation.field("createShout")
|
||||
@login_required
|
||||
|
@ -19,7 +23,8 @@ async def create_shout(_, info, input):
|
|||
new_shout = Shout.create(**input)
|
||||
ShoutAuthor.create(
|
||||
shout = new_shout.slug,
|
||||
user = user.slug)
|
||||
user = user.slug
|
||||
)
|
||||
|
||||
comments_subscribe(user, new_shout.slug, True)
|
||||
|
||||
|
@ -39,7 +44,7 @@ async def create_shout(_, info, input):
|
|||
"new shout %s" % (new_shout.slug)
|
||||
)
|
||||
|
||||
await ShoutCommentsStorage.send_shout(new_shout)
|
||||
# await ShoutCommentsStorage.send_shout(new_shout)
|
||||
|
||||
return {
|
||||
"shout" : new_shout
|
||||
|
@ -100,8 +105,8 @@ async def delete_shout(_, info, slug):
|
|||
|
||||
with local_session() as session:
|
||||
shout = session.query(Shout).filter(Shout.slug == slug).first()
|
||||
authors = [author.id for author in shout.authors]
|
||||
if not comment:
|
||||
authors = [a.id for a in shout.authors]
|
||||
if not shout:
|
||||
return {"error": "invalid shout slug"}
|
||||
if user_id not in authors:
|
||||
return {"error": "access denied"}
|
||||
|
|
|
@ -8,7 +8,7 @@ import asyncio
|
|||
|
||||
from sqlalchemy import func, and_
|
||||
|
||||
@query.field("topicsBySlugs")
|
||||
@query.field("topicsAll")
|
||||
async def topics_by_slugs(_, info, slugs = None):
|
||||
with local_session() as session:
|
||||
topics = await TopicStorage.get_topics(slugs)
|
||||
|
|
|
@ -197,7 +197,7 @@ type Query {
|
|||
recentAll(page: Int!, size: Int!): [Shout]!
|
||||
|
||||
# topics
|
||||
topicsBySlugs(slugs: [String]): [Topic]!
|
||||
topicsAll(slugs: [String]): [Topic]!
|
||||
topicsByCommunity(community: String!): [Topic]!
|
||||
topicsByAuthor(author: String!): [Topic]!
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user