Sha256: a7978f561b2879d793473dbe2f1d94dc5013fa1d605507090a1122c37686cddb

Contents?: true

Size: 712 Bytes

Versions: 38

Compression:

Stored size: 712 Bytes

Contents

# frozen_string_literal: true

module Decidim
  # This command updates the user's interests.
  class UpdateUserInterests < Rectify::Command
    # Updates a user's intersts.
    #
    # 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_interests
      @user.save!

      broadcast(:ok)
    end

    private

    def update_interests
      @user.extended_data ||= {}
      @user.extended_data["interested_scopes"] = selected_scopes_ids
    end

    def selected_scopes_ids
      @form.scopes.select(&:checked).map(&:id)
    end
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
decidim-core-0.26.1 app/commands/decidim/update_user_interests.rb
decidim-core-0.26.0 app/commands/decidim/update_user_interests.rb
decidim-core-0.26.0.rc2 app/commands/decidim/update_user_interests.rb
decidim-core-0.26.0.rc1 app/commands/decidim/update_user_interests.rb
decidim-core-0.25.2 app/commands/decidim/update_user_interests.rb
decidim-core-0.25.1 app/commands/decidim/update_user_interests.rb
decidim-core-0.25.0 app/commands/decidim/update_user_interests.rb
decidim-core-0.25.0.rc4 app/commands/decidim/update_user_interests.rb
decidim-core-0.25.0.rc3 app/commands/decidim/update_user_interests.rb
decidim-core-0.25.0.rc2 app/commands/decidim/update_user_interests.rb
decidim-core-0.25.0.rc1 app/commands/decidim/update_user_interests.rb
decidim-core-0.24.3 app/commands/decidim/update_user_interests.rb
decidim-core-0.23.6 app/commands/decidim/update_user_interests.rb
decidim-core-0.24.2 app/commands/decidim/update_user_interests.rb
decidim-core-0.23.5 app/commands/decidim/update_user_interests.rb
decidim-core-0.24.1 app/commands/decidim/update_user_interests.rb
decidim-core-0.24.0 app/commands/decidim/update_user_interests.rb
decidim-core-0.24.0.rc2 app/commands/decidim/update_user_interests.rb
decidim-core-0.23.4 app/commands/decidim/update_user_interests.rb
decidim-core-0.24.0.rc1 app/commands/decidim/update_user_interests.rb