Skip to content

Commit 857c223

Browse files
committed
chore: add global policies view
1 parent 2e8607d commit 857c223

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-0
lines changed

otterdog/webapp/home/routes.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import json
1010
import os.path
11+
from collections.abc import Mapping, MutableMapping
1112
from typing import Any
1213

1314
from quart import (
@@ -457,6 +458,28 @@ async def blueprints():
457458
return await render_home_template("blueprints.html")
458459

459460

461+
@blueprint.route("/admin/policies")
462+
async def policies():
463+
all_orgs = [x.github_id for x in await get_installations()]
464+
aggregate_status = {}
465+
for github_id in all_orgs:
466+
org_status = {x.id.policy_type: x.status for x in await get_policies_status(github_id)}
467+
_merge_policy_status(aggregate_status, org_status)
468+
469+
return await render_home_template("policies.html", policy_status=aggregate_status)
470+
471+
472+
def _merge_policy_status(aggregate_status: MutableMapping[str, Any], org_status: Mapping[str, Any]) -> None:
473+
def merge_dict(a: Mapping[str, Any], b: Mapping[str, Any]) -> dict[str, int]:
474+
return {k: a.get(k, 0) + b.get(k, 0) for k in set(a).union(set(b))}
475+
476+
for policy_type, status in org_status.items():
477+
if policy_type in aggregate_status:
478+
aggregate_status[policy_type] = merge_dict(aggregate_status[policy_type], status)
479+
else:
480+
aggregate_status.update({policy_type: status})
481+
482+
460483
@blueprint.route("/admin/tasks")
461484
async def tasks():
462485
return await render_home_template("tasks.html")
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{% extends "layouts/base.html" %}
2+
3+
{% block title %} Policies {% endblock %}
4+
5+
<!-- Element injected in the BODY element -->
6+
{% block body_class %} {% endblock body_class %}
7+
8+
<!-- Specific Page CSS goes HERE -->
9+
{% block stylesheets %}
10+
{{ super() }}
11+
<!-- jsGrid -->
12+
<link rel="stylesheet" href="/assets/vendor/jsgrid/jsgrid.min.css">
13+
<link rel="stylesheet" href="/assets/vendor/jsgrid/jsgrid-theme.min.css">
14+
{% endblock stylesheets %}
15+
16+
{% block content %}
17+
18+
<!-- Content Wrapper. Contains page content -->
19+
<div class="content-wrapper">
20+
<!-- Content Header (Page header) -->
21+
<section class="content-header">
22+
<div class="container-fluid">
23+
<div class="row mb-2">
24+
<div class="col-sm-6">
25+
<h1>Policies</h1>
26+
</div>
27+
<div class="col-sm-6">
28+
<ol class="breadcrumb float-sm-right">
29+
<li class="breadcrumb-item"><a href="/index">Home</a></li>
30+
<li class="breadcrumb-item active">Policies</li>
31+
</ol>
32+
</div>
33+
</div>
34+
</div><!-- /.container-fluid -->
35+
</section>
36+
37+
<!-- Main content -->
38+
<section class="content">
39+
<div class="container-fluid">
40+
{% for policy_type, status in policy_status.items() %}
41+
<div class="card card-info">
42+
<div class="card-header">
43+
<h3 class="card-title">{{policy_type}}</h3>
44+
</div>
45+
<div class="card-body">
46+
<div class="table-responsive p-0">
47+
<table class="table table-hover text-nowrap">
48+
<thead>
49+
<tr>
50+
{% for key, value in status.items() %}
51+
<th>{{ key | snake_to_normal }}</th>
52+
{% endfor %}
53+
</tr>
54+
</thead>
55+
<tbody>
56+
<tr>
57+
{% for key, value in status.items() %}
58+
<td>{{ value }}</td>
59+
{% endfor %}
60+
</tr>
61+
</tbody>
62+
</table>
63+
</div>
64+
</div>
65+
</div>
66+
{% endfor %}
67+
</div>
68+
<!-- /.container-fluid -->
69+
</section>
70+
<!-- /.content -->
71+
</div>
72+
73+
{% endblock content %}
74+
75+
<!-- Specific Page JS goes HERE -->
76+
{% block javascripts %}
77+
{{ super() }}
78+
79+
<!-- jsGrid -->
80+
<script src="/assets/vendor/jsgrid/jsgrid.min.js"></script>
81+
82+
<!-- page script -->
83+
<script>
84+
</script>
85+
86+
{% endblock javascripts %}

otterdog/webapp/templates/includes/sidebar.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,15 @@
123123
</p>
124124
</a>
125125
</li>
126+
<li class="nav-item">
127+
<a href="/admin/policies" class="nav-link {% if 'policies' in segments %} active {% endif %}">
128+
<i class="nav-icon fas fa-clipboard-check"></i>
129+
<p>
130+
Policies
131+
<i class="fas nav-icon"></i>
132+
</p>
133+
</a>
134+
</li>
126135
<li class="nav-item">
127136
<a href="/admin/blueprints" class="nav-link {% if 'blueprints' in segments %} active {% endif %}">
128137
<i class="nav-icon fas fa-clipboard-check"></i>

0 commit comments

Comments
 (0)