class Lita::Commands::TwoFactorOff

Public Class Methods

new(ou_path = "/") click to toggle source
# File lib/lita/commands/two_factor_off.rb, line 6
def initialize(ou_path = "/")
  @ou_path = ou_path
end

Public Instance Methods

name() click to toggle source
# File lib/lita/commands/two_factor_off.rb, line 10
def name
  'two-factor-off'
end
run(robot, target, gateway, opts = {}) click to toggle source
# File lib/lita/commands/two_factor_off.rb, line 14
def run(robot, target, gateway, opts = {})
  msg = build_msg(gateway)
  robot.send_message(target, msg) if msg
  if msg.nil? && opts[:negative_ack]
    robot.send_message(target, "All users in #{@ou_path} have Two Factor Authentication enabled")
  end
end

Private Instance Methods

active_users_without_tfa(gateway) click to toggle source
# File lib/lita/commands/two_factor_off.rb, line 36
def active_users_without_tfa(gateway)
  gateway.users.reject { |user|
    user.suspended?
  }.reject { |user|
    user.two_factor_enabled?
  }.select { |user|
    user.ou_path == @ou_path
  }.sort_by { |user|
    user.path
  }
end
build_msg(gateway) click to toggle source
# File lib/lita/commands/two_factor_off.rb, line 24
def build_msg(gateway)
  users = active_users_without_tfa(gateway)

  if users.any?
    msg = "Users in #{@ou_path} with Two Factor Authentication disabled:\n\n"
    users.each do |user|
      msg += "- #{user.email}\n"
    end
    msg
  end
end