-
Notifications
You must be signed in to change notification settings - Fork 3
Develop alert bot #123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Develop alert bot #123
Changes from 6 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |
| __pycache__/ | ||
| *.py[cod] | ||
| *$py.class | ||
|
|
||
| *.DS_Store | ||
| # C extensions | ||
| *.so | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -175,6 +175,7 @@ async def get_comments( | |
| user_id: int | None = None, | ||
| order_by: list[Literal["create_ts"]] = Query(default=[]), | ||
| unreviewed: bool = False, | ||
| review_mode: Literal["all", "pending"] = "all", # вот ключ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. А чем отличается от unreviewed?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. не стал переписывать unreviewd т.к возможно какаято логика завязана. Новый возвращает только pending без DISSMISED и еще чемто отлтичается
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. лучше тогда, если уж так начал сделать, сделать явно запрос по любому статусу DISMISSED, PENDING, REVIEW Если они не проставлены, то возвращаются все Но, чтобы можно было вернуть, чисто по статусу одному, нужны скоупы
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. короче очень костыльно, если твоим способом лучше так, как я предложил, но нужно это будет согласовать с фронтом |
||
| user=Depends(UnionAuth(scopes=["rating.comment.review"], auto_error=False, allow_none=True)), | ||
| ) -> CommentGetAll: | ||
| """ | ||
|
|
@@ -194,43 +195,64 @@ async def get_comments( | |
|
|
||
| `unreviewed` - вернет все непроверенные комментарии, если True. По дефолту False. | ||
| """ | ||
| comments = Comment.query(session=db.session).all() | ||
| if not comments: | ||
| raise ObjectNotFound(Comment, 'all') | ||
| if "rating.comment.review" in [scope['name'] for scope in user.get('session_scopes')]: | ||
| result = CommentGetAllWithAllInfo(limit=limit, offset=offset, total=len(comments)) | ||
| comment_validator = CommentGetWithAllInfo | ||
| elif user.get('id') == user_id: | ||
| result = CommentGetAllWithStatus(limit=limit, offset=offset, total=len(comments)) | ||
| comment_validator = CommentGetWithStatus | ||
|
|
||
| if review_mode == "pending": # Для бота либо без проблем получить все Pending | ||
| query = Comment.query(session=db.session) | ||
| # пусто или нет | ||
| query = query.filter( | ||
| Comment.review_status == ReviewStatus.PENDING, | ||
| ) | ||
|
|
||
| comments = query.all() | ||
| if not comments: | ||
| return CommentGetAll(polls=[], limit=limit, offset=offset, total=0) | ||
|
||
|
|
||
| paginated = comments[offset : offset + limit] | ||
| paginated.sort(key=lambda c: c.create_ts, reverse=True) | ||
|
|
||
| return CommentGetAll(comments=paginated, limit=limit, offset=offset, total=len(comments)) | ||
|
|
||
| else: | ||
| result = CommentGetAll(limit=limit, offset=offset, total=len(comments)) | ||
| comment_validator = CommentGet | ||
| result.comments = comments | ||
| if user_id is not None: | ||
| result.comments = [comment for comment in result.comments if comment.user_id == user_id] | ||
|
|
||
| if lecturer_id is not None: | ||
| result.comments = [comment for comment in result.comments if comment.lecturer_id == lecturer_id] | ||
|
|
||
| if unreviewed: | ||
| if not user: | ||
| raise ForbiddenAction(Comment) | ||
| comments = Comment.query(session=db.session).all() | ||
| if not comments: | ||
| raise ObjectNotFound(Comment, 'all') | ||
|
|
||
| if "rating.comment.review" in [scope['name'] for scope in user.get('session_scopes')]: | ||
| result.comments = [comment for comment in result.comments if comment.review_status is ReviewStatus.PENDING] | ||
| result = CommentGetAllWithAllInfo(limit=limit, offset=offset, total=len(comments)) | ||
| comment_validator = CommentGetWithAllInfo | ||
| elif user.get('id') == user_id: | ||
| result = CommentGetAllWithStatus(limit=limit, offset=offset, total=len(comments)) | ||
| comment_validator = CommentGetWithStatus | ||
| else: | ||
| raise ForbiddenAction(Comment) | ||
| else: | ||
| result.comments = [comment for comment in result.comments if comment.review_status is ReviewStatus.APPROVED] | ||
| result = CommentGetAll(limit=limit, offset=offset, total=len(comments)) | ||
| comment_validator = CommentGet | ||
| result.comments = comments | ||
| if user_id is not None: | ||
| result.comments = [comment for comment in result.comments if comment.user_id == user_id] | ||
|
|
||
| if lecturer_id is not None: | ||
| result.comments = [comment for comment in result.comments if comment.lecturer_id == lecturer_id] | ||
|
|
||
| if unreviewed: | ||
| if not user: | ||
| raise ForbiddenAction(Comment) | ||
| if "rating.comment.review" in [scope['name'] for scope in user.get('session_scopes')]: | ||
| result.comments = [ | ||
| comment for comment in result.comments if comment.review_status is ReviewStatus.PENDING | ||
| ] | ||
| else: | ||
| raise ForbiddenAction(Comment) | ||
| else: | ||
| result.comments = [comment for comment in result.comments if comment.review_status is ReviewStatus.APPROVED] | ||
|
|
||
| result.comments = result.comments[offset : limit + offset] | ||
| result.comments = result.comments[offset : limit + offset] | ||
|
|
||
| if "create_ts" in order_by: | ||
| if "create_ts" in order_by: | ||
| result.comments.sort(key=lambda comment: comment.create_ts, reverse=True) | ||
| result.total = len(result.comments) | ||
| result.comments = [comment_validator.model_validate(comment) for comment in result.comments] | ||
| result.comments.sort(key=lambda comment: comment.create_ts, reverse=True) | ||
| result.total = len(result.comments) | ||
| result.comments = [comment_validator.model_validate(comment) for comment in result.comments] | ||
| result.comments.sort(key=lambda comment: comment.create_ts, reverse=True) | ||
| return result | ||
| return result | ||
|
|
||
|
|
||
| @comment.patch("/{uuid}/review", response_model=CommentGetWithAllInfo) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.