knowledge_base_visibility_note_helper.rb 946 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. module KnowledgeBaseVisibilityNoteHelper
  2. def visibility_note(object)
  3. return if !current_user&.permissions?('knowledge_base.editor')
  4. text = visibility_text(object)
  5. return if text.nil?
  6. render 'knowledge_base/public/visibility_note', text: text
  7. end
  8. def visibility_text(object)
  9. case object
  10. when CanBePublished
  11. visiblity_text_can_be_published(object)
  12. when KnowledgeBase::Category
  13. visiblity_text_category(object)
  14. end
  15. end
  16. def visiblity_text_can_be_published(object)
  17. state_text_map = {
  18. internal: 'internal',
  19. archived: 'archived',
  20. draft: 'not published',
  21. }
  22. state_text_map[object.can_be_published_aasm.current_state]
  23. end
  24. def visiblity_text_category(object)
  25. return if object.public_content?
  26. if object.self_with_children_answers.only_internal.any?
  27. 'hidden, visible only internally'
  28. else
  29. 'hidden, no published answers'
  30. end
  31. end
  32. end