Module: Legion::Extensions::MicrosoftTeams::Runners::Ownership

Includes:
Helpers::Lex, Helpers::Client
Included in:
Client
Defined in:
lib/legion/extensions/microsoft_teams/runners/ownership.rb

Constant Summary collapse

TEAMS_FILTER =
"resourceProvisioningOptions/Any(x:x eq 'Team')"
TEAMS_SELECT =
'id,displayName,mail'
OWNERS_SELECT =
'id,displayName,mail'

Instance Method Summary collapse

Methods included from Helpers::Client

#bot_connection, #graph_connection, #oauth_connection, #user_path

Instance Method Details

#detect_orphansObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/legion/extensions/microsoft_teams/runners/ownership.rb', line 32

def detect_orphans(**)
  conn = graph_connection(**)
  teams = fetch_all_teams(conn: conn)
  orphaned = []

  teams.each do |team|
    owners = fetch_owners(conn: conn, team_id: team['id'])
    orphaned << { id: team['id'], display_name: team['displayName'], mail: team['mail'] } if owners.empty?
  end

  { orphaned_teams: orphaned, total_scanned: teams.length, orphan_count: orphaned.length }
rescue StandardError => e
  { error: e.message }
end

#get_team_owners(team_id:) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/legion/extensions/microsoft_teams/runners/ownership.rb', line 47

def get_team_owners(team_id:, **)
  conn = graph_connection(**)
  owners = fetch_owners(conn: conn, team_id: team_id)
  { team_id: team_id, owners: owners }
rescue StandardError => e
  { error: e.message }
end

#sync_owners(team_id: nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/legion/extensions/microsoft_teams/runners/ownership.rb', line 16

def sync_owners(team_id: nil, **)
  conn = graph_connection(**)
  if team_id
    owners = fetch_owners(conn: conn, team_id: team_id)
    { owners: owners, team_count: 1, synced_at: Time.now.utc.iso8601 }
  else
    teams = fetch_all_teams(conn: conn)
    all_owners = teams.flat_map do |team|
      fetch_owners(conn: conn, team_id: team['id']).map { |o| o.merge('team_id' => team['id']) }
    end
    { owners: all_owners, team_count: teams.length, synced_at: Time.now.utc.iso8601 }
  end
rescue StandardError => e
  { error: e.message }
end