retry_media_download.rb 1.0 KB

12345678910111213141516171819202122232425262728
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Mutations
  3. class Ticket::Article::RetryMediaDownload < BaseMutation
  4. description "Retry an article's media download."
  5. argument :article_id, GraphQL::Types::ID, loads: Gql::Types::Ticket::ArticleType, description: 'Retry the security process for this article.'
  6. field :success, Boolean, description: 'Was the operation successful?'
  7. field :article, Gql::Types::Ticket::ArticleType, description: 'Updated article (article is not updated in case of an error result).'
  8. def self.authorize(_obj, ctx)
  9. ctx.current_user.permissions?('ticket.agent')
  10. end
  11. def authorized?(article:)
  12. Pundit.authorize(context.current_user, article, :update?)
  13. end
  14. def resolve(article:)
  15. Whatsapp::Retry::Media.new(article:).process
  16. { success: true, article: article.reload }
  17. rescue Whatsapp::Retry::Media::ArticleInvalidError, Whatsapp::Client::CloudAPIError => e
  18. error_response({ message: e.message })
  19. end
  20. end
  21. end