forked from zammad/zammad
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't use stubs for UserInfo.current_user_id because it blocks the us…
…e case where UserInfo.current_user_id is changed at runtime.
- Loading branch information
1 parent
8096ee0
commit 6606aa2
Showing
33 changed files
with
484 additions
and
244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
module KnowledgeBaseBreadcrumbHelper | ||
def render_breadcrumb_if_needed(knowledge_base, object, alternative) | ||
objects = calculate_breadcrumb_path(object, alternative) | ||
|
||
return if objects.empty? | ||
|
||
render 'knowledge_base/public/breadcrumb', | ||
{ | ||
objects: objects, | ||
knowledge_base: knowledge_base | ||
} | ||
end | ||
|
||
def calculate_breadcrumb_path(object, alternative) | ||
objects = calculate_breadcrumb_to_category(object&.parent) | ||
|
||
last = if alternative.present? && alternative.translations.any? | ||
Translation.translate(system_locale_via_uri&.locale, 'Alternative translations') | ||
else | ||
object | ||
end | ||
|
||
objects + [last].compact | ||
end | ||
|
||
def calculate_breadcrumb_to_category(category) | ||
return [] if category.blank? | ||
|
||
output = [category] | ||
|
||
parent = category | ||
while (parent = find_category(parent&.parent_id)) | ||
output << parent | ||
end | ||
|
||
output.compact.reverse | ||
end | ||
|
||
def breadcrumb_path_for(object, locale = params.fetch(:locale)) | ||
case object | ||
when KnowledgeBase | ||
help_root_path(locale: locale) | ||
when KnowledgeBase::Category | ||
help_category_path(object.translation, locale: locale) | ||
when KnowledgeBase::Answer | ||
help_answer_path(object.category.translation, object.translation, locale: locale) | ||
end | ||
end | ||
|
||
def breadcrumb_text_for(object) | ||
case object | ||
when HasTranslations | ||
object.translation.title | ||
else | ||
object | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module KnowledgeBasePublicPageTitleHelper | ||
def kb_public_page_title(leading, trailing, exception) | ||
[ | ||
leading&.translation&.title, | ||
kb_public_page_title_suffix(trailing, exception) | ||
].compact.join(' - ') | ||
end | ||
|
||
def kb_public_page_title_suffix(item, exception) | ||
return item&.translation&.title if exception.blank? | ||
|
||
suffix = case exception | ||
when :not_found | ||
'Not Found' | ||
when :alternatives | ||
'Alternative Translations' | ||
end | ||
|
||
zt(suffix) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module KnowledgeBaseRichTextHelper | ||
def prepare_rich_text_links(input) | ||
scrubber = Loofah::Scrubber.new do |node| | ||
next if node.name != 'a' | ||
next if !node.key? 'data-target-type' | ||
|
||
case node['data-target-type'] | ||
when 'knowledge-base-answer' | ||
if (translation = KnowledgeBase::Answer::Translation.find_by(id: node['data-target-id'])) | ||
path = help_answer_path(translation.answer.category.translation_preferred(translation.kb_locale), | ||
translation, | ||
locale: translation.kb_locale.system_locale.locale) | ||
|
||
node['href'] = custom_path_if_needed path, translation.kb_locale.knowledge_base | ||
else | ||
node['href'] = '#' | ||
end | ||
end | ||
end | ||
|
||
parsed = Loofah.scrub_fragment(input, scrubber).to_s.html_safe # rubocop:disable Rails/OutputSafety | ||
|
||
parsed | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module KnowledgeBaseTopBarHelper | ||
def kb_top_bar_color(object) | ||
case object | ||
when KnowledgeBase::Answer | ||
kb_answer_top_bar_color(object) | ||
when KnowledgeBase::Category | ||
kb_locale = object&.translation&.kb_locale | ||
object.public_content?(kb_locale) ? 'green' : 'yellow' | ||
when KnowledgeBase | ||
'green' | ||
end | ||
end | ||
|
||
def kb_answer_top_bar_color(answer) | ||
case answer.can_be_published_aasm.current_state | ||
when :draft | ||
'yellow' | ||
when :internal | ||
'blue' | ||
when :published | ||
'green' | ||
when :archived | ||
'grey' | ||
end | ||
end | ||
|
||
def kb_top_bar_tag(object) | ||
case object | ||
when KnowledgeBase::Answer | ||
object.can_be_published_aasm.current_state | ||
when KnowledgeBase::Category | ||
kb_locale = object&.translation&.kb_locale | ||
object.public_content?(kb_locale) ? 'Visible' : 'Invisible' | ||
when KnowledgeBase | ||
'Published' | ||
end | ||
end | ||
end |
Oops, something went wrong.