add.rb 640 B

12345678910111213141516171819202122
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. class Service::Avatar::Add < Service::BaseWithCurrentUser
  3. def execute(full_image:, resize_image:)
  4. Avatar.add(
  5. object: 'User',
  6. o_id: current_user.id,
  7. full: {
  8. content: full_image[:content],
  9. mime_type: full_image[:mime_type],
  10. },
  11. resize: {
  12. content: resize_image[:content],
  13. mime_type: resize_image[:mime_type],
  14. },
  15. source: "upload #{Time.zone.now}",
  16. deletable: true,
  17. ).tap do |avatar|
  18. current_user.update!(image: avatar.store_hash)
  19. end
  20. end
  21. end