Sha256: dd72aee33afe13aaf7cf06e8caca2c315bd7935aaa957565ad2b1598b164e88b

Contents?: true

Size: 1.01 KB

Versions: 40

Compression:

Stored size: 1.01 KB

Contents

class Eco::API::Common::People::DefaultParsers::PolicyGroupsParser < Eco::API::Common::Loaders::Parser
  attribute "policy_group_ids"
  parsing_phase :final

  def parser(hash, _deps)
    policy_group_ids = hash["policy_group_ids"] || []
    policy_group_ids.map do |name|
      policy_groups.to_id(name&.downcase&.strip).tap do |known|
        unless !name || known || unknown_pgs.include?(name)
          unknown_pgs.push(name)
          log(:warn) { "Unknown Policy Group: '#{name}'" }
        end
      end
    end.compact.tap do |pg_names|
      pg_names.push(default_id) if pg_names.empty?
    end
  end

  def serializer(person, _deps)
    ids = person&.account&.policy_group_ids || []
    ids.map do |id|
      policy_groups.to_name(id)
    end.compact
  end

  private

  def unknown_pgs
    @unknown_pgs ||= []
  end

  def default_id
    @default_id ||= policy_groups.to_id(config.people.default_usergroup)
  end

  def policy_groups
    @policy_groups ||= config.policy_groups
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

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