Skip to content

Commit

Permalink
chore: add global policies view
Browse files Browse the repository at this point in the history
  • Loading branch information
netomi committed Dec 20, 2024
1 parent 2e8607d commit 857c223
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 0 deletions.
23 changes: 23 additions & 0 deletions otterdog/webapp/home/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import json
import os.path
from collections.abc import Mapping, MutableMapping
from typing import Any

from quart import (
Expand Down Expand Up @@ -457,6 +458,28 @@ async def blueprints():
return await render_home_template("blueprints.html")


@blueprint.route("/admin/policies")
async def policies():
all_orgs = [x.github_id for x in await get_installations()]
aggregate_status = {}
for github_id in all_orgs:
org_status = {x.id.policy_type: x.status for x in await get_policies_status(github_id)}
_merge_policy_status(aggregate_status, org_status)

return await render_home_template("policies.html", policy_status=aggregate_status)


def _merge_policy_status(aggregate_status: MutableMapping[str, Any], org_status: Mapping[str, Any]) -> None:
def merge_dict(a: Mapping[str, Any], b: Mapping[str, Any]) -> dict[str, int]:
return {k: a.get(k, 0) + b.get(k, 0) for k in set(a).union(set(b))}

for policy_type, status in org_status.items():
if policy_type in aggregate_status:
aggregate_status[policy_type] = merge_dict(aggregate_status[policy_type], status)
else:
aggregate_status.update({policy_type: status})


@blueprint.route("/admin/tasks")
async def tasks():
return await render_home_template("tasks.html")
Expand Down
86 changes: 86 additions & 0 deletions otterdog/webapp/templates/home/policies.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{% extends "layouts/base.html" %}

{% block title %} Policies {% endblock %}

<!-- Element injected in the BODY element -->
{% block body_class %} {% endblock body_class %}

<!-- Specific Page CSS goes HERE -->
{% block stylesheets %}
{{ super() }}
<!-- jsGrid -->
<link rel="stylesheet" href="/assets/vendor/jsgrid/jsgrid.min.css">
<link rel="stylesheet" href="/assets/vendor/jsgrid/jsgrid-theme.min.css">
{% endblock stylesheets %}

{% block content %}

<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h1>Policies</h1>
</div>
<div class="col-sm-6">
<ol class="breadcrumb float-sm-right">
<li class="breadcrumb-item"><a href="/index">Home</a></li>
<li class="breadcrumb-item active">Policies</li>
</ol>
</div>
</div>
</div><!-- /.container-fluid -->
</section>

<!-- Main content -->
<section class="content">
<div class="container-fluid">
{% for policy_type, status in policy_status.items() %}
<div class="card card-info">
<div class="card-header">
<h3 class="card-title">{{policy_type}}</h3>
</div>
<div class="card-body">
<div class="table-responsive p-0">
<table class="table table-hover text-nowrap">
<thead>
<tr>
{% for key, value in status.items() %}
<th>{{ key | snake_to_normal }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
<tr>
{% for key, value in status.items() %}
<td>{{ value }}</td>
{% endfor %}
</tr>
</tbody>
</table>
</div>
</div>
</div>
{% endfor %}
</div>
<!-- /.container-fluid -->
</section>
<!-- /.content -->
</div>

{% endblock content %}

<!-- Specific Page JS goes HERE -->
{% block javascripts %}
{{ super() }}

<!-- jsGrid -->
<script src="/assets/vendor/jsgrid/jsgrid.min.js"></script>

<!-- page script -->
<script>
</script>

{% endblock javascripts %}
9 changes: 9 additions & 0 deletions otterdog/webapp/templates/includes/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@
</p>
</a>
</li>
<li class="nav-item">
<a href="/admin/policies" class="nav-link {% if 'policies' in segments %} active {% endif %}">
<i class="nav-icon fas fa-clipboard-check"></i>
<p>
Policies
<i class="fas nav-icon"></i>
</p>
</a>
</li>
<li class="nav-item">
<a href="/admin/blueprints" class="nav-link {% if 'blueprints' in segments %} active {% endif %}">
<i class="nav-icon fas fa-clipboard-check"></i>
Expand Down

0 comments on commit 857c223

Please sign in to comment.