api: remove counters from overview api and allow filtering on object apis
This commit is contained in:
parent
3c12c8b3ff
commit
1179ba4ef2
|
@ -10,8 +10,6 @@ from rest_framework.viewsets import ViewSet
|
||||||
|
|
||||||
from authentik import __version__
|
from authentik import __version__
|
||||||
from authentik.admin.tasks import VERSION_CACHE_KEY, update_latest_version
|
from authentik.admin.tasks import VERSION_CACHE_KEY, update_latest_version
|
||||||
from authentik.core.models import Provider
|
|
||||||
from authentik.policies.models import Policy
|
|
||||||
from authentik.root.celery import CELERY_APP
|
from authentik.root.celery import CELERY_APP
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,8 +19,6 @@ class AdministrationOverviewSerializer(Serializer):
|
||||||
version = SerializerMethodField()
|
version = SerializerMethodField()
|
||||||
version_latest = SerializerMethodField()
|
version_latest = SerializerMethodField()
|
||||||
worker_count = SerializerMethodField()
|
worker_count = SerializerMethodField()
|
||||||
providers_without_application = SerializerMethodField()
|
|
||||||
policies_without_binding = SerializerMethodField()
|
|
||||||
cached_policies = SerializerMethodField()
|
cached_policies = SerializerMethodField()
|
||||||
cached_flows = SerializerMethodField()
|
cached_flows = SerializerMethodField()
|
||||||
|
|
||||||
|
@ -42,16 +38,6 @@ class AdministrationOverviewSerializer(Serializer):
|
||||||
"""Ping workers"""
|
"""Ping workers"""
|
||||||
return len(CELERY_APP.control.ping(timeout=0.5))
|
return len(CELERY_APP.control.ping(timeout=0.5))
|
||||||
|
|
||||||
def get_providers_without_application(self, _) -> int:
|
|
||||||
"""Count of providers without application"""
|
|
||||||
return len(Provider.objects.filter(application=None))
|
|
||||||
|
|
||||||
def get_policies_without_binding(self, _) -> int:
|
|
||||||
"""Count of policies not bound or use in prompt stages"""
|
|
||||||
return len(
|
|
||||||
Policy.objects.filter(bindings__isnull=True, promptstage__isnull=True)
|
|
||||||
)
|
|
||||||
|
|
||||||
def get_cached_policies(self, _) -> int:
|
def get_cached_policies(self, _) -> int:
|
||||||
"""Get cached policy count"""
|
"""Get cached policy count"""
|
||||||
return len(cache.keys("policy_*"))
|
return len(cache.keys("policy_*"))
|
||||||
|
|
|
@ -11,169 +11,6 @@
|
||||||
</section>
|
</section>
|
||||||
<section class="pf-c-page__main-section">
|
<section class="pf-c-page__main-section">
|
||||||
<div class="pf-l-gallery pf-m-gutter">
|
<div class="pf-l-gallery pf-m-gutter">
|
||||||
<div class="pf-c-card pf-c-card-aggregate pf-l-gallery__item pf-m-4-col" style="grid-column-end: span 3;grid-row-end: span 2;">
|
|
||||||
<div class="pf-c-card__header">
|
|
||||||
<div class="pf-c-card__header-main">
|
|
||||||
<i class="pf-icon pf-icon-server"></i> {% trans 'Logins over the last 24 hours' %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="pf-c-card__body">
|
|
||||||
<ak-admin-logins-chart url="{% url 'authentik_api:admin_metrics-list' %}"></ak-admin-logins-chart>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="pf-c-card pf-c-card-aggregate pf-l-gallery__item pf-m-4-col" style="grid-column-end: span 2;grid-row-end: span 3;">
|
|
||||||
<div class="pf-c-card__header">
|
|
||||||
<div class="pf-c-card__header-main">
|
|
||||||
<i class="pf-icon pf-icon-server"></i> {% trans 'Apps with most usage' %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="pf-c-card__body">
|
|
||||||
<table class="pf-c-table pf-m-compact" role="grid">
|
|
||||||
<thead>
|
|
||||||
<tr role="row">
|
|
||||||
<th role="columnheader" scope="col">{% trans 'Application' %}</th>
|
|
||||||
<th role="columnheader" scope="col">{% trans 'Logins' %}</th>
|
|
||||||
<th role="columnheader" scope="col"></th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody role="rowgroup">
|
|
||||||
{% for app in most_used_applications %}
|
|
||||||
<tr role="row">
|
|
||||||
<td role="cell">
|
|
||||||
{{ app.application.name }}
|
|
||||||
</td>
|
|
||||||
<td role="cell">
|
|
||||||
{{ app.total_logins }}
|
|
||||||
</td>
|
|
||||||
<td role="cell">
|
|
||||||
<progress value="{{ app.total_logins }}" max="{{ most_used_applications.0.total_logins }}"></progress>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="pf-c-card pf-c-card-aggregate pf-l-gallery__item pf-m-compact">
|
|
||||||
<div class="pf-c-card__header pf-l-flex pf-m-justify-content-space-between">
|
|
||||||
<div class="pf-c-card__header-main">
|
|
||||||
<i class="pf-icon pf-icon-plugged"></i> {% trans 'Providers' %}
|
|
||||||
</div>
|
|
||||||
<a href="{% url 'authentik_admin:providers' %}">
|
|
||||||
<i class="fa fa-external-link-alt"> </i>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<div class="pf-c-card__body">
|
|
||||||
{% if providers_without_application.exists %}
|
|
||||||
<p class="ak-aggregate-card">
|
|
||||||
<i class="fa fa-exclamation-triangle"></i> {{ provider_count }}
|
|
||||||
</p>
|
|
||||||
<p>{% trans 'Warning: At least one Provider has no application assigned.' %}</p>
|
|
||||||
{% else %}
|
|
||||||
<p class="ak-aggregate-card">
|
|
||||||
<i class="fa fa-check-circle"></i> {{ provider_count }}
|
|
||||||
</p>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="pf-c-card pf-c-card-aggregate pf-l-gallery__item pf-m-compact">
|
|
||||||
<div class="pf-c-card__header pf-l-flex pf-m-justify-content-space-between">
|
|
||||||
<div class="pf-c-card__header-main">
|
|
||||||
<i class="pf-icon pf-icon-infrastructure"></i> {% trans 'Policies' %}
|
|
||||||
</div>
|
|
||||||
<a href="{% url 'authentik_admin:policies' %}">
|
|
||||||
<i class="fa fa-external-link-alt"> </i>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<div class="pf-c-card__body">
|
|
||||||
{% if policies_without_binding %}
|
|
||||||
<p class="ak-aggregate-card">
|
|
||||||
<i class="fa fa-exclamation-triangle"></i> {{ policy_count }}
|
|
||||||
</p>
|
|
||||||
<p>{% trans 'Policies without binding exist.' %}</p>
|
|
||||||
{% else %}
|
|
||||||
<p class="ak-aggregate-card">
|
|
||||||
<i class="fa fa-check-circle"></i> {{ policy_count }}
|
|
||||||
</p>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="pf-c-card pf-c-card-aggregate pf-l-gallery__item pf-m-compact">
|
|
||||||
<div class="pf-c-card__header pf-l-flex pf-m-justify-content-space-between">
|
|
||||||
<div class="pf-c-card__header-main">
|
|
||||||
<i class="pf-icon pf-icon-user"></i> {% trans 'Users' %}
|
|
||||||
</div>
|
|
||||||
<a href="{% url 'authentik_admin:users' %}">
|
|
||||||
<i class="fa fa-external-link-alt"> </i>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<div class="pf-c-card__body">
|
|
||||||
<p class="ak-aggregate-card">
|
|
||||||
<i class="fa fa-check-circle"></i> {{ user_count }}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="pf-c-card pf-c-card-aggregate pf-l-gallery__item pf-m-compact">
|
|
||||||
<div class="pf-c-card__header pf-l-flex pf-m-justify-content-space-between">
|
|
||||||
<div class="pf-c-card__header-main">
|
|
||||||
<i class="pf-icon pf-icon-bundle"></i> {% trans 'Version' %}
|
|
||||||
</div>
|
|
||||||
<a href="https://github.com/BeryJu/authentik/releases" target="_blank">
|
|
||||||
<i class="fa fa-external-link-alt"> </i>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<div class="pf-c-card__body">
|
|
||||||
<p class="ak-aggregate-card">
|
|
||||||
{% if version >= version_latest %}
|
|
||||||
<i class="fa fa-check-circle"></i> {{ version }}
|
|
||||||
{% else %}
|
|
||||||
<i class="fa fa-exclamation-triangle"></i> {{ version }}
|
|
||||||
{% endif %}
|
|
||||||
</p>
|
|
||||||
{% if version >= version_latest %}
|
|
||||||
{% blocktrans %}
|
|
||||||
Up-to-date!
|
|
||||||
{% endblocktrans %}
|
|
||||||
{% else %}
|
|
||||||
{% blocktrans with latest=version_latest %}
|
|
||||||
{{ latest }} is available!
|
|
||||||
{% endblocktrans %}
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="pf-c-card pf-c-card-aggregate pf-l-gallery__item pf-m-compact">
|
|
||||||
<div class="pf-c-card__header">
|
|
||||||
<div class="pf-c-card__header-main">
|
|
||||||
<i class="pf-icon pf-icon-server"></i> {% trans 'Workers' %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<fetch-fill-slot class="pf-c-card__body" url="{% url 'authentik_api:admin_overview-list' %}" key="worker_count">
|
|
||||||
<div slot="value < 1">
|
|
||||||
<p class="ak-aggregate-card">
|
|
||||||
<i class="fa fa-exclamation-triangle"></i> <span data-value></span>
|
|
||||||
</p>
|
|
||||||
<p>{% trans 'No workers connected.' %}</p>
|
|
||||||
</div>
|
|
||||||
<div slot="value >= 1">
|
|
||||||
<p class="ak-aggregate-card">
|
|
||||||
<i class="fa fa-check-circle"></i> <span data-value></span>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<span class="pf-c-spinner" role="progressbar" aria-valuetext="Loading...">
|
|
||||||
<span class="pf-c-spinner__clipper"></span>
|
|
||||||
<span class="pf-c-spinner__lead-ball"></span>
|
|
||||||
<span class="pf-c-spinner__tail-ball"></span>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</fetch-fill-slot>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="pf-c-card pf-c-card-aggregate pf-l-gallery__item pf-m-compact">
|
<div class="pf-c-card pf-c-card-aggregate pf-l-gallery__item pf-m-compact">
|
||||||
<div class="pf-c-card__header pf-l-flex pf-m-justify-content-space-between">
|
<div class="pf-c-card__header pf-l-flex pf-m-justify-content-space-between">
|
||||||
<div class="pf-c-card__header-main">
|
<div class="pf-c-card__header-main">
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
"""Provider API Views"""
|
"""Provider API Views"""
|
||||||
from rest_framework.serializers import ModelSerializer, SerializerMethodField
|
from rest_framework.serializers import ModelSerializer, SerializerMethodField
|
||||||
from rest_framework.viewsets import ReadOnlyModelViewSet
|
from rest_framework.viewsets import ModelViewSet
|
||||||
|
|
||||||
from authentik.core.models import Provider
|
from authentik.core.models import Provider
|
||||||
|
|
||||||
|
@ -38,6 +38,9 @@ class ProviderViewSet(ModelViewSet):
|
||||||
|
|
||||||
queryset = Provider.objects.all()
|
queryset = Provider.objects.all()
|
||||||
serializer_class = ProviderSerializer
|
serializer_class = ProviderSerializer
|
||||||
|
filterset_fields = {
|
||||||
|
'application': ['isnull'],
|
||||||
|
}
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return Provider.objects.select_subclasses()
|
return Provider.objects.select_subclasses()
|
||||||
|
|
|
@ -68,6 +68,10 @@ class PolicyViewSet(ReadOnlyModelViewSet):
|
||||||
|
|
||||||
queryset = Policy.objects.all()
|
queryset = Policy.objects.all()
|
||||||
serializer_class = PolicySerializer
|
serializer_class = PolicySerializer
|
||||||
|
filterset_fields = {
|
||||||
|
'bindings': ['isnull'],
|
||||||
|
'promptstage': ['isnull'],
|
||||||
|
}
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return Policy.objects.select_subclasses()
|
return Policy.objects.select_subclasses()
|
||||||
|
|
Reference in a new issue