Sha256: e3c3ce38f7d8e9492b4229eb137d0eb3465a19e4f64f944975b16847e437140d

Contents?: true

Size: 792 Bytes

Versions: 12

Compression:

Stored size: 792 Bytes

Contents

# frozen_string_literal: true

module Decidim
  # This command updates the user's notifications settings.
  class UpdateNotificationsSettings < Rectify::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.email_on_notification = @form.email_on_notification
      @user.newsletter_notifications_at = @form.newsletter_notifications_at
      @user.notification_types = @form.notification_types
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
decidim-core-0.21.0 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.20.1 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.20.0 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.19.1 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.18.1 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.19.0 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.17.2 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.18.0 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.17.1 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.16.1 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.17.0 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.16.0 app/commands/decidim/update_notifications_settings.rb