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
IGNORED_ANCESTOR_TAGS = %w(pre code tt).to_set
def call
return doc unless context[:project]
return doc unless Feature.enabled?(:custom_emoji, context[:project])
return doc unless resource_parent
doc.xpath('descendant-or-self::text()').each do |node|
content = node.to_html
......@@ -50,12 +49,12 @@ module Banzai
def has_custom_emoji?
strong_memoize(:has_custom_emoji) do
namespace&.custom_emoji&.any?
CustomEmoji.for_resource(resource_parent).any?
end
end
def namespace
context[:project].namespace.root_ancestor
def resource_parent
context[:project] || context[:group]
end
def custom_emoji_candidates
......@@ -63,7 +62,8 @@ module Banzai
end
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
......
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