delete.rb 714 B

123456789101112131415161718192021222324
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Mutations
  3. class User::Current::AccessToken::Delete < BaseMutation
  4. description 'Deletes user access token'
  5. argument :token_id, GraphQL::Types::ID, loads: Gql::Types::TokenType, description: 'The token o be deleted'
  6. field :success, Boolean, null: false, description: 'Was the access token deletion successful?'
  7. def self.authorize(_obj, ctx)
  8. ctx.current_user.permissions?('user_preferences.access_token')
  9. end
  10. def resolve(token:)
  11. token.destroy!
  12. { success: true }
  13. end
  14. def authorized?(token:)
  15. Pundit.authorize(context.current_user, token, :destroy?)
  16. end
  17. end
  18. end