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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user