Class: Confluence::Jobs::DisableExpiredUsers
- Inherits:
-
Object
- Object
- Confluence::Jobs::DisableExpiredUsers
- Defined in:
- lib/confluence/jobs/disable_expired_users.rb
Constant Summary collapse
- MIN_GUEST_ACCOUNT_LDAP_UID =
11000000
Instance Method Summary collapse
- #confluence_admin?(username) ⇒ Boolean
-
#confluence_user_names ⇒ Array<String>
Confluence user names.
-
#disable_expired_users ⇒ Object
Disables any users that are expired in LDAP or are no longer in LDAP.
- #eligible_for_confluence?(person) ⇒ Boolean
-
#execute ⇒ Object
Run the job.
- #find_in_confluence(name) ⇒ Confluence::User?
- #find_in_ldap(ldap_uid) ⇒ UCB::LDAP::Person?
- #guest_account_user?(username) ⇒ Boolean
-
#initialize ⇒ DisableExpiredUsers
constructor
A new instance of DisableExpiredUsers.
- #log_job ⇒ Object
- #logger ⇒ Object
Constructor Details
#initialize ⇒ DisableExpiredUsers
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
26 27 28 |
# File 'lib/confluence/jobs/disable_expired_users.rb', line 26 def confluence_admin?(username) username == "conflusa" end |
#confluence_user_names ⇒ Array<String>
Returns 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_users ⇒ Object
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 guest_account_user?(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
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 |
#execute ⇒ Object
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?
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?
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
30 31 32 |
# File 'lib/confluence/jobs/disable_expired_users.rb', line 30 def guest_account_user?(username) username.to_i > MIN_GUEST_ACCOUNT_LDAP_UID end |
#log_job ⇒ Object
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 |
#logger ⇒ Object
60 61 62 |
# File 'lib/confluence/jobs/disable_expired_users.rb', line 60 def logger() Confluence.logger end |