overview_sortings_controller.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class User::OverviewSortingsController < ApplicationController
  3. prepend_before_action :authenticate_and_authorize!
  4. def index
  5. render json: {
  6. overviews: Ticket::Overviews.all(current_user: current_user),
  7. overview_sortings: User::OverviewSorting.where(user: current_user),
  8. }
  9. end
  10. def show
  11. model_show_render(User::OverviewSorting, params)
  12. end
  13. def create
  14. model_create_render(User::OverviewSorting, params)
  15. end
  16. def update
  17. model_update_render(User::OverviewSorting, params)
  18. end
  19. def destroy
  20. ActiveRecord::Base.transaction do
  21. model_destroy_render(User::OverviewSorting, params)
  22. end
  23. Gql::Subscriptions::User::Current::OverviewOrderingUpdates
  24. .trigger_by(current_user)
  25. end
  26. def prio
  27. overview_ids = params[:prios].map(&:first)
  28. authorized_overviews = Ticket::Overviews
  29. .all(current_user:)
  30. .where(id: overview_ids)
  31. .sort_by { |elem| overview_ids.index(elem.id) }
  32. Service::User::Overview::UpdateOrder
  33. .new(current_user, authorized_overviews)
  34. .execute
  35. Gql::Subscriptions::User::Current::OverviewOrderingUpdates
  36. .trigger_by(current_user)
  37. render json: { success: true }, status: :ok
  38. end
  39. end