enable user privacy mode for displaying favorites
This commit is contained in:
@@ -8,6 +8,11 @@ class FavoritesController < ApplicationController
|
|||||||
else
|
else
|
||||||
user_id = params[:user_id] || CurrentUser.user.id
|
user_id = params[:user_id] || CurrentUser.user.id
|
||||||
@user = User.find(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)
|
@favorite_set = PostSets::Favorite.new(user_id, params[:page], params)
|
||||||
respond_with(@favorite_set.posts) do |format|
|
respond_with(@favorite_set.posts) do |format|
|
||||||
format.xml do
|
format.xml do
|
||||||
|
|||||||
@@ -350,6 +350,12 @@ class PostQueryBuilder
|
|||||||
|
|
||||||
if q[:ordfav].present?
|
if q[:ordfav].present?
|
||||||
user_id = q[:ordfav].to_i
|
user_id = q[:ordfav].to_i
|
||||||
|
user = User.find(user_id)
|
||||||
|
|
||||||
|
if user.hide_favorites?
|
||||||
|
raise User::PrivilegeError.new
|
||||||
|
end
|
||||||
|
|
||||||
relation = relation.joins("INNER JOIN favorites ON favorites.post_id = posts.id")
|
relation = relation.joins("INNER JOIN favorites ON favorites.post_id = posts.id")
|
||||||
relation = relation.where("favorites.user_id % 100 = ? and favorites.user_id = ?", user_id % 100, user_id).order("favorites.id DESC")
|
relation = relation.where("favorites.user_id % 100 = ? and favorites.user_id = ?", user_id % 100, user_id).order("favorites.id DESC")
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -33,9 +33,21 @@ class FavoriteGroup < ActiveRecord::Base
|
|||||||
params = {} if params.blank?
|
params = {} if params.blank?
|
||||||
|
|
||||||
if params[:creator_id].present?
|
if params[:creator_id].present?
|
||||||
q = q.where("creator_id = ?", params[:creator_id].to_i)
|
user = User.find(params[:creator_id])
|
||||||
|
|
||||||
|
if user.hide_favorites?
|
||||||
|
raise User::PrivilegeError.new
|
||||||
|
end
|
||||||
|
|
||||||
|
q = q.where("creator_id = ?", user.id)
|
||||||
elsif params[:creator_name].present?
|
elsif params[:creator_name].present?
|
||||||
q = q.where("creator_id = (select _.id from users _ where lower(_.name) = ?)", params[:creator_name].tr(" ", "_").mb_chars.downcase)
|
user = User.find_by_name(params[:creator_name])
|
||||||
|
|
||||||
|
if user.hide_favorites?
|
||||||
|
raise User::PrivilegeError.new
|
||||||
|
end
|
||||||
|
|
||||||
|
q = q.where("creator_id = ?", user.id)
|
||||||
else
|
else
|
||||||
q = q.where("creator_id = ?", CurrentUser.user.id)
|
q = q.where("creator_id = ?", CurrentUser.user.id)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -855,7 +855,9 @@ class Post < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def favorited_users
|
def favorited_users
|
||||||
favorited_user_ids.map {|id| User.find(id)}
|
favorited_user_ids.map {|id| User.find(id)}.select do |x|
|
||||||
|
!x.hide_favorites?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def favorite_groups(active_id=nil)
|
def favorite_groups(active_id=nil)
|
||||||
|
|||||||
@@ -811,6 +811,10 @@ class User < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def hide_favorites?
|
||||||
|
enable_privacy_mode? && CurrentUser.user.id != id
|
||||||
|
end
|
||||||
|
|
||||||
def initialize_default_boolean_attributes
|
def initialize_default_boolean_attributes
|
||||||
self.enable_post_navigation = true
|
self.enable_post_navigation = true
|
||||||
self.new_post_navigation_layout = true
|
self.new_post_navigation_layout = true
|
||||||
|
|||||||
@@ -34,7 +34,11 @@ class UserSimilarityPresenter
|
|||||||
|
|
||||||
def each_user(&block)
|
def each_user(&block)
|
||||||
user_ids_with_scores.each do |user_id, score|
|
user_ids_with_scores.each do |user_id, score|
|
||||||
yield(User.find(user_id), 100 * score.to_f)
|
user = User.find(user_id)
|
||||||
|
|
||||||
|
if !user.hide_favorites?
|
||||||
|
yield(user, 100 * score.to_f)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -70,6 +70,8 @@
|
|||||||
|
|
||||||
<%= f.input :disable_categorized_saved_searches, :as => :select, :collection => [["No", "false"], ["Yes", "true"]], :include_blank => false %>
|
<%= f.input :disable_categorized_saved_searches, :as => :select, :collection => [["No", "false"], ["Yes", "true"]], :include_blank => false %>
|
||||||
|
|
||||||
|
<%= f.input :enable_privacy_mode, :as => :select, :collection => [["No", "false"], ["Yes", "true"]], :include_blank => false %>
|
||||||
|
|
||||||
<div class="input text optional field_with_hint">
|
<div class="input text optional field_with_hint">
|
||||||
<label class="text optional" for="user_favorite_tags">Frequent tags</label>
|
<label class="text optional" for="user_favorite_tags">Frequent tags</label>
|
||||||
<textarea id="user_favorite_tags" class="text optional" rows="5" name="user[favorite_tags]" cols="40"><%= raw @user.favorite_tags %></textarea>
|
<textarea id="user_favorite_tags" class="text optional" rows="5" name="user[favorite_tags]" cols="40"><%= raw @user.favorite_tags %></textarea>
|
||||||
|
|||||||
@@ -3,7 +3,10 @@
|
|||||||
<h1><%= link_to_user @user %></h1>
|
<h1><%= link_to_user @user %></h1>
|
||||||
|
|
||||||
<%= render "statistics", :presenter => @presenter, :user => @user %>
|
<%= render "statistics", :presenter => @presenter, :user => @user %>
|
||||||
<%= render "post_summary", :presenter => @presenter, :user => @user %>
|
|
||||||
|
<% if !@user.enable_privacy_mode? || CurrentUser.id == @user.id %>
|
||||||
|
<%= render "post_summary", :presenter => @presenter, :user => @user %>
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user