load fixed, auth wip
This commit is contained in:
@@ -8,7 +8,7 @@ from resolvers.auth import (
|
||||
get_current_user,
|
||||
)
|
||||
|
||||
from resolvers.create.collab import remove_author, invite_author
|
||||
from resolvers.create.collab import remove_coauthor, invite_coauthor
|
||||
from resolvers.create.migrate import markdown_body
|
||||
from resolvers.create.editor import create_shout, delete_shout, update_shout
|
||||
|
||||
@@ -93,8 +93,8 @@ __all__ = [
|
||||
# create.migrate
|
||||
"markdown_body",
|
||||
# create.collab
|
||||
"invite_author",
|
||||
"remove_author",
|
||||
"invite_coauthor",
|
||||
"remove_coauthor",
|
||||
# zine.topics
|
||||
"topics_all",
|
||||
"topics_by_community",
|
||||
|
@@ -13,7 +13,7 @@ from auth.identity import Identity, Password
|
||||
from auth.jwtcodec import JWTCodec
|
||||
from auth.tokenstorage import TokenStorage
|
||||
from base.exceptions import (BaseHttpException, InvalidPassword, InvalidToken,
|
||||
ObjectNotExist, OperationNotAllowed, Unauthorized)
|
||||
ObjectNotExist, Unauthorized)
|
||||
from base.orm import local_session
|
||||
from base.resolvers import mutation, query
|
||||
from orm import Role, User
|
||||
@@ -113,7 +113,7 @@ async def register_by_email(_, _info, email: str, password: str = "", name: str
|
||||
with local_session() as session:
|
||||
user = session.query(User).filter(User.email == email).first()
|
||||
if user:
|
||||
raise OperationNotAllowed("User already exist")
|
||||
raise Unauthorized("User already exist")
|
||||
else:
|
||||
slug = generate_unique_slug(name)
|
||||
user = session.query(User).where(User.slug == slug).first()
|
||||
|
@@ -1,7 +1,7 @@
|
||||
from auth.authenticate import login_required
|
||||
from base.orm import local_session
|
||||
from base.resolvers import query, mutation
|
||||
from base.exceptions import OperationNotAllowed, ObjectNotExist
|
||||
from base.exceptions import ObjectNotExist, BaseHttpException
|
||||
from orm.collab import Collab, CollabAuthor
|
||||
from orm.shout import Shout
|
||||
from orm.user import User
|
||||
@@ -27,7 +27,7 @@ async def invite_coauthor(_, info, author: str, shout: int):
|
||||
else:
|
||||
c = session.query(Collab).where(Collab.shout == shout).one()
|
||||
if user.slug not in c.authors:
|
||||
raise OperationNotAllowed("you are not in authors list")
|
||||
raise BaseHttpException("you are not in authors list")
|
||||
else:
|
||||
invited_user = session.query(User).where(User.slug == author).one()
|
||||
c.invites.append(invited_user)
|
||||
@@ -47,7 +47,7 @@ async def remove_coauthor(_, info, author: str, shout: int):
|
||||
if not s:
|
||||
raise ObjectNotExist("invalid shout id")
|
||||
if user.slug != s.createdBy.slug:
|
||||
raise OperationNotAllowed("only onwer can remove coauthors")
|
||||
raise BaseHttpException("only onwer can remove coauthors")
|
||||
else:
|
||||
c = session.query(Collab).where(Collab.shout == shout).one()
|
||||
ca = session.query(CollabAuthor).where(c.shout == shout, c.author == author).one()
|
||||
@@ -80,4 +80,4 @@ async def accept_coauthor(_, info, shout: int):
|
||||
session.commit()
|
||||
return {}
|
||||
else:
|
||||
raise OperationNotAllowed("only invited can accept")
|
||||
raise BaseHttpException("only invited can accept")
|
||||
|
@@ -12,6 +12,8 @@ from orm.user import User
|
||||
from resolvers.zine.reactions import reactions_follow, reactions_unfollow
|
||||
from services.zine.gittask import GitTask
|
||||
from resolvers.inbox.chats import create_chat
|
||||
from services.inbox import MessagesStorage
|
||||
from orm.collab import Collab
|
||||
|
||||
|
||||
@mutation.field("createShout")
|
||||
|
@@ -20,7 +20,7 @@ def add_author_stat_columns(q):
|
||||
author_followers = aliased(AuthorFollower)
|
||||
author_following = aliased(AuthorFollower)
|
||||
shout_author_aliased = aliased(ShoutAuthor)
|
||||
user_rating_aliased = aliased(UserRating)
|
||||
# user_rating_aliased = aliased(UserRating)
|
||||
|
||||
q = q.outerjoin(shout_author_aliased).add_columns(
|
||||
func.count(distinct(shout_author_aliased.shout)).label('shouts_stat')
|
||||
@@ -40,11 +40,11 @@ def add_author_stat_columns(q):
|
||||
# func.sum(user_rating_aliased.value).label('rating_stat')
|
||||
# )
|
||||
|
||||
q = q.add_columns(literal(0).label('commented_stat'))
|
||||
# FIXME
|
||||
# q = q.outerjoin(Reaction, and_(Reaction.createdBy == User.id, Reaction.body.is_not(None))).add_columns(
|
||||
# func.count(distinct(Reaction.id)).label('commented_stat')
|
||||
# )
|
||||
# q = q.add_columns(literal(0).label('commented_stat'))
|
||||
|
||||
q = q.outerjoin(Reaction, and_(Reaction.createdBy == User.id, Reaction.body.is_not(None))).add_columns(
|
||||
func.count(distinct(Reaction.id)).label('commented_stat')
|
||||
)
|
||||
|
||||
q = q.group_by(User.id)
|
||||
|
||||
@@ -117,12 +117,18 @@ async def get_followed_authors(_, _info, slug) -> List[User]:
|
||||
return await followed_authors(slug)
|
||||
|
||||
|
||||
async def followed_authors(slug) -> List[User]:
|
||||
q = select(User)
|
||||
q = add_author_stat_columns(q)
|
||||
q = q.join(AuthorFollower).join(User, User.id == AuthorFollower.follower).where(User.slug == slug)
|
||||
|
||||
return get_authors_from_query(q)
|
||||
async def followed_authors(slug):
|
||||
with local_session() as session:
|
||||
user = session.query(User).where(User.slug == slug).first()
|
||||
q = select(User)
|
||||
q = add_author_stat_columns(q)
|
||||
aliased_user = aliased(User)
|
||||
q = q.join(AuthorFollower, AuthorFollower.author == user.id).join(
|
||||
aliased_user, aliased_user.id == AuthorFollower.follower
|
||||
).where(
|
||||
aliased_user.slug == slug
|
||||
)
|
||||
return get_authors_from_query(q)
|
||||
|
||||
|
||||
@query.field("userFollowers")
|
||||
@@ -145,10 +151,10 @@ async def get_user_roles(slug):
|
||||
user = session.query(User).where(User.slug == slug).first()
|
||||
roles = (
|
||||
session.query(Role)
|
||||
.options(joinedload(Role.permissions))
|
||||
.join(UserRole)
|
||||
.where(UserRole.user == user.id)
|
||||
.all()
|
||||
.options(joinedload(Role.permissions))
|
||||
.join(UserRole)
|
||||
.where(UserRole.user == user.id)
|
||||
.all()
|
||||
)
|
||||
|
||||
return roles
|
||||
@@ -175,8 +181,8 @@ async def rate_user(_, info, rated_userslug, value):
|
||||
with local_session() as session:
|
||||
rating = (
|
||||
session.query(UserRating)
|
||||
.filter(and_(UserRating.rater == user.slug, UserRating.user == rated_userslug))
|
||||
.first()
|
||||
.filter(and_(UserRating.rater == user.slug, UserRating.user == rated_userslug))
|
||||
.first()
|
||||
)
|
||||
if rating:
|
||||
rating.value = value
|
||||
|
Reference in New Issue
Block a user