ip bans: rename ban types to full and partial.

Rename ban types from "normal" and "signup" to "full" and "partial".
This commit is contained in:
evazion
2020-04-07 14:59:46 -05:00
parent bfdb0a4f5e
commit 16011771f1
6 changed files with 17 additions and 17 deletions

View File

@@ -163,7 +163,7 @@ class ApplicationController < ActionController::Base
end
def ip_ban_check
raise User::PrivilegeError if !request.get? && IpBan.hit!(:normal, CurrentUser.ip_addr)
raise User::PrivilegeError if !request.get? && IpBan.hit!(:full, CurrentUser.ip_addr)
end
def pundit_user

View File

@@ -59,7 +59,7 @@ class UsersController < ApplicationController
end
def create
requires_verification = IpLookup.new(CurrentUser.ip_addr).is_proxy? || IpBan.hit!(:signup, CurrentUser.ip_addr)
requires_verification = IpLookup.new(CurrentUser.ip_addr).is_proxy? || IpBan.hit!(:partial, CurrentUser.ip_addr)
@user = authorize User.new(
last_ip_addr: CurrentUser.ip_addr,

View File

@@ -8,8 +8,8 @@ class IpBan < ApplicationRecord
deletable
enum category: {
normal: 0,
signup: 100
full: 0,
partial: 100
}, _suffix: "ban"
def self.ip_matches(ip_addr)
@@ -50,13 +50,13 @@ class IpBan < ApplicationRecord
errors[:ip_addr] << "is invalid"
elsif ip_addr.private? || ip_addr.loopback? || ip_addr.link_local?
errors[:ip_addr] << "must be a public address"
elsif normal_ban? && ip_addr.ipv4? && ip_addr.prefix < 24
elsif full_ban? && ip_addr.ipv4? && ip_addr.prefix < 24
errors[:ip_addr] << "may not have a subnet bigger than /24"
elsif signup_ban? && ip_addr.ipv4? && ip_addr.prefix < 8
elsif partial_ban? && ip_addr.ipv4? && ip_addr.prefix < 8
errors[:ip_addr] << "may not have a subnet bigger than /8"
elsif normal_ban? && ip_addr.ipv6? && ip_addr.prefix < 64
elsif full_ban? && ip_addr.ipv6? && ip_addr.prefix < 64
errors[:ip_addr] << "may not have a subnet bigger than /64"
elsif signup_ban? && ip_addr.ipv6? && ip_addr.prefix < 20
elsif partial_ban? && ip_addr.ipv6? && ip_addr.prefix < 20
errors[:ip_addr] << "may not have a subnet bigger than /20"
elsif new_record? && IpBan.active.ip_matches(subnetted_ip).exists?
errors[:ip_addr] << "is already banned"

View File

@@ -3,12 +3,12 @@
<h1>New IP Ban</h1>
<p>
A normal IP ban restricts the IP from creating new accounts, logging in to
A full IP ban prevents the IP from creating new accounts, logging in to
existing accounts, or editing the site in any way.
</p>
<p>
A signup IP ban restricts new signups from editing anything until after
A partial IP ban prevents new signups from editing anything until after
they've verified their email address.
<p>
@@ -17,7 +17,7 @@
<%= edit_form_for(@ip_ban) do |f| %>
<%= f.input :ip_addr, label: "IP Address", as: :string, hint: "Add /24 to ban a subnet. Example: 1.2.3.4/24" %>
<%= f.input :reason, as: :string %>
<%= f.input :category, as: :select, include_blank: false, collection: [["Normal", "normal"], ["Signup", "signup"]] %>
<%= f.input :category, as: :select, include_blank: false, collection: [["Full", "full"], ["Partial", "partial"]] %>
<%= f.button :submit, "Submit" %>
<% end %>
</div>