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

this comment time and create minutes #65

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
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
34 changes: 16 additions & 18 deletions rating_api/routes/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,22 @@ async def create_comment(lecturer_id: int, comment_info: CommentPost, user=Depen
if not lecturer:
raise ObjectNotFound(Lecturer, lecturer_id)

has_create_scope = "rating.comment.import" in [scope['name'] for scope in user.get('session_scopes')]
if (comment_info.create_ts or comment_info.update_ts) and not has_create_scope:
raise ForbiddenAction(Comment)

if not has_create_scope:
user_comments: list[LecturerUserComment] = (
LecturerUserComment.query(session=db.session).filter(LecturerUserComment.user_id == user.get("id")).all()
)
for user_comment in user_comments:
if datetime.datetime.utcnow() - user_comment.update_ts < datetime.timedelta(
minutes=settings.COMMENT_CREATE_FREQUENCY_IN_MINUTES
):
raise TooManyCommentRequests(
dtime=user_comment.update_ts
+ datetime.timedelta(minutes=settings.COMMENT_CREATE_FREQUENCY_IN_MINUTES)
- datetime.datetime.utcnow()
)

Copy link
Contributor

Choose a reason for hiding this comment

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

Не корректное разрешение коллизии. Необходимо сохранить проверку скоупов на задание ts

user_comments: list[LecturerUserComment] = (
LecturerUserComment.query(session=db.session).filter(LecturerUserComment.user_id == user.get("id")).all()
)
for user_comment in user_comments:
if datetime.datetime.now().month - user_comment.update_ts < datetime.timedelta(
month=settings.COMMENT_CREATE_FREQUENCY_IN_MONTH
) and datetime.datetime.now().year != datetime.timedelta(
year=settings.COMMENT_CREATE_FREQUENCY_IN_YEAR
Copy link
Contributor

Choose a reason for hiding this comment

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

Частота в годах не нужна

):
raise TooManyCommentRequests(
dtime=user_comment.update_ts
+ datetime.timedelta(month=settings.COMMENT_CREATE_FREQUENCY_IN_MONTH)
+ datetime.timedelta(year=settings.COMMENT_CREATE_FREQUENCY_IN_YEAR)
- datetime.datetime.now().month
- datetime.datetime.now().year
)
# Сначала добавляем с user_id, который мы получили при авторизации,
# в LecturerUserComment, чтобы нельзя было слишком быстро добавлять комментарии
LecturerUserComment.create(session=db.session, lecturer_id=lecturer_id, user_id=user.get('id'))
Copy link
Contributor

Choose a reason for hiding this comment

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

Создавать запись о комментарии юзера нужно с точностью до месяца

Expand Down
Loading