From f504761822a50067889d9d7796a8d863783935fe Mon Sep 17 00:00:00 2001 From: luap42 <21335202+luap42@users.noreply.github.com> Date: Sun, 2 Aug 2020 18:17:06 +0200 Subject: [PATCH 1/3] Fixing meta/277029 --- app/controllers/votes_controller.rb | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/app/controllers/votes_controller.rb b/app/controllers/votes_controller.rb index a751c84a5..12d10790e 100644 --- a/app/controllers/votes_controller.rb +++ b/app/controllers/votes_controller.rb @@ -13,16 +13,18 @@ def create recent_votes = Vote.where(created_at: 24.hours.ago..Time.now, user: current_user).count max_votes_per_day = SiteSetting['FreeVotes'] + (@current_user.reputation - SiteSetting['NewUserInitialRep']) - if recent_votes >= max_votes_per_day - vote_limit_msg = 'You have used your daily vote limit of ' + recent_votes.to_s + 'votes. Gain more reputation' \ - ' or come back tomorrow to continue voting.' + unless post&.parent&.user&.id == current_user.id + if recent_votes >= max_votes_per_day + vote_limit_msg = 'You have used your daily vote limit of ' + recent_votes.to_s + 'votes. Gain more reputation' \ + ' or come back tomorrow to continue voting.' - if max_votes_per_day <= 0 - vote_limit_msg = 'You need to gain some reputation on this site before you can start voting.' - end + if max_votes_per_day <= 0 + vote_limit_msg = 'You need to gain some reputation on this site before you can start voting.' + end - render json: { status: 'failed', message: vote_limit_msg }, status: 403 - return + render json: { status: 'failed', message: vote_limit_msg }, status: 403 + return + end end destroyed = post.votes.where(user: current_user).destroy_all From a13f301962d2c57a904631d966c3b2a67ba8bde7 Mon Sep 17 00:00:00 2001 From: ArtOfCode- Date: Thu, 6 Aug 2020 23:04:22 +0100 Subject: [PATCH 2/3] Don't load user --- app/controllers/votes_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/votes_controller.rb b/app/controllers/votes_controller.rb index 12d10790e..5b8209717 100644 --- a/app/controllers/votes_controller.rb +++ b/app/controllers/votes_controller.rb @@ -13,7 +13,7 @@ def create recent_votes = Vote.where(created_at: 24.hours.ago..Time.now, user: current_user).count max_votes_per_day = SiteSetting['FreeVotes'] + (@current_user.reputation - SiteSetting['NewUserInitialRep']) - unless post&.parent&.user&.id == current_user.id + unless post.parent&.user_id == current_user.id if recent_votes >= max_votes_per_day vote_limit_msg = 'You have used your daily vote limit of ' + recent_votes.to_s + 'votes. Gain more reputation' \ ' or come back tomorrow to continue voting.' From 8b3481f7bfd5997f4e3dbe3cced5b92751b83fd5 Mon Sep 17 00:00:00 2001 From: ArtOfCode- Date: Thu, 6 Aug 2020 23:06:54 +0100 Subject: [PATCH 3/3] Rubocop --- .rubocop.yml | 2 +- app/controllers/advertisement_controller.rb | 3 +-- app/controllers/users_controller.rb | 2 -- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 73506c13e..d84c1b13d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -27,7 +27,7 @@ Lint/StructNewOverride: Enabled: true Metrics/AbcSize: - Max: 50 + Enabled: false Metrics/BlockLength: Max: 30 Metrics/ClassLength: diff --git a/app/controllers/advertisement_controller.rb b/app/controllers/advertisement_controller.rb index 579f9aaf3..8477c2b48 100644 --- a/app/controllers/advertisement_controller.rb +++ b/app/controllers/advertisement_controller.rb @@ -3,7 +3,6 @@ # Neccessary due to rmagick # rubocop:disable Metrics/ClassLength # rubocop:disable Metrics/MethodLength -# rubocop:disable Metrics/AbcSize # rubocop:disable Metrics/BlockLength class AdvertisementController < ApplicationController include Magick @@ -359,5 +358,5 @@ def article_ad(article) end # rubocop:enable Metrics/MethodLength # rubocop:enable Metrics/ClassLength -# rubocop:enable Metrics/AbcSize + # rubocop:enable Metrics/BlockLength diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 908e23793..27cadcfd6 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -49,7 +49,6 @@ def posts end end - # rubocop:disable Metrics/AbcSize def activity @posts = Post.undeleted.where(user: @user).count @comments = Comment.undeleted.where(user: @user).where(post: Post.undeleted).count @@ -118,7 +117,6 @@ def full_log render layout: 'without_sidebar' end - # rubocop:enable Metrics/AbcSize def destroy if @user.votes.count > 100