mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Hide PM tags if the site setting is disabled (#10089)
* FIX: Hide PM tags if the site setting is disabled * Apply code suggestions
This commit is contained in:
@@ -144,6 +144,10 @@ class ListController < ApplicationController
|
||||
|
||||
def self.generate_message_route(action)
|
||||
define_method("#{action}") do
|
||||
if action == :private_messages_tag && !guardian.can_tag_pms?
|
||||
raise Discourse::NotFound
|
||||
end
|
||||
|
||||
list_opts = build_topic_list_options
|
||||
target_user = fetch_user_from_params({ include_inactive: current_user.try(:staff?) }, [:user_stat, :user_option])
|
||||
guardian.ensure_can_see_private_messages!(target_user.id)
|
||||
|
||||
@@ -37,10 +37,10 @@ class TagsController < ::ApplicationController
|
||||
ungrouped_tags = ungrouped_tags.where("tags.topic_count > 0") unless show_all_tags
|
||||
|
||||
grouped_tag_counts = TagGroup.visible(guardian).order('name ASC').includes(:tags).map do |tag_group|
|
||||
{ id: tag_group.id, name: tag_group.name, tags: self.class.tag_counts_json(tag_group.tags.where(target_tag_id: nil)) }
|
||||
{ id: tag_group.id, name: tag_group.name, tags: self.class.tag_counts_json(tag_group.tags.where(target_tag_id: nil), show_pm_tags: guardian.can_tag_pms?) }
|
||||
end
|
||||
|
||||
@tags = self.class.tag_counts_json(ungrouped_tags)
|
||||
@tags = self.class.tag_counts_json(ungrouped_tags, show_pm_tags: guardian.can_tag_pms?)
|
||||
@extras = { tag_groups: grouped_tag_counts }
|
||||
else
|
||||
tags = show_all_tags ? Tag.all : Tag.where("tags.topic_count > 0")
|
||||
@@ -54,7 +54,7 @@ class TagsController < ::ApplicationController
|
||||
{ id: c.id, tags: self.class.tag_counts_json(c.tags.where(target_tag_id: nil)) }
|
||||
end
|
||||
|
||||
@tags = self.class.tag_counts_json(unrestricted_tags)
|
||||
@tags = self.class.tag_counts_json(unrestricted_tags, show_pm_tags: guardian.can_tag_pms?)
|
||||
@extras = { categories: category_tag_counts }
|
||||
end
|
||||
|
||||
@@ -231,7 +231,7 @@ class TagsController < ::ApplicationController
|
||||
filter_params
|
||||
)
|
||||
|
||||
tags = self.class.tag_counts_json(tags_with_counts)
|
||||
tags = self.class.tag_counts_json(tags_with_counts, show_pm_tags: guardian.can_tag_pms?)
|
||||
|
||||
json_response = { results: tags }
|
||||
|
||||
@@ -336,17 +336,19 @@ class TagsController < ::ApplicationController
|
||||
raise Discourse::NotFound if DiscourseTagging.hidden_tag_names(guardian).include?(params[:tag_id])
|
||||
end
|
||||
|
||||
def self.tag_counts_json(tags)
|
||||
def self.tag_counts_json(tags, show_pm_tags: true)
|
||||
target_tags = Tag.where(id: tags.map(&:target_tag_id).compact.uniq).select(:id, :name)
|
||||
tags.map do |t|
|
||||
next if t.topic_count == 0 && t.pm_topic_count > 0 && !show_pm_tags
|
||||
|
||||
{
|
||||
id: t.name,
|
||||
text: t.name,
|
||||
count: t.topic_count,
|
||||
pm_count: t.pm_topic_count,
|
||||
pm_count: show_pm_tags ? t.pm_topic_count : 0,
|
||||
target_tag: t.target_tag_id ? target_tags.find { |x| x.id == t.target_tag_id }&.name : nil
|
||||
}
|
||||
end
|
||||
end.compact
|
||||
end
|
||||
|
||||
def set_category_from_params
|
||||
|
||||
Reference in New Issue
Block a user