update_order.rb 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Mutations
  3. class User::Current::Overview::UpdateOrder < BaseMutation
  4. description 'Update the overview sorting for the current user'
  5. argument :overview_ids, [GraphQL::Types::ID], description: 'The ordered list of overviews' # , loads: Gql::Types::OverviewType
  6. field :success, Boolean, null: false, description: 'Was the reset successful?'
  7. def self.authorize(_obj, ctx)
  8. ctx.current_user.permissions?('user_preferences.overview_sorting')
  9. end
  10. def resolve(overview_ids:)
  11. Service::User::Overview::UpdateOrder
  12. .new(context.current_user, authorized_overviews(overview_ids))
  13. .execute
  14. Gql::Subscriptions::User::Current::OverviewOrderingUpdates
  15. .trigger_by(context.current_user)
  16. { success: true }
  17. end
  18. private
  19. def authorized_overviews(overview_ids)
  20. overview_ids
  21. .filter_map { |elem| load(elem) }
  22. end
  23. def load(gql_id)
  24. Gql::ZammadSchema
  25. .authorized_object_from_id(gql_id, type: Overview, user: context.current_user, query: :use?)
  26. rescue Exceptions::Forbidden
  27. nil
  28. end
  29. end
  30. end