Class: Entitlements::Extras::LDAPGroup::Filters::MemberOfLDAPGroup

Inherits:
Data::Groups::Calculated::Filters::Base show all
Includes:
Contracts::Core
Defined in:
lib/entitlements/extras/ldap_group/filters/member_of_ldap_group.rb

Constant Summary collapse

C =
::Contracts

Instance Method Summary collapse

Methods included from Contracts::Core

common, extended, included

Methods inherited from Data::Groups::Calculated::Filters::Base

#initialize

Constructor Details

This class inherits a constructor from Entitlements::Data::Groups::Calculated::Filters::Base

Instance Method Details

#filtered?(member) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
# File 'lib/entitlements/extras/ldap_group/filters/member_of_ldap_group.rb', line 20

def filtered?(member)
  return false if filter == :all
  return false unless member_of_ldap_group?(member, config.fetch("ldap_group"))
  return true if filter == :none
  !member_of_filter?(member)
end

#member_of_ldap_group?(member, group_dn) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
41
42
43
44
45
# File 'lib/entitlements/extras/ldap_group/filters/member_of_ldap_group.rb', line 35

def member_of_ldap_group?(member, group_dn)
  Entitlements.cache[:member_of_ldap_group] ||= {}
  Entitlements.cache[:member_of_ldap_group][group_dn] ||= begin
    member_set = Entitlements::Extras::LDAPGroup::Rules::LDAPGroup.matches(value: group_dn)
    member_set.map { |person| person.uid.downcase }
  rescue Entitlements::Data::Groups::GroupNotFoundError
    []
  end

  Entitlements.cache[:member_of_ldap_group][group_dn].include?(member.uid.downcase)
end