update.rb 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Mutations
  3. class User::Update < BaseMutation
  4. description 'Update an existing user.'
  5. argument :id, GraphQL::Types::ID, description: 'The user ID', as: :current_user, loads: Gql::Types::UserType
  6. argument :input, Gql::Types::Input::UserInputType, description: 'The user data'
  7. field :user, Gql::Types::UserType, description: 'The created user.'
  8. def authorized?(current_user:, input:)
  9. Pundit.authorize(context.current_user, current_user, :update?)
  10. end
  11. def resolve(current_user:, input:)
  12. { user: update(current_user, input) }
  13. end
  14. private
  15. def update(current_user, input)
  16. user_data = input.to_h
  17. set_core_workflow_information(user_data, ::User, 'edit')
  18. Service::User::FilterPermissionAssignments.new(current_user: current_user).execute(user_data: user_data)
  19. current_user.with_lock do
  20. current_user.update!(user_data)
  21. end
  22. current_user
  23. end
  24. end
  25. end