Skip to content
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

Req. scope for comment creation #85

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions rating_api/routes/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@


@comment.post("", response_model=CommentGet)
async def create_comment(lecturer_id: int, comment_info: CommentPost, user=Depends(UnionAuth())) -> CommentGet:
async def create_comment(
lecturer_id: int, comment_info: CommentPost, user=Depends(UnionAuth(scopes=["rating.comment.create"]))
) -> CommentGet:
"""
Scopes: `["rating.comment.import"]`
Scopes: `["rating.comment.create"<, "rating.comment.import">]`
Создает комментарий к преподавателю в базе данных RatingAPI
Для создания комментария нужно быть авторизованным

Expand Down
4 changes: 3 additions & 1 deletion rating_api/routes/lecturer.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ async def get_lecturers(
if comment.review_status is ReviewStatus.APPROVED
]
if "comments" in info and approved_comments:
lecturer_to_result.comments = sorted(approved_comments, key=lambda comment: comment.create_ts, reverse=True)
lecturer_to_result.comments = sorted(
approved_comments, key=lambda comment: comment.create_ts, reverse=True
)
Comment on lines +138 to +140
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Исключительно линтинг, логика не была затронута

if "mark" in info and approved_comments:
lecturer_to_result.mark_freebie = sum([comment.mark_freebie for comment in approved_comments]) / len(
approved_comments
Expand Down
Loading