migration-orm-fixes
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
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 auth.authenticate import login_required
|
||||
import asyncio
|
||||
@@ -68,7 +69,7 @@ async def update_comment(_, info, id, body):
|
||||
comment = session.query(Comment).filter(Comment.id == id).first()
|
||||
if not comment:
|
||||
return {"error": "invalid comment id"}
|
||||
if comment.author != user_id:
|
||||
if comment.createdBy != user_id:
|
||||
return {"error": "access denied"}
|
||||
|
||||
comment.body = body
|
||||
@@ -88,7 +89,7 @@ async def delete_comment(_, info, id):
|
||||
comment = session.query(Comment).filter(Comment.id == id).first()
|
||||
if not comment:
|
||||
return {"error": "invalid comment id"}
|
||||
if comment.author != user_id:
|
||||
if comment.createdBy != user_id:
|
||||
return {"error": "access denied"}
|
||||
|
||||
comment.deletedAt = datetime.now()
|
||||
@@ -103,12 +104,12 @@ async def rate_comment(_, info, id, value):
|
||||
user_id = auth.user_id
|
||||
|
||||
with local_session() as session:
|
||||
user = session.query(User).filter(User.id == user_id).first()
|
||||
comment = session.query(Comment).filter(Comment.id == id).first()
|
||||
if not comment:
|
||||
return {"error": "invalid comment id"}
|
||||
|
||||
rating = session.query(CommentRating).\
|
||||
filter(CommentRating.comment_id == id, CommentRating.createdBy == user_id).first()
|
||||
filter(CommentRating.comment_id == id, CommentRating.createdBy == user.slug).first()
|
||||
if rating:
|
||||
rating.value = value
|
||||
session.commit()
|
||||
@@ -124,7 +125,8 @@ async def rate_comment(_, info, id, value):
|
||||
def get_subscribed_shout_comments(slug):
|
||||
with local_session() as session:
|
||||
rows = session.query(ShoutCommentsSubscription.shout).\
|
||||
filter(ShoutCommentsSubscription.subscriber == slug, ShoutCommentsSubscription.deletedAt == None).\
|
||||
filter(ShoutCommentsSubscription.subscriber == slug,\
|
||||
ShoutCommentsSubscription.deletedAt == None).\
|
||||
all()
|
||||
slugs = [row.shout for row in rows]
|
||||
return slugs
|
||||
|
@@ -91,7 +91,7 @@ async def user_comments(_, info, slug, page, size):
|
||||
page = page - 1
|
||||
with local_session() as session:
|
||||
comments = session.query(Comment).\
|
||||
filter(Comment.author == user.id).\
|
||||
filter(Comment.createdBy == user.id).\
|
||||
order_by(desc(Comment.createdAt)).\
|
||||
limit(size).\
|
||||
offset(page * size)
|
||||
@@ -198,7 +198,7 @@ async def shouts_reviewed(_, info, page, size):
|
||||
where(and_(Shout.publishedAt != None, ShoutRating.rater == user.slug))
|
||||
shouts_by_comment = session.query(Shout).\
|
||||
join(Comment).\
|
||||
where(and_(Shout.publishedAt != None, Comment.author == user.id))
|
||||
where(and_(Shout.publishedAt != None, Comment.createdBy == user.id))
|
||||
shouts = shouts_by_rating.union(shouts_by_comment).\
|
||||
order_by(desc(Shout.publishedAt)).\
|
||||
limit(size).\
|
||||
@@ -215,7 +215,7 @@ async def shouts_commented_by_user(_, info, slug, page, size):
|
||||
with local_session() as session:
|
||||
shouts = session.query(Shout).\
|
||||
join(Comment).\
|
||||
where(Comment.author == user.id).\
|
||||
where(Comment.createdBy == user.id).\
|
||||
order_by(desc(Comment.createdAt)).\
|
||||
limit(size).\
|
||||
offset( (page - 1) * size)
|
||||
|
@@ -272,7 +272,7 @@ async def get_shout_comments(_, info, slug):
|
||||
filter(Comment.shout == slug).\
|
||||
group_by(Comment.id).all()
|
||||
for comment in comments:
|
||||
comment.author = await UserStorage.get_user(comment.author)
|
||||
comment.createdBy = await UserStorage.get_user(comment.createdBy)
|
||||
return comments
|
||||
|
||||
@query.field("shoutsByTopics")
|
||||
|
Reference in New Issue
Block a user