Sha256: f9bb4ec3435c89d0391f3f53c92dd8f7602949d0f6bfe6363057cae84dea8cf7

Contents?: true

Size: 1.01 KB

Versions: 19

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

module Decidim
  # This command updates the user's notifications settings.
  class UpdateNotificationsSettings < Decidim::Command
    # Updates a user's notifications settings.
    #
    # user - The user to be updated.
    # form - The form with the data.
    def initialize(user, form)
      @user = user
      @form = form
    end

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

      update_notifications_settings
      @user.save!

      broadcast(:ok, @user)
    end

    private

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

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
decidim-core-0.28.4 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.27.9 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.28.3 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.27.8 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.28.2 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.27.7 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.28.1 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.27.6 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.28.0 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.27.5 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.28.0.rc5 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.28.0.rc4 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.27.4 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.27.3 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.27.2 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.27.1 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.27.0 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.27.0.rc2 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.27.0.rc1 app/commands/decidim/update_notifications_settings.rb