select.rb 1006 B

12345678910111213141516171819202122232425262728
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. module Gql::Mutations
  3. class User::Current::Avatar::Select < BaseMutation
  4. description 'Select avatar for the currently logged in user.'
  5. argument :id, GraphQL::Types::ID, description: 'The unique identifier of the avatar which should be selected.'
  6. field :success, Boolean, null: false, description: 'Was the avatar selection successful?'
  7. def self.authorize(_obj, ctx)
  8. ctx.current_user.permissions?('user_preferences.avatar')
  9. end
  10. def resolve(id:)
  11. avatar_id = Gql::ZammadSchema.verified_object_from_id(id, type: Avatar).id
  12. if avatar_id.blank? || Avatar.find_by(id: avatar_id, o_id: context.current_user.id).blank?
  13. raise ActiveRecord::RecordNotFound, __('Avatar could not be found.')
  14. end
  15. avatar = Avatar.set_default('User', context.current_user.id, avatar_id)
  16. context.current_user.update!(image: avatar.store_hash)
  17. { success: true }
  18. end
  19. end
  20. end