FIX: Whisper tooltip shows the allowed groups (#19509)
This commit is contained in:
parent
6f4cf81401
commit
d633467c60
|
@ -293,11 +293,22 @@ createWidget("post-meta-data", {
|
|||
let postInfo = [];
|
||||
|
||||
if (attrs.isWhisper) {
|
||||
const groups = this.site.get("whispers_allowed_groups_names");
|
||||
let title = "";
|
||||
|
||||
if (groups?.length > 0) {
|
||||
title = I18n.t("post.whisper_groups", {
|
||||
groupNames: groups.join(", "),
|
||||
});
|
||||
} else {
|
||||
title = I18n.t("post.whisper");
|
||||
}
|
||||
|
||||
postInfo.push(
|
||||
h(
|
||||
"div.post-info.whisper",
|
||||
{
|
||||
attributes: { title: I18n.t("post.whisper") },
|
||||
attributes: { title },
|
||||
},
|
||||
iconNode("far-eye-slash")
|
||||
)
|
||||
|
|
|
@ -39,7 +39,8 @@ class SiteSerializer < ApplicationSerializer
|
|||
:hashtag_icons,
|
||||
:displayed_about_plugin_stat_groups,
|
||||
:show_welcome_topic_banner,
|
||||
:anonymous_default_sidebar_tags
|
||||
:anonymous_default_sidebar_tags,
|
||||
:whispers_allowed_groups_names
|
||||
)
|
||||
|
||||
has_many :archetypes, embed: :objects, serializer: ArchetypeSerializer
|
||||
|
@ -246,6 +247,14 @@ class SiteSerializer < ApplicationSerializer
|
|||
scope.anonymous? && !SiteSetting.legacy_navigation_menu? && SiteSetting.tagging_enabled && SiteSetting.default_sidebar_tags.present?
|
||||
end
|
||||
|
||||
def whispers_allowed_groups_names
|
||||
SiteSetting.whispers_allowed_groups_map&.map { |id| Group.where(id: id).pluck_first(:name) }
|
||||
end
|
||||
|
||||
def include_whispers_allowed_groups_names?
|
||||
scope.can_see_whispers?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def ordered_flags(flags)
|
||||
|
|
|
@ -3447,6 +3447,7 @@ en:
|
|||
via_email: "this post arrived via email"
|
||||
via_auto_generated_email: "this post arrived via an auto generated email"
|
||||
whisper: "this post is a private whisper for moderators"
|
||||
whisper_groups: "this post is a private whisper only visible to %{groupNames}"
|
||||
|
||||
wiki:
|
||||
about: "this post is a wiki"
|
||||
|
|
|
@ -755,6 +755,9 @@
|
|||
"items": {
|
||||
|
||||
}
|
||||
},
|
||||
"whispers_allowed_groups_names" : {
|
||||
"type": "array"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
|
|
@ -234,4 +234,44 @@ RSpec.describe SiteSerializer do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#whispers_allowed_groups_names' do
|
||||
fab!(:admin) { Fabricate(:admin) }
|
||||
fab!(:allowed_user) { Fabricate(:user) }
|
||||
fab!(:not_allowed_user) { Fabricate(:user) }
|
||||
fab!(:group1) { Fabricate(:group, name: 'whisperers1', users: [allowed_user]) }
|
||||
fab!(:group2) { Fabricate(:group, name: 'whisperers2', users: [allowed_user]) }
|
||||
|
||||
it "returns correct group names for created groups" do
|
||||
admin_guardian = Guardian.new(admin)
|
||||
SiteSetting.whispers_allowed_groups = "#{group1.id}|#{group2.id}"
|
||||
|
||||
serialized = described_class.new(Site.new(admin_guardian), scope: admin_guardian, root: false).as_json
|
||||
expect(serialized[:whispers_allowed_groups_names]).to eq(["whisperers1", "whisperers2"])
|
||||
end
|
||||
|
||||
it "returns correct group names for automatic groups" do
|
||||
admin_guardian = Guardian.new(admin)
|
||||
SiteSetting.whispers_allowed_groups = "#{Group::AUTO_GROUPS[:staff]}|#{Group::AUTO_GROUPS[:trust_level_4]}"
|
||||
|
||||
serialized = described_class.new(Site.new(admin_guardian), scope: admin_guardian, root: false).as_json
|
||||
expect(serialized[:whispers_allowed_groups_names]).to eq(["staff", "trust_level_4"])
|
||||
end
|
||||
|
||||
it "returns group names when user is allowed to whisper" do
|
||||
user_guardian = Guardian.new(allowed_user)
|
||||
SiteSetting.whispers_allowed_groups = "#{group1.id}|#{group2.id}"
|
||||
|
||||
serialized = described_class.new(Site.new(user_guardian), scope: user_guardian, root: false).as_json
|
||||
expect(serialized[:whispers_allowed_groups_names]).to eq(["whisperers1", "whisperers2"])
|
||||
end
|
||||
|
||||
it "returns nil when user is not allowed to whisper" do
|
||||
user_guardian = Guardian.new(not_allowed_user)
|
||||
SiteSetting.whispers_allowed_groups = "#{Group::AUTO_GROUPS[:staff]}|#{Group::AUTO_GROUPS[:trust_level_4]}"
|
||||
|
||||
serialized = described_class.new(Site.new(user_guardian), scope: user_guardian, root: false).as_json
|
||||
expect(serialized[:whispers_allowed_groups_names]).to eq(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue