update.rb 677 B

123456789101112131415161718192021222324252627282930
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Service::User::CalendarSubscription::Update < Service::Base
  3. attr_reader :user, :input
  4. def initialize(user, input:)
  5. super()
  6. @user = user
  7. @input = input
  8. end
  9. def execute
  10. user.preferences[:calendar_subscriptions] ||= {}
  11. user.preferences[:calendar_subscriptions][:tickets] = build_subscription_preferences(input)
  12. user.save!
  13. end
  14. private
  15. def build_subscription_preferences(input)
  16. output = { alarm: input[:alarm] }
  17. %i[new_open pending escalation]
  18. .each_with_object(output) do |elem, memo|
  19. memo[elem] = input[elem]
  20. end
  21. end
  22. end