summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Jankowski <matt@jankowski.online>2023-10-16 10:36:28 -0400
committerGitHub <noreply@github.com>2023-10-16 16:36:28 +0200
commit08a376cbcbb2fa46c32c43937b77ddb081418af8 (patch)
tree121b83aac697c57bd336dc7a32f6e7e68b207c07
parentc91c0175db1cc8b954a977d29472886234ce9586 (diff)
Fix `Style/CombinableLoops` cop (#27429)
-rw-r--r--.rubocop_todo.yml6
-rw-r--r--app/models/form/custom_emoji_batch.rb18
-rw-r--r--app/models/form/ip_block_batch.rb6
3 files changed, 16 insertions, 14 deletions
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index 29d9f484c0b..980339f4969 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -517,12 +517,6 @@ Style/ClassVars:
Exclude:
- '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).
# Configuration parameters: AllowedVars.
Style/FetchEnvVar:
diff --git a/app/models/form/custom_emoji_batch.rb b/app/models/form/custom_emoji_batch.rb
index 484415f9022..c63996e0695 100644
--- a/app/models/form/custom_emoji_batch.rb
+++ b/app/models/form/custom_emoji_batch.rb
@@ -34,7 +34,7 @@ class Form::CustomEmojiBatch
end
def update!
- custom_emojis.each { |custom_emoji| authorize(custom_emoji, :update?) }
+ verify_authorization(:update?)
category = if category_id.present?
CustomEmojiCategory.find(category_id)
@@ -49,7 +49,7 @@ class Form::CustomEmojiBatch
end
def list!
- custom_emojis.each { |custom_emoji| authorize(custom_emoji, :update?) }
+ verify_authorization(:update?)
custom_emojis.each do |custom_emoji|
custom_emoji.update(visible_in_picker: true)
@@ -58,7 +58,7 @@ class Form::CustomEmojiBatch
end
def unlist!
- custom_emojis.each { |custom_emoji| authorize(custom_emoji, :update?) }
+ verify_authorization(:update?)
custom_emojis.each do |custom_emoji|
custom_emoji.update(visible_in_picker: false)
@@ -67,7 +67,7 @@ class Form::CustomEmojiBatch
end
def enable!
- custom_emojis.each { |custom_emoji| authorize(custom_emoji, :enable?) }
+ verify_authorization(:enable?)
custom_emojis.each do |custom_emoji|
custom_emoji.update(disabled: false)
@@ -76,7 +76,7 @@ class Form::CustomEmojiBatch
end
def disable!
- custom_emojis.each { |custom_emoji| authorize(custom_emoji, :disable?) }
+ verify_authorization(:disable?)
custom_emojis.each do |custom_emoji|
custom_emoji.update(disabled: true)
@@ -85,7 +85,7 @@ class Form::CustomEmojiBatch
end
def copy!
- custom_emojis.each { |custom_emoji| authorize(custom_emoji, :copy?) }
+ verify_authorization(:copy?)
custom_emojis.each do |custom_emoji|
copied_custom_emoji = custom_emoji.copy!
@@ -94,11 +94,15 @@ class Form::CustomEmojiBatch
end
def delete!
- custom_emojis.each { |custom_emoji| authorize(custom_emoji, :destroy?) }
+ verify_authorization(:destroy?)
custom_emojis.each do |custom_emoji|
custom_emoji.destroy
log_action :destroy, custom_emoji
end
end
+
+ def verify_authorization(permission)
+ custom_emojis.each { |custom_emoji| authorize(custom_emoji, permission) }
+ end
end
diff --git a/app/models/form/ip_block_batch.rb b/app/models/form/ip_block_batch.rb
index f6fe9b59357..bdfeb91c8a8 100644
--- a/app/models/form/ip_block_batch.rb
+++ b/app/models/form/ip_block_batch.rb
@@ -21,11 +21,15 @@ class Form::IpBlockBatch
end
def delete!
- ip_blocks.each { |ip_block| authorize(ip_block, :destroy?) }
+ verify_authorization(:destroy?)
ip_blocks.each do |ip_block|
ip_block.destroy
log_action :destroy, ip_block
end
end
+
+ def verify_authorization(permission)
+ ip_blocks.each { |ip_block| authorize(ip_block, permission) }
+ end
end