Class: EgovUtils::RefreshGroups

Inherits:
Object
  • Object
show all
Defined in:
app/services/egov_utils/refresh_groups.rb

Instance Method Summary collapse

Instance Method Details

#callObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/services/egov_utils/refresh_groups.rb', line 4

def call
  hsh = remote_groups.each_with_object({}) do |group, memo|
    infos = group.ldap_members
    infos.each do |info|
      memo[info] ||= []
      memo[info] << group
    end
  end

  hsh.each do |info, groups|
    user = EgovUtils::User.where("login ILIKE ?", info[:login]).first
    next unless user

    all_groups = user.groups.where(ldap_uid: nil) + groups
    info[:login] = info[:login].downcase
    info[:mail] = info[:mail].downcase
    user.update(info.except(:dn).merge(groups: all_groups))
  end
end