rubocop: fix various Rubocop warnings.

This commit is contained in:
evazion
2021-06-16 18:24:42 -05:00
parent cfe471e0b5
commit 07e23204b6
99 changed files with 412 additions and 374 deletions

View File

@@ -90,9 +90,9 @@ class ApplicationController < ActionController::Base
render_error_page(401, exception, template: "sessions/new")
when ActionController::InvalidAuthenticityToken, ActionController::UnpermittedParameters, ActionController::InvalidCrossOriginRequest
render_error_page(403, exception)
when ActiveSupport::MessageVerifier::InvalidSignature # raised by `find_signed!`
render_error_page(403, exception, template: "static/access_denied", message: "Access denied")
when User::PrivilegeError, Pundit::NotAuthorizedError
when ActiveSupport::MessageVerifier::InvalidSignature, # raised by `find_signed!`
User::PrivilegeError,
Pundit::NotAuthorizedError
render_error_page(403, exception, template: "static/access_denied", message: "Access denied")
when ActiveRecord::RecordNotFound
render_error_page(404, exception, message: "That record was not found.")
@@ -183,7 +183,7 @@ class ApplicationController < ActionController::Base
return if CurrentUser.user.is_anonymous?
last_authenticated_at = session[:last_authenticated_at]
if last_authenticated_at.blank? || Time.parse(last_authenticated_at) < 60.minutes.ago
if last_authenticated_at.blank? || Time.zone.parse(last_authenticated_at) < 60.minutes.ago
redirect_to confirm_password_session_path(url: request.fullpath)
end
end
@@ -197,7 +197,7 @@ class ApplicationController < ActionController::Base
params[:search] ||= ActionController::Parameters.new
deep_reject_blank = lambda do |hash|
hash.reject { |k, v| v.blank? || (v.is_a?(Hash) && deep_reject_blank.call(v).blank?) }
hash.reject { |_k, v| v.blank? || (v.is_a?(Hash) && deep_reject_blank.call(v).blank?) }
end
nonblank_search_params = deep_reject_blank.call(params[:search])

View File

@@ -56,7 +56,7 @@ class ArtistsController < ApplicationController
def destroy
@artist = authorize Artist.find(params[:id])
@artist.update_attribute(:is_deleted, true)
@artist.update(is_deleted: true)
redirect_to(artist_path(@artist), :notice => "Artist deleted")
end

View File

@@ -3,7 +3,7 @@ class CommentVotesController < ApplicationController
def index
@comment_votes = authorize CommentVote.visible(CurrentUser.user).paginated_search(params, count_pages: true)
@comment_votes = @comment_votes.includes(:user, comment: [:creator, post: [:uploader]]) if request.format.html?
@comment_votes = @comment_votes.includes(:user, comment: [:creator, { post: [:uploader] }]) if request.format.html?
respond_with(@comment_votes)
end

View File

@@ -82,7 +82,7 @@ class CommentsController < ApplicationController
def index_by_post
@limit = params.fetch(:limit, 20)
@posts = Post.where("last_comment_bumped_at IS NOT NULL").user_tag_match(params[:tags]).reorder("last_comment_bumped_at DESC NULLS LAST").paginate(params[:page], limit: @limit, search_count: params[:search])
@posts = Post.where.not(last_comment_bumped_at: nil).user_tag_match(params[:tags]).reorder("last_comment_bumped_at DESC NULLS LAST").paginate(params[:page], limit: @limit, search_count: params[:search])
if request.format.html?
@posts = @posts.includes(comments: [:creator])

View File

@@ -8,33 +8,25 @@ class DelayedJobsController < ApplicationController
def cancel
@job = authorize Delayed::Job.find(params[:id]), policy_class: DelayedJobPolicy
if !@job.locked_at?
@job.fail!
end
@job.fail! unless @job.locked_at?
respond_with(@job)
end
def retry
@job = authorize Delayed::Job.find(params[:id]), policy_class: DelayedJobPolicy
if !@job.locked_at?
@job.update(failed_at: nil, attempts: 0)
end
@job.update(failed_at: nil, attempts: 0) unless @job.locked_at?
respond_with(@job)
end
def run
@job = authorize Delayed::Job.find(params[:id]), policy_class: DelayedJobPolicy
if !@job.locked_at?
@job.update(run_at: Time.now)
end
@job.update(run_at: Time.zone.now) unless @job.locked_at?
respond_with(@job)
end
def destroy
@job = authorize Delayed::Job.find(params[:id]), policy_class: DelayedJobPolicy
if !@job.locked_at?
@job.destroy
end
@job.destroy unless @job.locked_at?
respond_with(@job)
end
end

View File

@@ -2,7 +2,8 @@ class DtextPreviewsController < ApplicationController
def create
@inline = params[:inline].to_s.truthy?
@disable_mentions = params[:disable_mentions].to_s.truthy?
@html = helpers.format_text(params[:body], inline: @inline, disable_mentions: @disable_mentions)
render inline: "<%= format_text(params[:body], inline: @inline, disable_mentions: @disable_mentions) %>"
render html: @html
end
end

View File

@@ -79,7 +79,7 @@ class ForumTopicsController < ApplicationController
def mark_all_as_read
authorize ForumTopic
CurrentUser.user.update_attribute(:last_forum_read_at, Time.now)
CurrentUser.user.update(last_forum_read_at: Time.zone.now)
ForumTopicVisit.prune!(CurrentUser.user)
redirect_to forum_topics_path, :notice => "All topics marked as read"
end

View File

@@ -4,9 +4,10 @@ class IpAddressesController < ApplicationController
def index
@ip_addresses = authorize IpAddress.visible(CurrentUser.user).paginated_search(params)
if search_params[:group_by] == "ip_addr"
case search_params[:group_by]
when "ip_addr"
@ip_addresses = @ip_addresses.group_by_ip_addr(search_params[:ipv4_masklen], search_params[:ipv6_masklen])
elsif search_params[:group_by] == "user"
when "user"
@ip_addresses = @ip_addresses.group_by_user.includes(:user)
else
@ip_addresses = @ip_addresses.includes(:user, :model)

View File

@@ -4,7 +4,7 @@ module Maintenance
class VerificationError < StandardError; end
before_action :validate_sig, :only => [:destroy]
rescue_from VerificationError, :with => :render_403
rescue_from VerificationError, with: :render_verification_error
def show
end
@@ -17,15 +17,15 @@ module Maintenance
private
def render_403
render plain: "", :status => 403
def render_verification_error
render plain: "", status: 403
end
def validate_sig
verifier = ActiveSupport::MessageVerifier.new(Danbooru.config.email_key, digest: "SHA256", serializer: JSON)
calculated_sig = verifier.generate(params[:user_id].to_s)
if calculated_sig != params[:sig]
raise VerificationError.new
raise VerificationError, "Invalid signature"
end
end
end

View File

@@ -35,8 +35,6 @@ class PoolVersionsController < ApplicationController
end
def check_availabililty
if !PoolVersion.enabled?
raise NotImplementedError.new("Archive service is not configured. Pool versions are not saved.")
end
raise NotImplementedError, "Archive service is not configured. Pool versions are not saved." unless PoolVersion.enabled?
end
end

View File

@@ -54,7 +54,7 @@ class PoolsController < ApplicationController
def destroy
@pool = authorize Pool.find(params[:id])
@pool.update_attribute(:is_deleted, true)
@pool.update(is_deleted: true)
@pool.create_mod_action_for_delete
flash[:notice] = "Pool deleted"
respond_with(@pool)
@@ -62,7 +62,7 @@ class PoolsController < ApplicationController
def undelete
@pool = authorize Pool.find(params[:id])
@pool.update_attribute(:is_deleted, false)
@pool.update(is_deleted: false)
@pool.create_mod_action_for_undelete
flash[:notice] = "Pool undeleted"
respond_with(@pool)

View File

@@ -37,8 +37,7 @@ class PostVersionsController < ApplicationController
end
def check_availabililty
if !PostVersion.enabled?
raise NotImplementedError.new("Archive service is not configured. Post versions are not saved.")
end
return if PostVersion.enabled?
raise NotImplementedError, "Archive service is not configured. Post versions are not saved."
end
end

View File

@@ -116,7 +116,7 @@ class PostsController < ApplicationController
render :template => "static/error", :status => 500
else
response_params = {:q => params[:tags_query], :pool_id => params[:pool_id], :favgroup_id => params[:favgroup_id]}
response_params.reject! {|key, value| value.blank?}
response_params.reject! {|_key, value| value.blank?}
redirect_to post_path(post, response_params)
end
end

View File

@@ -4,7 +4,7 @@ class RecommendedPostsController < ApplicationController
def index
limit = params.fetch(:limit, 100).to_i.clamp(0, 200)
@recs = RecommenderService.search(search_params).take(limit)
@posts = @recs.map { |rec| rec[:post] }
@posts = @recs.pluck(:post)
respond_with(@recs)
end

View File

@@ -33,7 +33,7 @@ class StaticController < ApplicationController
def sitemap_index
@sitemap = params[:sitemap]
@limit = params.fetch(:limit, 10000).to_i
@limit = params.fetch(:limit, 10_000).to_i
case @sitemap
when "artists"

View File

@@ -45,7 +45,7 @@ class UploadsController < ApplicationController
def preprocess
authorize Upload
@upload, @remote_size = UploadService::ControllerHelper.prepare(
url: params.dig(:upload, :source), file: params.dig(:upload, :file), ref: params.dig(:upload, :referer_url),
url: params.dig(:upload, :source), file: params.dig(:upload, :file), ref: params.dig(:upload, :referer_url)
)
render body: nil
end