Sha256: e92abfd5c9d730d52ce435fb1635ac3b55454559c9fa18dc78bc183794870d7c

Contents?: true

Size: 854 Bytes

Versions: 9

Compression:

Stored size: 854 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
      @user.direct_message_types = @form.direct_message_types
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
decidim-core-0.23.6 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.23.5 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.23.4 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.23.3 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.23.2 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.23.1 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.23.1.rc1 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.23.0 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.22.0 app/commands/decidim/update_notifications_settings.rb