related tags: eliminate favorite_tags cookie (#3955).
This commit is contained in:
@@ -3,7 +3,7 @@ class RelatedTagsController < ApplicationController
|
||||
before_action :require_reportbooru_key, only: [:update]
|
||||
|
||||
def show
|
||||
@query = RelatedTagQuery.new(params[:query], category: params[:category], translated_tags: params[:translated_tags], artists: params[:artists])
|
||||
@query = RelatedTagQuery.new(params[:query], category: params[:category], translated_tags: params[:translated_tags], artists: params[:artists], user: CurrentUser.user)
|
||||
respond_with(@query) do |format|
|
||||
format.json do
|
||||
render :json => @query.to_json
|
||||
|
||||
@@ -65,8 +65,6 @@ class UsersController < ApplicationController
|
||||
@user = User.find(params[:id])
|
||||
check_privilege(@user)
|
||||
@user.update(user_params(:update))
|
||||
cookies.delete(:favorite_tags)
|
||||
cookies.delete(:favorite_tags_with_categories)
|
||||
if @user.errors.any?
|
||||
flash[:notice] = @user.errors.full_messages.join("; ")
|
||||
else
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
class RelatedTagQuery
|
||||
attr_reader :query, :category, :translated_tags, :artists
|
||||
attr_reader :query, :category, :translated_tags, :artists, :user
|
||||
|
||||
def initialize(query, category: nil, translated_tags: nil, artists: nil);
|
||||
def initialize(query, category: nil, translated_tags: nil, artists: nil, user: nil)
|
||||
@user = user
|
||||
@query = TagAlias.to_aliased(query.to_s.downcase.strip).join(" ")
|
||||
@category = category
|
||||
@translated_tags = translated_tags.to_s.split
|
||||
@@ -25,6 +26,10 @@ class RelatedTagQuery
|
||||
end
|
||||
end
|
||||
|
||||
def favorite_tags
|
||||
user&.favorite_tags.to_s.split
|
||||
end
|
||||
|
||||
def wiki_page_tags
|
||||
results = wiki_page.try(:tags) || []
|
||||
results.reject! do |name|
|
||||
|
||||
@@ -28,7 +28,6 @@ class SessionLoader
|
||||
update_last_logged_in_at
|
||||
update_last_ip_addr
|
||||
set_time_zone
|
||||
store_favorite_tags_in_cookies
|
||||
CurrentUser.user.unban! if CurrentUser.user.ban_expired?
|
||||
end
|
||||
|
||||
@@ -92,14 +91,6 @@ private
|
||||
cookies[:password_hash] && cookies.signed[:user_name] && User.authenticate_cookie_hash(cookies.signed[:user_name], cookies[:password_hash])
|
||||
end
|
||||
|
||||
def store_favorite_tags_in_cookies
|
||||
if (cookies[:favorite_tags].blank? || cookies[:favorite_tags_with_categories].blank?) && CurrentUser.user.favorite_tags.present?
|
||||
favorite_tags = CurrentUser.user.favorite_tags.slice(0, 1024)
|
||||
cookies[:favorite_tags] = favorite_tags
|
||||
cookies[:favorite_tags_with_categories] = Tag.categories_for(favorite_tags.split(/[[:space:]]+/)).to_a.flatten.join(" ")
|
||||
end
|
||||
end
|
||||
|
||||
def update_last_logged_in_at
|
||||
return if CurrentUser.is_anonymous?
|
||||
return if CurrentUser.last_logged_in_at && CurrentUser.last_logged_in_at > 1.week.ago
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<div id="related-tags" class="related-tags">
|
||||
<% if local_assigns[:related_tags] %>
|
||||
<%= render "tag_column", tags: cookies[:recent_tags].to_s.split, title: "Recent" %>
|
||||
<%= render "tag_column", tags: cookies[:favorite_tags].to_s.split, title: "Frequent" %>
|
||||
<%= render "tag_column", tags: related_tags.favorite_tags, title: "Frequent" %>
|
||||
<%= render "tag_column", tags: related_tags.tags, class: "general-related-tags-column", title: related_tags.pretty_name %>
|
||||
<%= render "tag_column", tags: related_tags.translated_tags, title: "Translated Tags" %>
|
||||
<%= render "tag_column", tags: related_tags.wiki_page_tags, class: "wiki-related-tags-column", title: link_to("wiki:#{related_tags.pretty_name}", show_or_new_wiki_pages_path(title: related_tags.query)) %>
|
||||
|
||||
Reference in New Issue
Block a user