Remove CurrentUser.ip_addr.

Remove the `CurrentUser.ip_addr` global variable and replace it with
`request.remote_ip`. Before we had to track the current user's IP in a
global variable so that when we edited a post for example, we could pass
down the user's IP to the model and save it in the post_versions table.
Now that we now longer save IPs in version tables, we don't need a global
variable to get access to the current user's IP outside of controllers.
This commit is contained in:
evazion
2022-09-18 04:41:01 -05:00
parent d4da8499ce
commit 1d2bac7b95
41 changed files with 15 additions and 87 deletions

View File

@@ -39,7 +39,7 @@ class ApplicationController < ActionController::Base
before_action(only: action, if: if_proc) do
key = "#{controller_name}:#{action}"
rate_limiter = RateLimiter.build(action: key, rate: rate, burst: burst, user: CurrentUser.user, ip_addr: CurrentUser.ip_addr)
rate_limiter = RateLimiter.build(action: key, rate: rate, burst: burst, user: CurrentUser.user, ip_addr: request.remote_ip)
headers["X-Rate-Limit"] = rate_limiter.to_json
rate_limiter.limit!
end
@@ -101,7 +101,7 @@ class ApplicationController < ActionController::Base
rate: CurrentUser.user.api_regen_multiplier,
burst: 200,
user: CurrentUser.user,
ip_addr: CurrentUser.ip_addr,
ip_addr: request.remote_ip,
)
headers["X-Rate-Limit"] = rate_limiter.to_json
@@ -178,7 +178,6 @@ class ApplicationController < ActionController::Base
def reset_current_user
CurrentUser.user = nil
CurrentUser.ip_addr = nil
CurrentUser.safe_mode = false
end
@@ -215,7 +214,7 @@ class ApplicationController < ActionController::Base
end
def ip_ban_check
raise User::PrivilegeError if !request.get? && IpBan.hit!(:full, CurrentUser.ip_addr)
raise User::PrivilegeError if !request.get? && IpBan.hit!(:full, request.remote_ip)
end
def pundit_user

View File

@@ -43,7 +43,7 @@ class CommentsController < ApplicationController
end
def create
@comment = authorize Comment.new(creator: CurrentUser.user, creator_ip_addr: CurrentUser.ip_addr)
@comment = authorize Comment.new(creator: CurrentUser.user, creator_ip_addr: request.remote_ip)
@comment.update(permitted_attributes(@comment))
flash[:notice] = @comment.valid? ? "Comment posted" : @comment.errors.full_messages.join("; ")
respond_with(@comment) do |format|

View File

@@ -38,7 +38,7 @@ class DmailsController < ApplicationController
end
def create
@dmail = authorize(Dmail).create_split(from: CurrentUser.user, creator_ip_addr: CurrentUser.ip_addr, **permitted_attributes(Dmail))
@dmail = authorize(Dmail).create_split(from: CurrentUser.user, creator_ip_addr: request.remote_ip, **permitted_attributes(Dmail))
respond_with(@dmail)
end

View File

@@ -38,7 +38,7 @@ class ForumPostsController < ApplicationController
end
def create
@forum_post = authorize ForumPost.new(creator: CurrentUser.user, creator_ip_addr: CurrentUser.ip_addr, topic_id: params.dig(:forum_post, :topic_id))
@forum_post = authorize ForumPost.new(creator: CurrentUser.user, creator_ip_addr: request.remote_ip, topic_id: params.dig(:forum_post, :topic_id))
@forum_post.update(permitted_attributes(@forum_post))
page = @forum_post.topic.last_page if @forum_post.topic.last_page > 1

View File

@@ -58,7 +58,7 @@ class ForumTopicsController < ApplicationController
def create
@forum_topic = authorize ForumTopic.new(creator: CurrentUser.user, **permitted_attributes(ForumTopic))
@forum_topic.original_post.creator = CurrentUser.user
@forum_topic.original_post.creator_ip_addr = CurrentUser.ip_addr
@forum_topic.original_post.creator_ip_addr = request.remote_ip
@forum_topic.save
respond_with(@forum_topic)

View File

@@ -65,7 +65,7 @@ class UsersController < ApplicationController
user_verifier = UserVerifier.new(CurrentUser.user, request)
@user = authorize User.new(
last_ip_addr: CurrentUser.ip_addr,
last_ip_addr: request.remote_ip,
last_logged_in_at: Time.zone.now,
requires_verification: user_verifier.requires_verification?,
level: user_verifier.initial_level,