knowledge_base_visibility_class_helper.rb 872 B

123456789101112131415161718192021222324252627282930313233
  1. module KnowledgeBaseVisibilityClassHelper
  2. def visibility_class_name(object)
  3. return if !current_user&.permissions?('knowledge_base.editor')
  4. suffix = case object
  5. when CanBePublished
  6. visiblity_class_suffix_can_be_published(object)
  7. when KnowledgeBase::Category
  8. visiblity_class_suffix_category(object)
  9. end
  10. "kb-item--#{suffix}" if suffix
  11. end
  12. def visiblity_class_suffix_can_be_published(object)
  13. state_suffix_map = {
  14. internal: 'internal',
  15. archived: 'archived',
  16. draft: 'not-published',
  17. }
  18. state_suffix_map[object.can_be_published_aasm.current_state]
  19. end
  20. def visiblity_class_suffix_category(object)
  21. return if object.public_content?
  22. if object.self_with_children_answers.only_internal.any?
  23. 'internal'
  24. else
  25. 'empty'
  26. end
  27. end
  28. end