class Lita::Commands::ListAdmins

Public Instance Methods

name() click to toggle source
# File lib/lita/commands/list_admins.rb, line 6
def name
  'list-admins'
end
run(robot, target, gateway, opts = {}) click to toggle source
# File lib/lita/commands/list_admins.rb, line 10
def run(robot, target, gateway, opts = {})
  msg = build_msg(gateway)
  robot.send_message(target, msg) if msg
  robot.send_message(target, "No admins found") if msg.nil? && opts[:negative_ack]
end

Private Instance Methods

all_admins(gateway) click to toggle source
# File lib/lita/commands/list_admins.rb, line 29
def all_admins(gateway)
  (gateway.delegated_admins + gateway.super_admins).uniq.sort_by(&:path)
end
build_msg(gateway) click to toggle source
# File lib/lita/commands/list_admins.rb, line 18
def build_msg(gateway)
  users = all_admins(gateway)

  if users.any?
    msg = "The following accounts have administrative privileges:\n"
    msg += users.map { |user|
      "- #{user.ou_path}/#{user.email} (2fa enabled: #{tfa?(user)})"
    }.join("\n")
  end
end
tfa?(user) click to toggle source
# File lib/lita/commands/list_admins.rb, line 33
def tfa?(user)
  user.two_factor_enabled? ? "Y" : "N"
end