Sha256: 6af1076ebf8764421b0b8071f29edb314d719825000df68e084b99e3ac128a7a

Contents?: true

Size: 1.23 KB

Versions: 23

Compression:

Stored size: 1.23 KB

Contents

module Eco
  module API
    class MicroCases
      # If defined, it sets the default usergroup, only when the `policy_group_ids` was not part of the input data.
      # @param entry [PersonEntry] the input entry with the data we should set on person.
      # @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done.
      # @param options [Hash] the options.
      def fix_default_group(entry, person, options)
        return if options.dig(:exclude, :account)
        return if options.dig(:exclude, :policy_groups) && !person.new?

        end_pg_ids = person.account.policy_group_ids

        if person.account_added? && __def_usergroup_id && !entry.policy_group_ids?
          # on account creation, if missing policy_group_ids column in the input
          # use default_usergroup, if it's defined
          end_pg_ids = [__def_usergroup_id]
        end

        person.account.policy_group_ids = end_pg_ids
      end

      private

      def __def_usergroup_id
        @__def_usergroup_id ||=
          if session.config.people.default_usergroup?
            session.policy_groups.to_id(session.config.people.default_usergroup)
          end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
eco-helpers-3.0.21 lib/eco/api/microcases/fix_default_group.rb
eco-helpers-3.0.20 lib/eco/api/microcases/fix_default_group.rb
eco-helpers-3.0.19 lib/eco/api/microcases/fix_default_group.rb
eco-helpers-3.0.18 lib/eco/api/microcases/fix_default_group.rb
eco-helpers-3.0.17 lib/eco/api/microcases/fix_default_group.rb
eco-helpers-3.0.16 lib/eco/api/microcases/fix_default_group.rb
eco-helpers-3.0.15 lib/eco/api/microcases/fix_default_group.rb
eco-helpers-3.0.14 lib/eco/api/microcases/fix_default_group.rb
eco-helpers-3.0.13 lib/eco/api/microcases/fix_default_group.rb
eco-helpers-3.0.12 lib/eco/api/microcases/fix_default_group.rb
eco-helpers-3.0.11 lib/eco/api/microcases/fix_default_group.rb
eco-helpers-3.0.10 lib/eco/api/microcases/fix_default_group.rb
eco-helpers-3.0.9 lib/eco/api/microcases/fix_default_group.rb
eco-helpers-3.0.8 lib/eco/api/microcases/fix_default_group.rb
eco-helpers-3.0.7 lib/eco/api/microcases/fix_default_group.rb
eco-helpers-3.0.6 lib/eco/api/microcases/fix_default_group.rb
eco-helpers-3.0.5 lib/eco/api/microcases/fix_default_group.rb
eco-helpers-3.0.4 lib/eco/api/microcases/fix_default_group.rb
eco-helpers-3.0.3 lib/eco/api/microcases/fix_default_group.rb
eco-helpers-3.0.2 lib/eco/api/microcases/fix_default_group.rb