Fix `Style/CombinableLoops` cop (#27429)

This commit is contained in:
Matt Jankowski 2023-10-16 10:36:28 -04:00 committed by GitHub
parent c91c0175db
commit 08a376cbcb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 14 deletions

View File

@ -517,12 +517,6 @@ Style/ClassVars:
Exclude: Exclude:
- 'config/initializers/devise.rb' - 'config/initializers/devise.rb'
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/CombinableLoops:
Exclude:
- 'app/models/form/custom_emoji_batch.rb'
- 'app/models/form/ip_block_batch.rb'
# This cop supports safe autocorrection (--autocorrect). # This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowedVars. # Configuration parameters: AllowedVars.
Style/FetchEnvVar: Style/FetchEnvVar:

View File

@ -34,7 +34,7 @@ class Form::CustomEmojiBatch
end end
def update! def update!
custom_emojis.each { |custom_emoji| authorize(custom_emoji, :update?) } verify_authorization(:update?)
category = if category_id.present? category = if category_id.present?
CustomEmojiCategory.find(category_id) CustomEmojiCategory.find(category_id)
@ -49,7 +49,7 @@ class Form::CustomEmojiBatch
end end
def list! def list!
custom_emojis.each { |custom_emoji| authorize(custom_emoji, :update?) } verify_authorization(:update?)
custom_emojis.each do |custom_emoji| custom_emojis.each do |custom_emoji|
custom_emoji.update(visible_in_picker: true) custom_emoji.update(visible_in_picker: true)
@ -58,7 +58,7 @@ class Form::CustomEmojiBatch
end end
def unlist! def unlist!
custom_emojis.each { |custom_emoji| authorize(custom_emoji, :update?) } verify_authorization(:update?)
custom_emojis.each do |custom_emoji| custom_emojis.each do |custom_emoji|
custom_emoji.update(visible_in_picker: false) custom_emoji.update(visible_in_picker: false)
@ -67,7 +67,7 @@ class Form::CustomEmojiBatch
end end
def enable! def enable!
custom_emojis.each { |custom_emoji| authorize(custom_emoji, :enable?) } verify_authorization(:enable?)
custom_emojis.each do |custom_emoji| custom_emojis.each do |custom_emoji|
custom_emoji.update(disabled: false) custom_emoji.update(disabled: false)
@ -76,7 +76,7 @@ class Form::CustomEmojiBatch
end end
def disable! def disable!
custom_emojis.each { |custom_emoji| authorize(custom_emoji, :disable?) } verify_authorization(:disable?)
custom_emojis.each do |custom_emoji| custom_emojis.each do |custom_emoji|
custom_emoji.update(disabled: true) custom_emoji.update(disabled: true)
@ -85,7 +85,7 @@ class Form::CustomEmojiBatch
end end
def copy! def copy!
custom_emojis.each { |custom_emoji| authorize(custom_emoji, :copy?) } verify_authorization(:copy?)
custom_emojis.each do |custom_emoji| custom_emojis.each do |custom_emoji|
copied_custom_emoji = custom_emoji.copy! copied_custom_emoji = custom_emoji.copy!
@ -94,11 +94,15 @@ class Form::CustomEmojiBatch
end end
def delete! def delete!
custom_emojis.each { |custom_emoji| authorize(custom_emoji, :destroy?) } verify_authorization(:destroy?)
custom_emojis.each do |custom_emoji| custom_emojis.each do |custom_emoji|
custom_emoji.destroy custom_emoji.destroy
log_action :destroy, custom_emoji log_action :destroy, custom_emoji
end end
end end
def verify_authorization(permission)
custom_emojis.each { |custom_emoji| authorize(custom_emoji, permission) }
end
end end

View File

@ -21,11 +21,15 @@ class Form::IpBlockBatch
end end
def delete! def delete!
ip_blocks.each { |ip_block| authorize(ip_block, :destroy?) } verify_authorization(:destroy?)
ip_blocks.each do |ip_block| ip_blocks.each do |ip_block|
ip_block.destroy ip_block.destroy
log_action :destroy, ip_block log_action :destroy, ip_block
end end
end end
def verify_authorization(permission)
ip_blocks.each { |ip_block| authorize(ip_block, permission) }
end
end end