Sha256: 3c2d80ace54f94e5bd34ef641c37b54cc9ea1685ffce0c8d0097447fd296eaf6

Contents?: true

Size: 1005 Bytes

Versions: 2

Compression:

Stored size: 1005 Bytes

Contents

module Workarea
  decorate Storefront::Users::AccountsController, with: :mail_chimp do
    decorated { before_action :set_email_interests, only: :edit }

    private

    def user_params
      @user_params ||= super
        .merge(params.permit(:email_signup, :groups))
        .merge(sanitize_groups_param(params))
    end

    def sanitize_groups_param(params)
      @sanitize_groups_param ||= Hash[
        :groups,
        params.fetch(:groups, []).map do |group|
          {
            _id: group[:id],
            name: group[:name],
            interests: group[:interests].to_unsafe_hash
          }
        end
      ]
    end

    def set_email_interests
      key = "mail_chimp_email_interests/#{Workarea::MailChimp.config.default_store[:list_id]}"
      options = { expires_in: 1.hour }

      options.merge!(force: true) if Rails.cache.read(key).nil?

      @email_interests = Rails.cache.fetch(key, options) do
        Workarea::MailChimp.gateway.list.interests
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
workarea-mail_chimp-3.0.3 app/controllers/workarea/storefront/users/accounts_controller.decorator
workarea-mail_chimp-3.0.2 app/controllers/workarea/storefront/users/accounts_controller.decorator