FIX: Use a default hashtag icon color for user with no permission (#21825)

One user can create a post or chat message with a hashtag they
have permission to use, but then when other users look at that
post they will see an empty space next to the hashtag because they
do not have the permission to load the colors in CSS classes for
the related category.

This fixes the issue by adding a default color with a special
CSS class if the user doesn't have permission to see the linked
channel/category on the hashtag.
This commit is contained in:
Martin Brennan
2023-06-07 10:15:39 +10:00
committed by GitHub
parent af74cf5c77
commit 69eecf92d0
6 changed files with 79 additions and 4 deletions

View File

@ -93,4 +93,21 @@ describe "Using #hashtag autocompletion to search for and lookup categories and
<a class=\"hashtag-cooked\" href=\"#{tag.url}\" data-type=\"tag\" data-slug=\"cooltag\" data-id=\"#{tag.id}\"><svg class=\"fa d-icon d-icon-tag svg-icon hashtag-color--tag-#{tag.id} svg-string\" xmlns=\"http://www.w3.org/2000/svg\"><use href=\"#tag\"></use></svg><span>cooltag</span></a>
HTML
end
context "when a user cannot access the category for a hashtag cooked in another post" do
fab!(:admin) { Fabricate(:admin) }
fab!(:manager_group) { Fabricate(:group, name: "Managers") }
fab!(:private_category) do
Fabricate(:private_category, name: "Management", slug: "management", group: manager_group)
end
fab!(:admin_group_user) { Fabricate(:group_user, user: admin, group: manager_group) }
fab!(:post_with_private_category) do
Fabricate(:post, topic: topic, raw: "this is a secret #management category", user: admin)
end
it "shows a default color and css class for the category icon square" do
topic_page.visit_topic(topic, post_number: post_with_private_category.post_number)
expect(page).to have_css(".hashtag-cooked .hashtag-missing")
end
end
end

View File

@ -8,8 +8,10 @@ module PageObjects
@fast_edit_component = PageObjects::Components::FastEditor.new
end
def visit_topic(topic)
page.visit "/t/#{topic.id}"
def visit_topic(topic, post_number: nil)
url = "/t/#{topic.id}"
url += "/#{post_number}" if post_number
page.visit url
self
end