Skip to content

Удаление своего комментария #99

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

Closed
wants to merge 21 commits into from
Closed
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
17 changes: 14 additions & 3 deletions rating_api/routes/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,16 +234,27 @@ async def review_comment(

@comment.delete("/{uuid}", response_model=StatusResponseModel)
async def delete_comment(

Choose a reason for hiding this comment

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

[КРИТИЧНО] Потенциальное исключение при отсутствии комментария

Choose a reason for hiding this comment

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

[КРИТИЧНО] Неправильное использование Depends

Choose a reason for hiding this comment

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

[УЛУЧШЕНИЕ] Использование filter_by вместо filter

Choose a reason for hiding this comment

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

[ВАЖНО] Проверка наличия скоупа для удаления комментариев

Choose a reason for hiding this comment

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

[УЛУЧШЕНИЕ] Неоптимальное форматирование строки

Choose a reason for hiding this comment

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

[ВАЖНО] Добавьте аннотацию типа для параметра user

Choose a reason for hiding this comment

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

[КРИТИЧНО] Потенциальная уязвимость при использовании one_or_none

Choose a reason for hiding this comment

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

[УЛУЧШЕНИЕ] Использование user=Depends(UnionAuth(auto_error=True, allow_none=False))

Choose a reason for hiding this comment

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

[УЛУЧШЕНИЕ] Переименование переменной

Choose a reason for hiding this comment

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

[СТИЛЬ] Использование констант для строк

Choose a reason for hiding this comment

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

[УЛУЧШЕНИЕ] Избыточность переменной user

Choose a reason for hiding this comment

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

[УЛУЧШЕНИЕ] Использование более информативных имен переменных

Choose a reason for hiding this comment

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

[КРИТИЧНО] Неправильное использование переменной user

Choose a reason for hiding this comment

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

[УЛУЧШЕНИЕ] Упрощение логики проверки наличия скоупа

Choose a reason for hiding this comment

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

[УЛУЧШЕНИЕ] Избегайте дублирования кода

uuid: UUID, _=Depends(UnionAuth(scopes=["rating.comment.delete"], allow_none=False, auto_error=True))
uuid: UUID,

Choose a reason for hiding this comment

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

[СТИЛЬ] Переименование переменной для ясности

Choose a reason for hiding this comment

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

[КРИТИЧНО] Некорректное использование переменной comment

Choose a reason for hiding this comment

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

[КРИТИЧНО] Логическая ошибка в проверке прав

user=Depends(UnionAuth(auto_error=True, allow_none=False)),
):
"""

Choose a reason for hiding this comment

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

[ВАЖНО] Логическая ошибка в проверке прав

Choose a reason for hiding this comment

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

[СТИЛЬ] Неправильное использование raise

Choose a reason for hiding this comment

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

[КРИТИЧНО] Логическая ошибка в проверке прав доступа

Choose a reason for hiding this comment

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

[УЛУЧШЕНИЕ] Улучшение читаемости кода

Choose a reason for hiding this comment

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

[ВАЖНО] Неэффективное использование памяти

Choose a reason for hiding this comment

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

[УЛУЧШЕНИЕ] Дублирование кода

Scopes: `["rating.comment.delete"]`

Choose a reason for hiding this comment

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

[КРИТИЧНО] Потенциальная ошибка при отсутствии прав

Choose a reason for hiding this comment

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

[ВАЖНО] Неэффективный запрос к базе данных

Choose a reason for hiding this comment

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

[ВАЖНО] Упростите проверку наличия скоупа

Choose a reason for hiding this comment

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

[ВАЖНО] Логическая ошибка в проверке прав

Choose a reason for hiding this comment

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

[УЛУЧШЕНИЕ] Использование констант для строк

Choose a reason for hiding this comment

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

[УЛУЧШЕНИЕ] Избыточная проверка

Choose a reason for hiding this comment

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

[КРИТИЧНО] Логическая ошибка при проверке прав


Choose a reason for hiding this comment

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

[ВАЖНО] Потенциальная утечка ресурсов

Choose a reason for hiding this comment

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

[УЛУЧШЕНИЕ] Использование запроса к БД для получения комментария

Choose a reason for hiding this comment

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

[УЛУЧШЕНИЕ] Использование более конкретного имени переменной

Choose a reason for hiding this comment

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

[КРИТИЧНО] Неправильное использование Depends

Choose a reason for hiding this comment

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

[УЛУЧШЕНИЕ] Переменная user должна быть названа более информативно

Choose a reason for hiding this comment

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

[УЛУЧШЕНИЕ] Использование имени переменной user

Удаляет комментарий по его UUID в базе данных RatingAPI

Choose a reason for hiding this comment

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

[КРИТИЧНО] Потенциальная уязвимость

Choose a reason for hiding this comment

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

[СТИЛЬ] Нарушение стилевых соглашений

Choose a reason for hiding this comment

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

[КРИТИЧНО] Неправильное использование зависимостей

Choose a reason for hiding this comment

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

[ВАЖНО] Проверка наличия скоупа

Choose a reason for hiding this comment

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

[КРИТИЧНО] Логическая ошибка в проверке прав

Choose a reason for hiding this comment

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

[КРИТИЧНО] Неправильное именование переменной

Choose a reason for hiding this comment

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

[УЛУЧШЕНИЕ] Использование переменной для хранения результата проверки скоупов

Choose a reason for hiding this comment

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

[СТИЛЬ] Форматирование кода

Choose a reason for hiding this comment

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

[УЛУЧШЕНИЕ] Использование более информативных имен переменных

Choose a reason for hiding this comment

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

[СТИЛЬ] Использование list comprehension для проверки скоупа

Choose a reason for hiding this comment

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

[ВАЖНО] Неправильное использование переменной user

"""
check_comment = Comment.get(session=db.session, id=uuid)
if check_comment is None:
comment = Comment.get(uuid, session=db.session)

Choose a reason for hiding this comment

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

[СТИЛЬ] Форматирование строки

if comment is None:

Choose a reason for hiding this comment

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

[УЛУЧШЕНИЕ] Дублирование кода при возврате ответа

Choose a reason for hiding this comment

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

[СТИЛЬ] Неправильное форматирование возвращаемого значения

raise ObjectNotFound(Comment, uuid)
# Наличие скоупа для удаления любых комментариев
has_delete_scope = "rating.comment.delete" in [scope['name'] for scope in user.get('session_scopes', [])]

Choose a reason for hiding this comment

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

[УЛУЧШЕНИЕ] Неэффективный способ проверки наличия скоупа

Choose a reason for hiding this comment

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

[СТИЛЬ] Условие проверки прав обычного пользователя

Choose a reason for hiding this comment

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

[КРИТИЧНО] Отсутствие обработки исключений при запросе к базе данных

Choose a reason for hiding this comment

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

[КРИТИЧНО] Логическая ошибка в условии

Choose a reason for hiding this comment

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

[КРИТИЧНО] Проверка наличия комментария

# Если нет привилегии - проверяем права обычного пользователя

Choose a reason for hiding this comment

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

[УЛУЧШЕНИЕ] Упростите условие проверки прав обычного пользователя

Choose a reason for hiding this comment

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

[КРИТИЧНО] Логическая ошибка в условии

Choose a reason for hiding this comment

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

[УЛУЧШЕНИЕ] Дублирование логики проверки прав

if not has_delete_scope:
if comment.is_anonymous:

Choose a reason for hiding this comment

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

[ВАЖНО] Логическая ошибка в условии проверки прав

Choose a reason for hiding this comment

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

[ВАЖНО] Проверка наличия комментария не эффективна

Choose a reason for hiding this comment

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

[ВАЖНО] Проверка анонимности комментария

Choose a reason for hiding this comment

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

[УЛУЧШЕНИЕ] Удаление избыточного кода

raise ForbiddenAction(Comment)

Choose a reason for hiding this comment

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

[КРИТИЧНО] Логическая ошибка в проверке прав доступа

Choose a reason for hiding this comment

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

[КРИТИЧНО] Проверка прав доступа

Choose a reason for hiding this comment

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

[СТИЛЬ] Улучшение читаемости кода


if not has_delete_scope or comment.user_id != user.id:
raise ForbiddenAction(Comment)

Choose a reason for hiding this comment

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

[СТИЛЬ] Улучшение читаемости кода

Comment.delete(session=db.session, id=uuid)

Choose a reason for hiding this comment

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

[СТИЛЬ] Форматирование строки возврата

Choose a reason for hiding this comment

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

[УЛУЧШЕНИЕ] Логика проверки прав доступа

Choose a reason for hiding this comment

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

[УЛУЧШЕНИЕ] Логика проверки прав доступа

Choose a reason for hiding this comment

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

[КРИТИЧНО] Проверка прав доступа

Choose a reason for hiding this comment

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

[ВАЖНО] Проверка на удаление комментария


Choose a reason for hiding this comment

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

[ВАЖНО] Логика проверки прав доступа сложна и трудночитаема

Choose a reason for hiding this comment

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

[УЛУЧШЕНИЕ] Удаление избыточного кода

return StatusResponseModel(
Expand Down
Loading