can_prioritize.rb 694 B

1234567891011121314151617181920212223242526
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. module CanPrioritize
  3. extend ActiveSupport::Concern
  4. def prio
  5. klass.without_callback(:update, :before, :rearrangement) do
  6. params[:prios].each do |entry_prio|
  7. entry = prio_find(entry_prio) || prio_create(entry_prio)
  8. next if entry.prio == entry_prio[1]
  9. entry.prio = entry_prio[1]
  10. entry.save!
  11. end
  12. end
  13. render json: { success: true }, status: :ok
  14. end
  15. def prio_create(entry_prio)
  16. klass.try(:prio_create, id: entry_prio[0], prio: entry_prio[1], current_user: current_user)
  17. end
  18. def prio_find(entry_prio)
  19. klass.find_by(id: entry_prio[0])
  20. end
  21. end