Sha256: 249f503a784949a7cd0640a8febfb2de961683f5c60febe81c208123f392b65e

Contents?: true

Size: 1.07 KB

Versions: 6

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module Decidim
  # This command updates the user's notifications settings.
  class UpdateNotificationsSettings < Decidim::Command
    delegate :current_user, to: :form

    # Updates a user's notifications settings.
    #
    # form - The form with the data.
    def initialize(form)
      @form = form
    end

    def call
      return broadcast(:invalid) unless @form.valid?

      update_notifications_settings
      current_user.save!

      broadcast(:ok, current_user)
    end

    private

    attr_reader :form

    def update_notifications_settings
      current_user.newsletter_notifications_at = @form.newsletter_notifications_at
      current_user.notification_types = @form.notification_types
      current_user.direct_message_types = @form.direct_message_types
      current_user.email_on_moderations = @form.email_on_moderations
      current_user.notification_settings = current_user.notification_settings.merge(@form.notification_settings)
      current_user.notifications_sending_frequency = @form.notifications_sending_frequency
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
decidim-core-0.29.1 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.29.0 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.29.0.rc4 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.29.0.rc3 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.29.0.rc2 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.29.0.rc1 app/commands/decidim/update_notifications_settings.rb