Commit de6999b7 authored by Toon Claes's avatar Toon Claes

banzai: Get Custom Emoji from group as well

Not all markdown fields are related to a project. Some, like those in
Epics, might be related to a group. So in addition to finding the
containing namespace through the project, also get try to get it from
the group or namespace.

Because we moved the responsibility of looking up the root namespace to
the scope #for_resource in CustomEmoji, we can rely on that.

This fixes custom emoji in Epic descriptions and notes.

Changelog: fixed
parent 289acd2f
...@@ -8,8 +8,7 @@ module Banzai ...@@ -8,8 +8,7 @@ module Banzai
IGNORED_ANCESTOR_TAGS = %w(pre code tt).to_set IGNORED_ANCESTOR_TAGS = %w(pre code tt).to_set
def call def call
return doc unless context[:project] return doc unless resource_parent
return doc unless Feature.enabled?(:custom_emoji, context[:project])
doc.xpath('descendant-or-self::text()').each do |node| doc.xpath('descendant-or-self::text()').each do |node|
content = node.to_html content = node.to_html
...@@ -50,12 +49,12 @@ module Banzai ...@@ -50,12 +49,12 @@ module Banzai
def has_custom_emoji? def has_custom_emoji?
strong_memoize(:has_custom_emoji) do strong_memoize(:has_custom_emoji) do
namespace&.custom_emoji&.any? CustomEmoji.for_resource(resource_parent).any?
end end
end end
def namespace def resource_parent
context[:project].namespace.root_ancestor context[:project] || context[:group]
end end
def custom_emoji_candidates def custom_emoji_candidates
...@@ -63,7 +62,8 @@ module Banzai ...@@ -63,7 +62,8 @@ module Banzai
end end
def all_custom_emoji def all_custom_emoji
@all_custom_emoji ||= namespace.custom_emoji.by_name(custom_emoji_candidates).index_by(&:name) @all_custom_emoji ||=
CustomEmoji.for_resource(resource_parent).by_name(custom_emoji_candidates).index_by(&:name)
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment