Sha256: ed66323479a92e7053d4e8f558fe44e1477aa9bd7851fb25635b73999c6cbd12

Contents?: true

Size: 602 Bytes

Versions: 5

Compression:

Stored size: 602 Bytes

Contents

module EgovUtils
  class RefreshGroups

    def call
      hsh = 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.find_by(login: info[:login])
        next unless user

        all_groups = user.groups.where(ldap_uid: nil) + groups
        user.update(info.merge(groups: all_groups))
      end
    end

    private

    def groups
      EgovUtils::Group.where.not(ldap_uid: nil)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
egov_utils-1.2.4 app/services/egov_utils/refresh_groups.rb
egov_utils-1.2.3 app/services/egov_utils/refresh_groups.rb
egov_utils-1.2.2 app/services/egov_utils/refresh_groups.rb
egov_utils-1.2.1 app/services/egov_utils/refresh_groups.rb
egov_utils-1.2.0 app/services/egov_utils/refresh_groups.rb