manage_controller.rb 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class KnowledgeBase::ManageController < KnowledgeBase::BaseController
  3. def init
  4. render json: assets
  5. end
  6. def activate
  7. update_activity true
  8. end
  9. def deactivate
  10. update_activity false
  11. end
  12. def server_snippets
  13. kb = KnowledgeBase.find params[:id]
  14. if kb.custom_address.blank?
  15. raise Exceptions::UnprocessableEntity, __('Please submit custom address before generating the snippet')
  16. end
  17. render json: {
  18. address: kb.custom_address,
  19. address_type: kb.custom_address_uri.host.present? ? 'domain' : 'path',
  20. snippets: {
  21. nginx: KnowledgeBase::ServerSnippetNginx.new(kb).render,
  22. apache: KnowledgeBase::ServerSnippetApache.new(kb).render
  23. }
  24. }
  25. end
  26. def update_menu_items
  27. kb = KnowledgeBase.find params[:id]
  28. affected_items = KnowledgeBase::MenuItemUpdateAction.update_using_params! kb, params_for_permission[:menu_items_sets]
  29. render json: { assets: ApplicationModel::CanAssets.reduce(affected_items || [], {}) }
  30. end
  31. def destroy
  32. KnowledgeBase.find(params[:id]).full_destroy!
  33. render json: { status: :ok }
  34. end
  35. private
  36. def update_activity(status)
  37. kb = KnowledgeBase.find params[:id]
  38. kb.update! active: status
  39. render json: kb.assets({})
  40. end
  41. def assets
  42. %w[
  43. KnowledgeBase
  44. KnowledgeBase::Locale
  45. KnowledgeBase::MenuItem
  46. ].each_with_object({}) do |model, assets|
  47. model.constantize.find_in_batches do |group|
  48. assets = ApplicationModel::CanAssets.reduce(group, assets)
  49. end
  50. end
  51. end
  52. def klass
  53. KnowledgeBase
  54. end
  55. def params_for_permission
  56. params.permit!
  57. end
  58. end