2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2019-09-18 17:25:04 +00:00
|
|
|
module KnowledgeBaseVisibilityNoteHelper
|
|
|
|
def visibility_note(object)
|
2021-07-23 13:07:16 +00:00
|
|
|
return if !policy(:knowledge_base).edit?
|
2019-09-18 17:25:04 +00:00
|
|
|
|
|
|
|
text = visibility_text(object)
|
|
|
|
|
|
|
|
return if text.nil?
|
|
|
|
|
|
|
|
render 'knowledge_base/public/visibility_note', text: text
|
|
|
|
end
|
|
|
|
|
|
|
|
def visibility_text(object)
|
|
|
|
case object
|
|
|
|
when CanBePublished
|
|
|
|
visiblity_text_can_be_published(object)
|
|
|
|
when KnowledgeBase::Category
|
|
|
|
visiblity_text_category(object)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def visiblity_text_can_be_published(object)
|
2020-07-13 12:46:08 +00:00
|
|
|
state_text_map = {
|
|
|
|
internal: 'internal',
|
|
|
|
archived: 'archived',
|
|
|
|
draft: 'not published',
|
|
|
|
}
|
|
|
|
state_text_map[object.can_be_published_aasm.current_state]
|
2019-09-18 17:25:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def visiblity_text_category(object)
|
|
|
|
return if object.public_content?
|
|
|
|
|
|
|
|
if object.self_with_children_answers.only_internal.any?
|
|
|
|
'hidden, visible only internally'
|
|
|
|
else
|
|
|
|
'hidden, no published answers'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|