From 19cbadfbd66be628a9c544debe752f92b293d345 Mon Sep 17 00:00:00 2001
From: Matt Jankowski <matt@jankowski.online>
Date: Thu, 14 Mar 2024 05:31:15 -0400
Subject: [PATCH] Use enum-generated scope for `IpBlock` in CLI (#28144)

---
 app/models/ip_block.rb        | 2 +-
 app/models/user.rb            | 2 +-
 lib/mastodon/cli/ip_blocks.rb | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/app/models/ip_block.rb b/app/models/ip_block.rb
index 9def5b0cd..d6242efbf 100644
--- a/app/models/ip_block.rb
+++ b/app/models/ip_block.rb
@@ -23,7 +23,7 @@ class IpBlock < ApplicationRecord
     sign_up_requires_approval: 5000,
     sign_up_block: 5500,
     no_access: 9999,
-  }
+  }, prefix: true
 
   validates :ip, :severity, presence: true
   validates :ip, uniqueness: true
diff --git a/app/models/user.rb b/app/models/user.rb
index 14c2bb6e0..ee9116b9f 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -446,7 +446,7 @@ class User < ApplicationRecord
   end
 
   def sign_up_from_ip_requires_approval?
-    sign_up_ip.present? && IpBlock.sign_up_requires_approval.exists?(['ip >>= ?', sign_up_ip.to_s])
+    sign_up_ip.present? && IpBlock.severity_sign_up_requires_approval.exists?(['ip >>= ?', sign_up_ip.to_s])
   end
 
   def sign_up_email_requires_approval?
diff --git a/lib/mastodon/cli/ip_blocks.rb b/lib/mastodon/cli/ip_blocks.rb
index 100bf7bad..3c5fdb275 100644
--- a/lib/mastodon/cli/ip_blocks.rb
+++ b/lib/mastodon/cli/ip_blocks.rb
@@ -105,7 +105,7 @@ module Mastodon::CLI
       tools. Only blocks with no_access severity are returned.
     LONG_DESC
     def export
-      IpBlock.where(severity: :no_access).find_each do |ip_block|
+      IpBlock.severity_no_access.find_each do |ip_block|
         case options[:format]
         when 'nginx'
           say "deny #{ip_block.ip}/#{ip_block.ip.prefix};"