From dfc0af21ee7ff0fbcd540d64fe958de360b3f052 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Mon, 9 May 2022 12:40:01 +0100 Subject: [PATCH] Lower ratelimit --- app/blueprints/packages/reviews.py | 10 +++++----- app/models/users.py | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/blueprints/packages/reviews.py b/app/blueprints/packages/reviews.py index e5336c40..aae705d8 100644 --- a/app/blueprints/packages/reviews.py +++ b/app/blueprints/packages/reviews.py @@ -54,11 +54,11 @@ def review(package): flash(gettext("You can't review your own package!"), "danger") return redirect(package.getURL("packages.view")) - if not current_user.canReviewRL(): - flash(gettext("You've reviewed too many packages recently. Please wait before trying again, and consider making your reviews more detailed"), "danger") - return redirect(package.getURL("packages.view")) - review = PackageReview.query.filter_by(package=package, author=current_user).first() + can_review = review is not None or current_user.canReviewRL() + + if not can_review: + flash(gettext("You've reviewed too many packages recently. Please wait before trying again, and consider making your reviews more detailed"), "danger") form = ReviewForm(formdata=request.form, obj=review) @@ -69,7 +69,7 @@ def review(package): form.comment.data = review.thread.replies[0].comment # Validate and submit - elif form.validate_on_submit(): + elif can_review and form.validate_on_submit(): was_new = False if not review: was_new = True diff --git a/app/models/users.py b/app/models/users.py index 23de1a33..a6846098 100644 --- a/app/models/users.py +++ b/app/models/users.py @@ -281,12 +281,12 @@ class User(db.Model, UserMixin): five_mins_ago = datetime.datetime.utcnow() - datetime.timedelta(minutes=5) if PackageReview.query.filter_by(author=self) \ - .filter(PackageReview.created_at > five_mins_ago).count() >= 4 * factor: + .filter(PackageReview.created_at > five_mins_ago).count() > 2 * factor: return False hour_ago = datetime.datetime.utcnow() - datetime.timedelta(hours=1) return PackageReview.query.filter_by(author=self) \ - .filter(PackageReview.created_at > hour_ago).count() < 30 * factor + .filter(PackageReview.created_at > hour_ago).count() < 10 * factor def __eq__(self, other):