add.rb 798 B

123456789101112131415161718192021222324252627
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Mutations
  3. class User::Current::AccessToken::Add < BaseMutation
  4. description 'Create a new user access token'
  5. argument :input, Gql::Types::Input::User::AccessTokenInputType, description: 'The token data'
  6. field :token_value, String, null: false, description: 'The token itself, shown once'
  7. field :token, Gql::Types::TokenType, description: 'The token data'
  8. def self.authorize(_obj, ctx)
  9. ctx.current_user.permissions?('user_preferences.access_token')
  10. end
  11. def resolve(input:)
  12. token = Service::User::AccessToken::Create
  13. .new(context.current_user, **input)
  14. .execute
  15. {
  16. token:,
  17. token_value: token.token
  18. }
  19. end
  20. end
  21. end