Sha256: deb4c581bdc5c0e0a1befe483d1a8cfe5fb58d46fa7601c064ada728e8d134f2

Contents?: true

Size: 775 Bytes

Versions: 19

Compression:

Stored size: 775 Bytes

Contents

# frozen_string_literal: true

module Decidim
  # This command updates the user's interests.
  class UpdateUserInterests < Decidim::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.map do |scope|
        next unless scope.checked?

        scope.id.to_i
      end.compact
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

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