add_first_admin.rb 1018 B

12345678910111213141516171819202122232425262728293031
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Mutations
  3. class User::AddFirstAdmin < BaseMutation
  4. include Gql::Mutations::Concerns::HandlesAuthentication
  5. description 'Add the first admin user during system set-up and log that user in.'
  6. argument :input, Gql::Types::Input::User::SignupInputType, description: 'The user data'
  7. field :session, Gql::Types::SessionType, description: 'The current session, if the user was successfully created.'
  8. def self.authorize(...)
  9. true
  10. end
  11. def resolve(input:)
  12. user = Service::User::AddFirstAdmin.new.execute(
  13. user_data: input.to_h,
  14. request: context[:controller].request,
  15. )
  16. create_session(user, false, 'password')
  17. authenticate_result
  18. rescue Service::System::CheckSetup::SystemSetupError => e
  19. error_response({ message: e.message })
  20. rescue PasswordPolicy::Error => e
  21. error_response({ message: e.message, field: 'password' })
  22. end
  23. end
  24. end