create.rb 658 B

123456789101112131415161718192021222324252627282930
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Service::User::AccessToken::Create < Service::Base
  3. attr_reader :user, :name, :permission, :expires_at
  4. def initialize(user, name:, permission:, expires_at: nil)
  5. super()
  6. @user = user
  7. @name = name
  8. @permission = permission
  9. @expires_at = expires_at
  10. end
  11. def execute
  12. Token
  13. .where(
  14. action: 'api',
  15. persistent: true,
  16. )
  17. .create!(
  18. name: name,
  19. user: user,
  20. expires_at: expires_at,
  21. preferences: {
  22. permission: permission
  23. }
  24. )
  25. end
  26. end