diff --git a/app/controllers/favorite_groups_controller.rb b/app/controllers/favorite_groups_controller.rb index 9ffd97cf2..c6d77ca97 100644 --- a/app/controllers/favorite_groups_controller.rb +++ b/app/controllers/favorite_groups_controller.rb @@ -3,6 +3,7 @@ class FavoriteGroupsController < ApplicationController respond_to :html, :xml, :json, :js def index + params[:search][:creator_id] ||= params[:user_id] @favorite_groups = FavoriteGroup.paginated_search(params) respond_with(@favorite_groups) end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index eea6fff76..aa1536934 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -109,7 +109,7 @@ class UsersController < ApplicationController time_zone per_page custom_style theme receive_email_notifications always_resize_images enable_post_navigation - new_post_navigation_layout enable_privacy_mode + new_post_navigation_layout enable_private_favorites enable_sequential_post_navigation hide_deleted_posts style_usernames enable_auto_complete show_deleted_children disable_categorized_saved_searches disable_tagged_filenames diff --git a/app/models/favorite_group.rb b/app/models/favorite_group.rb index 38188e4db..67cdbf578 100644 --- a/app/models/favorite_group.rb +++ b/app/models/favorite_group.rb @@ -21,14 +21,8 @@ class FavoriteGroup < ApplicationRecord where_ilike(:name, name) end - def hide_private(user, params) - if user.hide_favorites? - where("is_public = true") - elsif params[:is_public].present? - where("is_public = ?", params[:is_public]) - else - all - end + def visible(user) + where(is_public: true).or(where(creator_id: user.id)) end def default_order @@ -37,20 +31,8 @@ class FavoriteGroup < ApplicationRecord def search(params) q = super - q = q.search_attributes(params, :name, :is_public, :post_ids) - - if params[:creator_id].present? - user = User.find(params[:creator_id]) - q = q.hide_private(user, params) - q = q.where("creator_id = ?", user.id) - elsif params[:creator_name].present? - user = User.find_by_name(params[:creator_name]) - q = q.hide_private(user, params) - q = q.where("creator_id = ?", user.id) - else - q = q.hide_private(CurrentUser.user, params) - q = q.where("creator_id = ?", CurrentUser.user.id) - end + q = q.visible(CurrentUser.user) + q = q.search_attributes(params, :name, :is_public, :post_ids, :creator) if params[:name_matches].present? q = q.name_matches(params[:name_matches]) @@ -177,6 +159,6 @@ class FavoriteGroup < ApplicationRecord end def viewable_by?(user) - creator_id == user.id || !creator.hide_favorites? || is_public + creator_id == user.id || is_public end end diff --git a/app/models/user.rb b/app/models/user.rb index c380e759a..411d29799 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -40,7 +40,7 @@ class User < ApplicationRecord always_resize_images enable_post_navigation new_post_navigation_layout - enable_privacy_mode + enable_private_favorites enable_sequential_post_navigation hide_deleted_posts style_usernames @@ -653,7 +653,7 @@ class User < ApplicationRecord end def favorite_group_count - favorite_groups.count + favorite_groups.visible(CurrentUser.user).count end def appeal_count @@ -792,7 +792,7 @@ class User < ApplicationRecord end def hide_favorites? - !CurrentUser.is_admin? && enable_privacy_mode? && CurrentUser.user.id != id + !CurrentUser.is_admin? && enable_private_favorites? && CurrentUser.user.id != id end def initialize_attributes diff --git a/app/presenters/user_presenter.rb b/app/presenters/user_presenter.rb index e780c0d29..df991576f 100644 --- a/app/presenters/user_presenter.rb +++ b/app/presenters/user_presenter.rb @@ -88,7 +88,7 @@ class UserPresenter end def favorite_group_count(template) - template.link_to(user.favorite_group_count, template.favorite_groups_path(:search => {:creator_id => user.id})) + template.link_to(user.favorite_group_count, template.user_favorite_groups_path(user.id)) end def comment_count(template) diff --git a/app/views/favorite_groups/index.html.erb b/app/views/favorite_groups/index.html.erb index 5f6b0c759..7957ca4ac 100644 --- a/app/views/favorite_groups/index.html.erb +++ b/app/views/favorite_groups/index.html.erb @@ -13,6 +13,8 @@ <% end %> <% end %> + <%= numbered_paginator(@favorite_groups) %> + <%= render "secondary_links" %> diff --git a/app/views/posts/partials/common/_secondary_links.html.erb b/app/views/posts/partials/common/_secondary_links.html.erb index 0076a0eb7..0a98a31d5 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 @@ <% end %> <% unless CurrentUser.is_anonymous? %> <%= subnav_link_to "Favorites", posts_path(tags: "ordfav:#{CurrentUser.user.name}") %> - <%= subnav_link_to "Fav groups", favorite_groups_path %> + <%= subnav_link_to "Fav groups", user_favorite_groups_path(CurrentUser.id) %> <%= subnav_link_to "Saved searches", posts_path(tags: "search:all") %> <% end %> <%= subnav_link_to "Changes", post_versions_path %> diff --git a/app/views/users/_post_summary.html.erb b/app/views/users/_post_summary.html.erb index 8f8dfd3ea..3b85ade65 100644 --- a/app/views/users/_post_summary.html.erb +++ b/app/views/users/_post_summary.html.erb @@ -11,7 +11,7 @@ <% end %> -<% if presenter.has_favorites? %> +<% if presenter.has_favorites? && !user.hide_favorites? %>

<%= link_to "Favorites", posts_path(tags: "ordfav:#{user.name}") %> diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index 2c83731b7..9de157b6c 100644 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -57,7 +57,7 @@ <%= f.input :show_deleted_children, :as => :select, :label => "Show deleted children", :hint => "Show thumbnail borders on parent posts even if the children are deleted", :include_blank => false, :collection => [["Yes", "true"], ["No", "false"]] %> <%= f.input :enable_auto_complete, :as => :select, :hint => "Enable tag autocomplete in the search box", :collection => [["Yes", "true"], ["No", "false"]], :include_blank => false %> <%= f.input :disable_categorized_saved_searches, :hint => "Don't show dialog box when creating a new saved search", :as => :select, :collection => [["No", "false"], ["Yes", "true"]], :include_blank => false %> - <%= f.input :enable_privacy_mode, :as => :select, :hint => "Make your favorites private", :collection => [["No", "false"], ["Yes", "true"]], :include_blank => false %> + <%= f.input :enable_private_favorites, :as => :select, :hint => "Make your favorites private", :collection => [["No", "false"], ["Yes", "true"]], :include_blank => false %> <%= f.input :disable_tagged_filenames, :as => :select, :hint => "Don't include tags in image filenames", :collection => [["No", "false"], ["Yes", "true"]], :include_blank => false %> <%= f.input :disable_mobile_gestures, :as => :select, :hint => "Disable swipe left / swipe right gestures on mobile", :collection => [["No", "false"], ["Yes", "true"]], :include_blank => false %> <%= f.input :disable_post_tooltips, :as => :select, :hint => "Disable advanced tooltips when hovering over thumbnails", :collection => [["No", "false"], ["Yes", "true"]], :include_blank => false %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index e0996424a..665b2b5d1 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -4,10 +4,8 @@ <%= render "statistics", presenter: @user.presenter, user: @user %> - <% if !CurrentUser.is_admin? && !@user.enable_privacy_mode? || CurrentUser.id == @user.id %> - <%= render "posts/partials/common/inline_blacklist" %> - <%= render "post_summary", presenter: @user.presenter, user: @user %> - <% end %> + <%= render "posts/partials/common/inline_blacklist" %> + <%= render "post_summary", presenter: @user.presenter, user: @user %>

diff --git a/config/routes.rb b/config/routes.rb index 967f3dfa3..a0e692beb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -268,6 +268,7 @@ Rails.application.routes.draw do end end resources :users do + resources :favorite_groups, controller: "favorite_groups", only: [:index], as: "favorite_groups" resource :password, :only => [:edit], :controller => "maintenance/user/passwords" resource :api_key, :only => [:show, :view, :update, :destroy], :controller => "maintenance/user/api_keys" do post :view diff --git a/db/migrate/20200118015014_change_is_public_default_on_favorite_groups.rb b/db/migrate/20200118015014_change_is_public_default_on_favorite_groups.rb new file mode 100644 index 000000000..b07a50f76 --- /dev/null +++ b/db/migrate/20200118015014_change_is_public_default_on_favorite_groups.rb @@ -0,0 +1,6 @@ +class ChangeIsPublicDefaultOnFavoriteGroups < ActiveRecord::Migration[6.0] + def change + change_column_default :favorite_groups, :is_public, from: false, to: true + add_index :favorite_groups, :is_public + end +end diff --git a/db/structure.sql b/db/structure.sql index f4b32785e..5f00617b0 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -924,7 +924,7 @@ CREATE TABLE public.favorite_groups ( post_ids integer[] DEFAULT '{}'::integer[] NOT NULL, created_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, - is_public boolean DEFAULT false NOT NULL + is_public boolean DEFAULT true NOT NULL ); @@ -4967,6 +4967,13 @@ CREATE INDEX index_dtext_links_on_model_type_and_model_id ON public.dtext_links CREATE INDEX index_favorite_groups_on_creator_id ON public.favorite_groups USING btree (creator_id); +-- +-- Name: index_favorite_groups_on_is_public; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_favorite_groups_on_is_public ON public.favorite_groups USING btree (is_public); + + -- -- Name: index_favorite_groups_on_lower_name; Type: INDEX; Schema: public; Owner: - -- @@ -7407,6 +7414,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20191119061018'), ('20191223032633'), ('20200114204550'), -('20200115010442'); +('20200115010442'), +('20200118015014'); diff --git a/script/fixes/061_fix_favgroup_privacy.rb b/script/fixes/061_fix_favgroup_privacy.rb new file mode 100755 index 000000000..c50477a70 --- /dev/null +++ b/script/fixes/061_fix_favgroup_privacy.rb @@ -0,0 +1,8 @@ +#!/usr/bin/env ruby + +require_relative "../../config/environment" + +users = User.bit_prefs_match(:enable_private_favorites, true) +favgroups = FavoriteGroup.where(is_public: false).where.not(creator_id: users.select(:id)) + +favgroups.update_all(is_public: true) diff --git a/test/unit/post_test.rb b/test/unit/post_test.rb index e14be6cd4..a8a73e3d9 100644 --- a/test/unit/post_test.rb +++ b/test/unit/post_test.rb @@ -1706,7 +1706,7 @@ class PostTest < ActiveSupport::TestCase @parent = FactoryBot.create(:post) @child = FactoryBot.create(:post, parent: @parent) - @user1 = FactoryBot.create(:user, enable_privacy_mode: true) + @user1 = FactoryBot.create(:user, enable_private_favorites: true) @gold1 = FactoryBot.create(:gold_user) @supervoter1 = FactoryBot.create(:user, is_super_voter: true)