Class: Confluence::Jobs::DisableExpiredUsers

Inherits:
Object
  • Object
show all
Defined in:
lib/confluence/jobs/disable_expired_users.rb

Constant Summary collapse

MIN_GUEST_ACCOUNT_LDAP_UID =
11000000

Instance Method Summary collapse

Constructor Details

#initializeDisableExpiredUsers

Returns a new instance of DisableExpiredUsers.



13
14
15
# File 'lib/confluence/jobs/disable_expired_users.rb', line 13

def initialize()
  @disabled_users = []
end

Instance Method Details

#confluence_admin?(username) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/confluence/jobs/disable_expired_users.rb', line 26

def confluence_admin?(username)
  username == "conflusa"
end

#confluence_user_namesArray<String>

Returns confluence user names.

Returns:

  • (Array<String>)

    confluence user names.



67
68
69
# File 'lib/confluence/jobs/disable_expired_users.rb', line 67

def confluence_user_names()
  Confluence::User.active.map(&:name)
end

#disable_expired_usersObject

Disables any users that are expired in LDAP or are no longer in LDAP.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/confluence/jobs/disable_expired_users.rb', line 37

def disable_expired_users()
  confluence_user_names.each do |name|

    next if confluence_admin?(name)
    next if (name)

    ldap_person = find_in_ldap(name)
    
    if ldap_person.nil? || !eligible_for_confluence?(ldap_person)
      user = find_in_confluence(name)
      user.disable()
      @disabled_users << user        
    end
  end
end

#eligible_for_confluence?(person) ⇒ Boolean

Returns:

  • (Boolean)


87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/confluence/jobs/disable_expired_users.rb', line 87

def eligible_for_confluence?(person)
  valid_affiliations = person.affiliations.inject([]) do |accum, aff|
    if aff =~ /AFFILIATE-TYPE.*(ALUMNUS|RETIREE|EXPIRED|ADVCON)/
      accum
    elsif aff =~ /AFFILIATE-TYPE.*/
      accum << aff
    end
    accum
  end
  
  person.employee? || !valid_affiliations.empty?
end

#executeObject

Run the job



20
21
22
23
24
# File 'lib/confluence/jobs/disable_expired_users.rb', line 20

def execute()
  @disabled_users.clear()
  disable_expired_users()
  log_job()
end

#find_in_confluence(name) ⇒ Confluence::User?

Parameters:

  • user's (String)

    confluence account name.

Returns:



75
76
77
# File 'lib/confluence/jobs/disable_expired_users.rb', line 75

def find_in_confluence(name)
  Confluence::User.find_by_name(name)
end

#find_in_ldap(ldap_uid) ⇒ UCB::LDAP::Person?

Parameters:

  • user's (String)

    ldap uid

Returns:

  • (UCB::LDAP::Person, nil)


83
84
85
# File 'lib/confluence/jobs/disable_expired_users.rb', line 83

def find_in_ldap(ldap_uid)
  UCB::LDAP::Person.find_by_uid(ldap_uid)
end

#guest_account_user?(username) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/confluence/jobs/disable_expired_users.rb', line 30

def (username)
  username.to_i > MIN_GUEST_ACCOUNT_LDAP_UID
end

#log_jobObject



53
54
55
56
57
58
# File 'lib/confluence/jobs/disable_expired_users.rb', line 53

def log_job()
  msg = "#{self.class.name}\n\n"
  msg.concat("Disabled the following Users:\n\n")
  @disabled_users.each { |u| msg.concat(u.to_s()) }
  logger.info(msg)
end

#loggerObject



60
61
62
# File 'lib/confluence/jobs/disable_expired_users.rb', line 60

def logger()
  Confluence.logger
end