ticket_checklist_items_controller.rb 853 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class TicketChecklistItemsController < ApplicationController
  3. prepend_before_action :authenticate_and_authorize!
  4. def create
  5. new_item = checklist.items.create!(checklist_params)
  6. render json: { id: new_item.id, assets: checklist.assets({}) }
  7. end
  8. def update
  9. checklist_item.update!(checklist_params)
  10. render json: { success: true }
  11. end
  12. def destroy
  13. checklist_item.destroy!
  14. render json: { success: true }
  15. end
  16. private
  17. def checklist
  18. @checklist ||= Checklist.find_by(ticket: params[:ticket_id])
  19. raise ActiveRecord::RecordNotFound if !@checklist
  20. @checklist
  21. end
  22. def checklist_item
  23. @checklist_item ||= checklist.items.find_by(id: params[:id])
  24. end
  25. def checklist_params
  26. params.permit(:text, :checked)
  27. end
  28. end