diff --git a/app/controllers/favorites_controller.rb b/app/controllers/favorites_controller.rb
index 6976fce4d..ab0f5feef 100644
--- a/app/controllers/favorites_controller.rb
+++ b/app/controllers/favorites_controller.rb
@@ -5,22 +5,13 @@ class FavoritesController < ApplicationController
rescue_with Favorite::Error, status: 422
def index
- if params[:tags]
- redirect_to(posts_path(:tags => params[:tags]))
+ if params[:user_id].present?
+ user = User.find(params[:user_id])
+ redirect_to posts_path(tags: "ordfav:#{user.name}")
+ elsif CurrentUser.is_member?
+ redirect_to posts_path(tags: "ordfav:#{CurrentUser.name}")
else
- user_id = params[:user_id] || CurrentUser.user.id
- @user = User.find(user_id)
-
- if @user.hide_favorites?
- raise User::PrivilegeError.new
- end
-
- @favorite_set = PostSets::Favorite.new(user_id, params[:page], params)
- respond_with(@favorite_set.posts) do |format|
- format.xml do
- render :xml => @favorite_set.posts.to_xml(:root => "posts")
- end
- end
+ redirect_to posts_path
end
end
diff --git a/app/logical/post_sets/favorite.rb b/app/logical/post_sets/favorite.rb
deleted file mode 100644
index 3f2789db1..000000000
--- a/app/logical/post_sets/favorite.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-module PostSets
- class Favorite < PostSets::Base
- attr_reader :user, :page, :favorites, :params
-
- def initialize(user_id, page = 1, params = {})
- @params = params
- @user = ::User.find(user_id)
- @favorites = ::Favorite.for_user(user.id).paginate(page, :limit => limit).order("favorites.id desc")
- end
-
- def limit
- params[:limit] || CurrentUser.user.per_page
- end
-
- def tag_array
- @tag_array ||= ["fav:#{user.name}"]
- end
-
- def tag_string
- tag_array.uniq.join(" ")
- end
-
- def humanized_tag_string
- "fav:#{user.pretty_name}"
- end
-
- def posts
- @posts ||= favorites.includes(:post).map(&:post).compact
- end
-
- def presenter
- @presenter ||= ::PostSetPresenters::Favorite.new(self)
- end
- end
-end
diff --git a/app/presenters/post_set_presenters/favorite.rb b/app/presenters/post_set_presenters/favorite.rb
deleted file mode 100644
index 357596475..000000000
--- a/app/presenters/post_set_presenters/favorite.rb
+++ /dev/null
@@ -1,12 +0,0 @@
-module PostSetPresenters
- class Favorite < Base
- attr_accessor :post_set, :tag_set_presenter
- delegate :favorites, :posts, :to => :post_set
- delegate :tag_list_html, to: :tag_set_presenter
-
- def initialize(post_set)
- @post_set = post_set
- @tag_set_presenter = TagSetPresenter.new(RelatedTagCalculator.frequent_tags_for_posts(post_set.posts).take(25))
- end
- end
-end
diff --git a/app/views/favorites/index.html.erb b/app/views/favorites/index.html.erb
deleted file mode 100644
index ea14cc280..000000000
--- a/app/views/favorites/index.html.erb
+++ /dev/null
@@ -1,43 +0,0 @@
-
-
-
-
-
- Favorites
-
- <%= render "posts/partials/index/edit" %>
-
-
- <%= @favorite_set.presenter.post_previews_html(self) %>
-
- <%= sequential_paginator(@favorite_set.favorites) %>
-
-
-
-
-
-<%= render "posts/partials/common/secondary_links" %>
-
-<% content_for(:page_title) do %>
- Favorites - <%= @user.pretty_name %> - <%= Danbooru.config.app_name %>
-<% end %>
diff --git a/app/views/posts/partials/common/_secondary_links.html.erb b/app/views/posts/partials/common/_secondary_links.html.erb
index c1677c04c..ce9045a49 100644
--- a/app/views/posts/partials/common/_secondary_links.html.erb
+++ b/app/views/posts/partials/common/_secondary_links.html.erb
@@ -7,7 +7,7 @@
<%= subnav_link_to "Recommended", recommended_posts_path(context: "user") %>
<% end %>
<% unless CurrentUser.is_anonymous? %>
- <%= subnav_link_to "Favorites", favorites_path %>
+ <%= subnav_link_to "Favorites", posts_path(tags: "ordfav:#{CurrentUser.user.name}") %>
<%= subnav_link_to "Fav groups", favorite_groups_path %>
<% if CurrentUser.has_saved_searches? %>
<%= subnav_link_to "Saved searches", posts_path(:tags => "search:all") %>
diff --git a/app/views/users/_post_summary.html.erb b/app/views/users/_post_summary.html.erb
index 58d0678e0..0fa6a4106 100644
--- a/app/views/users/_post_summary.html.erb
+++ b/app/views/users/_post_summary.html.erb
@@ -14,7 +14,7 @@
<% if presenter.has_favorites? %>
- <%= link_to "Favorites", favorites_path(:user_id => user.id) %>
+ <%= link_to "Favorites", posts_path(tags: "ordfav:#{user.name}") %>
<% presenter.favorites.each do |post| %>
@@ -39,4 +39,4 @@
<% end %>
-<% end %>
\ No newline at end of file
+<% end %>
diff --git a/test/functional/favorites_controller_test.rb b/test/functional/favorites_controller_test.rb
index cfcfb7f79..feef446bf 100644
--- a/test/functional/favorites_controller_test.rb
+++ b/test/functional/favorites_controller_test.rb
@@ -12,16 +12,19 @@ class FavoritesControllerTest < ActionDispatch::IntegrationTest
@post.add_favorite!(@user)
end
- context "with a specified tags parameter" do
- should "redirect to the posts controller" do
- get_auth favorites_path, @user, params: {:tags => "fav:#{@user.name} abc"}
- assert_redirected_to(posts_path(:tags => "fav:#{@user.name} abc"))
- end
+ should "redirect the user_id param to an ordfav: search" do
+ get favorites_path(user_id: @user.id)
+ assert_redirected_to posts_path(tags: "ordfav:#{@user.name}")
end
- should "display the current user's favorites" do
+ should "redirect members to an ordfav: search" do
get_auth favorites_path, @user
- assert_response :success
+ assert_redirected_to posts_path(tags: "ordfav:#{@user.name}")
+ end
+
+ should "redirect anonymous users to the posts index" do
+ get favorites_path
+ assert_redirected_to posts_path
end
end
diff --git a/test/unit/post_sets/favorite_test.rb b/test/unit/post_sets/favorite_test.rb
deleted file mode 100644
index f57bafe3f..000000000
--- a/test/unit/post_sets/favorite_test.rb
+++ /dev/null
@@ -1,134 +0,0 @@
-require 'test_helper'
-
-module PostSets
- class FavoriteTest < ActiveSupport::TestCase
- context "In all cases" do
- setup do
- @user = FactoryBot.create(:user)
- CurrentUser.user = @user
- CurrentUser.ip_addr = "127.0.0.1"
-
- @post_1 = FactoryBot.create(:post)
- @post_2 = FactoryBot.create(:post)
- @post_3 = FactoryBot.create(:post)
- @post_2.add_favorite!(@user)
- @post_1.add_favorite!(@user)
- @post_3.add_favorite!(@user)
- end
-
- teardown do
- CurrentUser.user = nil
- CurrentUser.ip_addr = nil
- end
-
- context "a favorite set for before the most recent post" do
- setup do
- id = ::Favorite.where(:user_id => @user.id, :post_id => @post_3.id).first.id
- @set = PostSets::Favorite.new(@user.id, "b#{id}", limit: 1)
- end
-
- context "a sequential paginator" do
- should "return the second most recent element" do
- assert_equal(@post_1.id, @set.posts.first.id)
- end
-
- should "know what page it's on" do
- refute(@set.favorites.is_first_page?)
- refute(@set.favorites.is_last_page?)
- end
- end
- end
-
- context "a favorite set for after the third most recent post" do
- setup do
- id = ::Favorite.where(:user_id => @user.id, :post_id => @post_2.id).first.id
- ::Favorite.stubs(:records_per_page).returns(1)
- @set = PostSets::Favorite.new(@user.id, "a#{id}")
- end
-
- context "a sequential paginator" do
- should "return the second most recent element" do
- assert_equal(@post_1.id, @set.posts.first.id)
- end
-
- should "know what page it's on" do
- refute(@set.favorites.is_first_page?)
- refute(@set.favorites.is_last_page?)
- end
- end
- end
-
- context "a favorite set for before the second most recent post" do
- setup do
- id = ::Favorite.where(:user_id => @user.id, :post_id => @post_1.id).first.id
- ::Favorite.stubs(:records_per_page).returns(1)
- @set = PostSets::Favorite.new(@user.id, "b#{id}")
- end
-
- context "a sequential paginator" do
- should "return the third most recent element" do
- assert_equal(@post_2.id, @set.posts.first.id)
- end
-
- should "know what page it's on" do
- refute(@set.favorites.is_first_page?)
- assert(@set.favorites.is_last_page?)
- end
- end
- end
-
- context "a favorite set for after the second most recent post" do
- setup do
- id = ::Favorite.where(:user_id => @user.id, :post_id => @post_1.id).first.id
- ::Favorite.stubs(:records_per_page).returns(1)
- @set = PostSets::Favorite.new(@user.id, "a#{id}")
- end
-
- context "a sequential paginator" do
- should "return the most recent element" do
- assert_equal(@post_3.id, @set.posts.first.id)
- end
-
- should "know what page it's on" do
- assert(@set.favorites.is_first_page?)
- refute(@set.favorites.is_last_page?)
- end
- end
- end
-
- context "a favorite set for page 2" do
- setup do
- ::Favorite.stubs(:records_per_page).returns(1)
- @set = PostSets::Favorite.new(@user.id, 2)
- end
-
- context "a numbered paginator" do
- should "return the second most recent element" do
- assert_equal(@post_1.id, @set.posts.first.id)
- end
-
- should "know what page it's on" do
- refute(@set.favorites.is_first_page?)
- refute(@set.favorites.is_last_page?)
- end
- end
- end
-
- context "a favorite set with no page specified" do
- setup do
- ::Favorite.stubs(:records_per_page).returns(1)
- @set = PostSets::Favorite.new(@user.id)
- end
-
- should "return the most recent element" do
- assert_equal(@post_3.id, @set.posts.first.id)
- end
-
- should "know what page it's on" do
- assert(@set.favorites.is_first_page?)
- refute(@set.favorites.is_last_page?)
- end
- end
- end
- end
-end