From 29d16211525dead2391da0dddddfac5f538f4571 Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Mon, 16 Mar 2026 17:24:20 -0300 Subject: [PATCH] add reserved application checks to prevent modification and deletion --- app_gateway/views.py | 18 +++++++++++++- templates/app_gateway/app_gateway_list.html | 2 +- .../app_gateway/application_details.html | 24 +++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/app_gateway/views.py b/app_gateway/views.py index 7926f4e..3d4d71d 100644 --- a/app_gateway/views.py +++ b/app_gateway/views.py @@ -15,7 +15,7 @@ from app_gateway.forms import ( ApplicationPolicyForm, ApplicationRouteForm ) from app_gateway.models import ( - Application, ApplicationHost, AccessPolicy, ApplicationPolicy, ApplicationRoute + Application, ApplicationHost, AccessPolicy, ApplicationPolicy, ApplicationRoute, RESERVED_APP_NAME ) from app_gateway.setup_defaults import create_default_entries from user_manager.models import UserAcl @@ -59,6 +59,7 @@ def view_application_details(request): 'application': application, 'hosts': hosts, 'routes': routes, + 'is_reserved': application.name == RESERVED_APP_NAME, 'page_title': _('Application Details'), } return render(request, 'app_gateway/application_details.html', context) @@ -73,6 +74,9 @@ def view_manage_application(request): if application_uuid: application = get_object_or_404(Application, uuid=application_uuid) + if application.name == RESERVED_APP_NAME: + messages.error(request, _('The WireGuard WebAdmin application cannot be modified.')) + return redirect(reverse('view_application') + f'?uuid={application.uuid}') title = _('Edit Application') else: application = None @@ -117,6 +121,10 @@ def view_delete_application(request): cancel_url = reverse('app_gateway_list') + '?tab=applications' + if application.name == RESERVED_APP_NAME: + messages.error(request, _('The WireGuard WebAdmin application cannot be deleted.')) + return redirect(reverse('view_application') + f'?uuid={application.uuid}') + if request.method == 'POST': application.delete() messages.success(request, _('Application deleted successfully.')) @@ -150,6 +158,10 @@ def view_manage_application_host(request): cancel_url = reverse('view_application') + f'?uuid={application.uuid}#hosts' + if application.name == RESERVED_APP_NAME: + messages.error(request, _('The WireGuard WebAdmin application cannot be modified.')) + return redirect(cancel_url) + form = ApplicationHostForm(request.POST or None, instance=application_host, cancel_url=cancel_url) if form.is_valid(): host = form.save(commit=False) @@ -176,6 +188,10 @@ def view_delete_application_host(request): cancel_url = reverse('view_application') + f'?uuid={application.uuid}#hosts' + if application.name == RESERVED_APP_NAME: + messages.error(request, _('The WireGuard WebAdmin application cannot be modified.')) + return redirect(cancel_url) + if request.method == 'POST': application_host.delete() messages.success(request, _('Application Host deleted successfully.')) diff --git a/templates/app_gateway/app_gateway_list.html b/templates/app_gateway/app_gateway_list.html index c93a80a..8f1d5ee 100644 --- a/templates/app_gateway/app_gateway_list.html +++ b/templates/app_gateway/app_gateway_list.html @@ -145,7 +145,7 @@ {% for policy in access_policies %} - {{ policy }} + {{ policy.display_name|default:policy.name }} {{ policy.get_policy_type_display }} {{ policy.groups.count }} {{ policy.methods.count }} diff --git a/templates/app_gateway/application_details.html b/templates/app_gateway/application_details.html index e40b882..9a18789 100644 --- a/templates/app_gateway/application_details.html +++ b/templates/app_gateway/application_details.html @@ -11,12 +11,21 @@ {% trans 'Back to List' %} + {% if is_reserved %} + + {% trans 'Edit Application' %} + + + {% trans 'Delete Application' %} + + {% else %} {% trans 'Edit Application' %} {% trans 'Delete Application' %} + {% endif %}
@@ -46,10 +55,16 @@

{% trans 'Application Hosts' %}

+ {% if is_reserved %} + + {% trans 'Add Host' %} + + {% else %} {% trans 'Add Host' %} + {% endif %}
{% if hosts %} @@ -66,6 +81,14 @@ {{ host.hostname }} + {% if is_reserved %} + + + + + + + {% else %} @@ -74,6 +97,7 @@ class="btn btn-sm btn-danger" title="{% trans 'Delete' %}"> + {% endif %} {% endfor %}