locale.rb 776 B

1234567891011121314151617181920212223242526
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Mutations
  3. class User::Current::Locale < BaseMutation
  4. description 'Update the language of the currently logged in user'
  5. argument :locale, String, 'The locale to use, e.g. "de-de".'
  6. field :success, Boolean, null: false, description: 'Was the update successful?'
  7. def self.authorize(_obj, ctx)
  8. ctx.current_user.permissions?('user_preferences.language')
  9. end
  10. def resolve(locale:)
  11. if !Locale.exists?(locale: locale, active: true)
  12. raise ActiveRecord::RecordNotFound, __('Locale could not be found.')
  13. end
  14. context.current_user.preferences['locale'] = locale
  15. context.current_user.save!
  16. { success: true }
  17. end
  18. end
  19. end