Fix #4670: Replace RequestStore with AS::CurrentAttributes.
This also requires replacing CurrentUser.name with CurrentUser.user.name because the `name` method had a conflict with CurrentAttributes.
This commit is contained in:
@@ -47,7 +47,7 @@ class FavoriteGroupsController < ApplicationController
|
||||
@favorite_group = authorize FavoriteGroup.find(params[:id])
|
||||
@favorite_group.destroy!
|
||||
flash[:notice] = "Favorite group deleted" if request.format.html?
|
||||
respond_with(@favorite_group, location: favorite_groups_path(search: { creator_name: CurrentUser.name }))
|
||||
respond_with(@favorite_group, location: favorite_groups_path(search: { creator_name: CurrentUser.user.name }))
|
||||
end
|
||||
|
||||
def add_post
|
||||
|
||||
@@ -12,7 +12,7 @@ class FavoritesController < ApplicationController
|
||||
user = User.find(params[:user_id])
|
||||
redirect_to posts_path(tags: "ordfav:#{user.name}", format: request.format.symbol)
|
||||
elsif !CurrentUser.is_anonymous?
|
||||
redirect_to posts_path(tags: "ordfav:#{CurrentUser.name}", format: request.format.symbol)
|
||||
redirect_to posts_path(tags: "ordfav:#{CurrentUser.user.name}", format: request.format.symbol)
|
||||
else
|
||||
redirect_to posts_path(format: request.format.symbol)
|
||||
end
|
||||
|
||||
@@ -7,7 +7,7 @@ class UserNameChangeRequestsController < ApplicationController
|
||||
end
|
||||
|
||||
def create
|
||||
@change_request = authorize UserNameChangeRequest.new(user: CurrentUser.user, original_name: CurrentUser.name)
|
||||
@change_request = authorize UserNameChangeRequest.new(user: CurrentUser.user, original_name: CurrentUser.user.name)
|
||||
@change_request.update(permitted_attributes(@change_request))
|
||||
flash[:notice] = "Your name has been changed" if @change_request.valid?
|
||||
respond_with(@change_request, location: profile_path)
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
class CurrentUser
|
||||
def self.scoped(user, ip_addr = "127.0.0.1")
|
||||
old_user = self.user
|
||||
old_ip_addr = self.ip_addr
|
||||
class CurrentUser < ActiveSupport::CurrentAttributes
|
||||
attribute :user, :ip_addr, :country, :root_url, :safe_mode
|
||||
|
||||
self.user = user
|
||||
self.ip_addr = ip_addr
|
||||
alias_method :safe_mode?, :safe_mode
|
||||
delegate :id, to: :user, allow_nil: true
|
||||
delegate_missing_to :user
|
||||
|
||||
begin
|
||||
yield
|
||||
ensure
|
||||
self.user = old_user
|
||||
self.ip_addr = old_ip_addr
|
||||
def self.scoped(user, ip_addr = "127.0.0.1", &block)
|
||||
set(user: user, ip_addr: ip_addr) do
|
||||
yield user
|
||||
end
|
||||
end
|
||||
|
||||
@@ -24,59 +21,7 @@ class CurrentUser
|
||||
scoped(user, &block)
|
||||
end
|
||||
|
||||
def self.user
|
||||
RequestStore[:current_user]
|
||||
end
|
||||
|
||||
def self.user=(user)
|
||||
RequestStore[:current_user] = user
|
||||
end
|
||||
|
||||
def self.ip_addr
|
||||
RequestStore[:current_ip_addr]
|
||||
end
|
||||
|
||||
def self.ip_addr=(ip_addr)
|
||||
RequestStore[:current_ip_addr] = ip_addr
|
||||
end
|
||||
|
||||
def self.country
|
||||
RequestStore[:country]
|
||||
end
|
||||
|
||||
def self.country=(country)
|
||||
RequestStore[:country] = country
|
||||
end
|
||||
|
||||
def self.root_url
|
||||
RequestStore[:current_root_url] || "https://#{Danbooru.config.hostname}"
|
||||
end
|
||||
|
||||
def self.root_url=(root_url)
|
||||
RequestStore[:current_root_url] = root_url
|
||||
end
|
||||
|
||||
def self.id
|
||||
if user.nil?
|
||||
nil
|
||||
else
|
||||
user.id
|
||||
end
|
||||
end
|
||||
|
||||
def self.name
|
||||
user.name
|
||||
end
|
||||
|
||||
def self.safe_mode?
|
||||
RequestStore[:safe_mode]
|
||||
end
|
||||
|
||||
def self.safe_mode=(safe_mode)
|
||||
RequestStore[:safe_mode] = safe_mode
|
||||
end
|
||||
|
||||
def self.method_missing(method, *params, &block)
|
||||
user.__send__(method, *params, &block)
|
||||
attributes[:root_url] || "https://#{Danbooru.config.hostname}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,11 +10,11 @@ class Comment < ApplicationRecord
|
||||
before_create :autoreport_spam
|
||||
after_create :update_last_commented_at_on_create
|
||||
after_update(:if => ->(rec) {(!rec.is_deleted? || !rec.saved_change_to_is_deleted?) && CurrentUser.id != rec.creator_id}) do |rec|
|
||||
ModAction.log("comment ##{rec.id} updated by #{CurrentUser.name}", :comment_update)
|
||||
ModAction.log("comment ##{rec.id} updated by #{CurrentUser.user.name}", :comment_update)
|
||||
end
|
||||
after_save :update_last_commented_at_on_destroy, :if => ->(rec) {rec.is_deleted? && rec.saved_change_to_is_deleted?}
|
||||
after_save(:if => ->(rec) {rec.is_deleted? && rec.saved_change_to_is_deleted? && CurrentUser.id != rec.creator_id}) do |rec|
|
||||
ModAction.log("comment ##{rec.id} deleted by #{CurrentUser.name}", :comment_delete)
|
||||
ModAction.log("comment ##{rec.id} deleted by #{CurrentUser.user.name}", :comment_delete)
|
||||
end
|
||||
|
||||
deletable
|
||||
|
||||
@@ -18,10 +18,10 @@ class ForumPost < ApplicationRecord
|
||||
validates_presence_of :body
|
||||
after_save :delete_topic_if_original_post
|
||||
after_update(:if => ->(rec) {rec.updater_id != rec.creator_id}) do |rec|
|
||||
ModAction.log("#{CurrentUser.name} updated forum ##{rec.id}", :forum_post_update)
|
||||
ModAction.log("#{CurrentUser.user.name} updated forum ##{rec.id}", :forum_post_update)
|
||||
end
|
||||
after_destroy(:if => ->(rec) {rec.updater_id != rec.creator_id}) do |rec|
|
||||
ModAction.log("#{CurrentUser.name} deleted forum ##{rec.id}", :forum_post_delete)
|
||||
ModAction.log("#{CurrentUser.user.name} deleted forum ##{rec.id}", :forum_post_delete)
|
||||
end
|
||||
|
||||
deletable
|
||||
|
||||
@@ -8,10 +8,10 @@ class UserFeedback < ApplicationRecord
|
||||
validates_inclusion_of :category, :in => %w(positive negative neutral)
|
||||
after_create :create_dmail, unless: :disable_dmail_notification
|
||||
after_update(:if => ->(rec) { CurrentUser.id != rec.creator_id}) do |rec|
|
||||
ModAction.log(%{#{CurrentUser.name} updated user feedback for "#{rec.user.name}":#{Routes.user_path(rec.user)}}, :user_feedback_update)
|
||||
ModAction.log(%{#{CurrentUser.user.name} updated user feedback for "#{rec.user.name}":#{Routes.user_path(rec.user)}}, :user_feedback_update)
|
||||
end
|
||||
after_destroy(:if => ->(rec) { CurrentUser.id != rec.creator_id}) do |rec|
|
||||
ModAction.log(%{#{CurrentUser.name} deleted user feedback for "#{rec.user.name}":#{Routes.user_path(rec.user)}}, :user_feedback_delete)
|
||||
ModAction.log(%{#{CurrentUser.user.name} deleted user feedback for "#{rec.user.name}":#{Routes.user_path(rec.user)}}, :user_feedback_delete)
|
||||
end
|
||||
|
||||
deletable
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
<%= subnav_link_to "Upload", new_upload_path %>
|
||||
<%= subnav_link_to "Hot", posts_path(:tags => "order:rank", :d => "1") %>
|
||||
<% if RecommenderService.available_for_user?(CurrentUser.user) %>
|
||||
<%= subnav_link_to "Recommended", recommended_posts_path(search: { user_name: CurrentUser.name }) %>
|
||||
<%= subnav_link_to "Recommended", recommended_posts_path(search: { user_name: CurrentUser.user.name }) %>
|
||||
<% end %>
|
||||
<% if policy(Favorite).create? %>
|
||||
<%= subnav_link_to "Favorites", posts_path(tags: "ordfav:#{CurrentUser.user.name}") %>
|
||||
<% end %>
|
||||
<% if policy(FavoriteGroup).create? %>
|
||||
<%= subnav_link_to "Fav groups", favorite_groups_path(search: { creator_name: CurrentUser.name }) %>
|
||||
<%= subnav_link_to "Fav groups", favorite_groups_path(search: { creator_name: CurrentUser.user.name }) %>
|
||||
<% end %>
|
||||
<% if policy(SavedSearch).create? %>
|
||||
<%= subnav_link_to "Saved searches", posts_path(tags: "search:all") %>
|
||||
|
||||
Reference in New Issue
Block a user