users: rework privacy mode into private favorites (fix #4257).
* Rename 'privacy mode' to 'private favorites'. * Make the private favorites setting only hide favorites, not favgroups and not the user's uploads on their profile page. * Make the favgroup is_public flag default to true instead of false and fix existing favgroups to be public if the user didn't have privacy mode enabled before. * List _all_ public favgroups on the /favorite_groups index, not just favgroups belonging to the current user. * Add a /users/<id>/favorite_groups endpoint.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<%= numbered_paginator(@favorite_groups) %>
|
||||
|
||||
<%= render "secondary_links" %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -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 %>
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<% if presenter.has_favorites? %>
|
||||
<% if presenter.has_favorites? && !user.hide_favorites? %>
|
||||
<div class="box user-favorites">
|
||||
<h2>
|
||||
<%= link_to "Favorites", posts_path(tags: "ordfav:#{user.name}") %>
|
||||
|
||||
@@ -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 %>
|
||||
|
||||
@@ -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 %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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');
|
||||
|
||||
|
||||
|
||||
8
script/fixes/061_fix_favgroup_privacy.rb
Executable file
8
script/fixes/061_fix_favgroup_privacy.rb
Executable file
@@ -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)
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user