Sha256: 5e80cb9819170f96529afcc4c02a822ebe4fa11de1414f3a63c33eb4dbc80d77

Contents?: true

Size: 1.02 KB

Versions: 28

Compression:

Stored size: 1.02 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)
          logger.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

28 entries across 28 versions & 1 rubygems

Version Path
eco-helpers-2.4.4 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.4.3 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.4.2 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.3.3 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.3.2 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.2.5 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.2.4 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb
eco-helpers-2.2.3 lib/eco/api/common/people/default_parsers/policy_groups_parser.rb