FIX: Hide post replies content for ignored users (#7320)

This commit is contained in:
Tarek Khalil
2019-04-05 15:13:36 +01:00
committed by Régis Hanol
parent 9c2e6b9a54
commit 131eba0366
8 changed files with 51 additions and 17 deletions

View File

@@ -6,8 +6,7 @@ class BasicPostSerializer < ApplicationSerializer
:avatar_template,
:created_at,
:cooked,
:cooked_hidden,
:ignored
:cooked_hidden
def name
object.user && object.user.name
@@ -36,21 +35,11 @@ class BasicPostSerializer < ApplicationSerializer
else
I18n.t('flagging.user_must_edit')
end
elsif ignored
I18n.t('ignored.hidden_content')
else
object.filter_quotes(@parent_post)
end
end
def ignored
return false unless SiteSetting.ignore_user_enabled?
object.is_first_post? &&
scope.current_user&.id != object.user_id &&
IgnoredUser.where(user_id: scope.current_user&.id,
ignored_user_id: object.user_id).exists?
end
def include_name?
SiteSetting.enable_names?
end

View File

@@ -42,7 +42,8 @@ class CurrentUserSerializer < BasicUserSerializer
:top_category_ids,
:hide_profile_and_presence,
:groups,
:second_factor_enabled
:second_factor_enabled,
:ignored_users
def groups
object.visible_groups.pluck(:id, :name).map { |id, name| { id: id, name: name.downcase } }
@@ -157,6 +158,10 @@ class CurrentUserSerializer < BasicUserSerializer
CategoryUser.lookup(object, :muted).pluck(:category_id)
end
def ignored_users
IgnoredUser.where(user: object.id).joins(:ignored_user).pluck(:username)
end
def top_category_ids
omitted_notification_levels = [CategoryUser.notification_levels[:muted], CategoryUser.notification_levels[:regular]]
CategoryUser.where(user_id: object.id)