Sha256: 1a847b641620ecf6361f10e846be6dfcfadb3f8b41855b415f19842e8ee26370

Contents?: true

Size: 1.26 KB

Versions: 139

Compression:

Stored size: 1.26 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)
        unless options.dig(:exclude, :account)
          unless 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
        end
      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

139 entries across 139 versions & 1 rubygems

Version Path
eco-helpers-2.3.3 lib/eco/api/microcases/fix_default_group.rb
eco-helpers-2.3.2 lib/eco/api/microcases/fix_default_group.rb
eco-helpers-2.2.5 lib/eco/api/microcases/fix_default_group.rb
eco-helpers-2.2.4 lib/eco/api/microcases/fix_default_group.rb
eco-helpers-2.2.3 lib/eco/api/microcases/fix_default_group.rb
eco-helpers-2.2.2 lib/eco/api/microcases/fix_default_group.rb
eco-helpers-2.2.1 lib/eco/api/microcases/fix_default_group.rb
eco-helpers-2.1.12 lib/eco/api/microcases/fix_default_group.rb
eco-helpers-2.1.11 lib/eco/api/microcases/fix_default_group.rb
eco-helpers-2.1.10 lib/eco/api/microcases/fix_default_group.rb
eco-helpers-2.1.9 lib/eco/api/microcases/fix_default_group.rb
eco-helpers-2.1.8 lib/eco/api/microcases/fix_default_group.rb
eco-helpers-2.1.7 lib/eco/api/microcases/fix_default_group.rb
eco-helpers-2.1.6 lib/eco/api/microcases/fix_default_group.rb
eco-helpers-2.1.5 lib/eco/api/microcases/fix_default_group.rb
eco-helpers-2.1.4 lib/eco/api/microcases/fix_default_group.rb
eco-helpers-2.1.3 lib/eco/api/microcases/fix_default_group.rb
eco-helpers-2.1.2 lib/eco/api/microcases/fix_default_group.rb
eco-helpers-2.1.1 lib/eco/api/microcases/fix_default_group.rb
eco-helpers-2.0.68 lib/eco/api/microcases/fix_default_group.rb