Sha256: 9fa17a6a164dd8d487d0dc1304fe700884523452a1a8dee750b04ec3028ebec5

Contents?: true

Size: 792 Bytes

Versions: 5

Compression:

Stored size: 792 Bytes

Contents

# frozen_string_literal: true
module Decidim
  # This command updates the user's notifictions 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.comments_notifications = @form.comments_notifications
      @user.replies_notifications = @form.replies_notifications
      @user.newsletter_notifications = @form.newsletter_notifications
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
decidim-core-0.1.0 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.0.8.1 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.0.7 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.0.6 app/commands/decidim/update_notifications_settings.rb
decidim-core-0.0.5 app/commands/decidim/update_notifications_settings.rb