Remove duplicate functionality

- remove customer hosting package list
- replace useless dashboard with redirect
- move all hosting package list for superuser to top level menu item
- replace btn-default with btn-secondary
- improve email address management page
This commit is contained in:
Jan Dittberner 2023-04-29 12:35:49 +02:00
parent 2d05580ed3
commit 866f6c8083
16 changed files with 142 additions and 214 deletions

View file

@ -15,37 +15,20 @@
<thead>
<tr>
<th>{% translate "Name" %}</th>
<th>{% translate "Disk space" %}</th>
<th>{% translate "Mailboxes" %}</th>
<th>{% translate "Databases" %}</th>
<th>{% translate "Setup date" %}</th>
<th>{% translate "Actions" %}</th>
</tr>
</thead>
<tbody>
{% for package in hosting_packages %}
<tr>
<th><a href="{{ package.get_absolute_url }}"
<td><a href="{{ package.get_absolute_url }}"
title="{% blocktranslate with packagename=package.name trimmed %}
Show details for {{ packagename }}
{% endblocktranslate %}">{{ package.name }}</a>
</th>
<th>
{% with diskspace=package.get_disk_space %}
<span title="{% blocktranslate trimmed %}
The reserved disk space for your hosting package is {{ diskspace }} bytes.
{% endblocktranslate %}">{{ diskspace|filesizeformat }}</span>
{% endwith %}
</th>
<th>
{% blocktranslate with num=package.used_mailbox_count total=package.mailbox_count trimmed %}
used {{ num }} of {{ total }}
{% endblocktranslate %}</th>
<th>{% for dbtype in package.get_databases %}
{{ dbtype.number }}
{% include "userdbs/snippets/db_type.html" with db_type=dbtype.db_type %}
{% if not forloop.last %} / {% endif %}
{% endfor %}</th>
<th></th>
</td>
<td>{{ package.created }}</td>
<td></td>
</tr>
{% endfor %}
</tbody>

View file

@ -4,6 +4,7 @@ This module defines the views for the gnuviechadmin customer dashboard.
"""
from django.contrib.auth import get_user_model
from django.contrib.auth.mixins import LoginRequiredMixin
from django.shortcuts import redirect
from django.views.generic import DetailView, TemplateView
from gvacommon.viewmixins import StaffOrSelfLoginRequiredMixin
@ -18,6 +19,11 @@ class IndexView(LoginRequiredMixin, TemplateView):
template_name = "dashboard/index.html"
def dispatch(self, request, *args, **kwargs):
if not request.user.is_anonymous:
return redirect("customer_dashboard", slug=request.user.username)
return super().dispatch(request, *args, **kwargs)
class UserDashboardView(StaffOrSelfLoginRequiredMixin, DetailView):
"""

View file

@ -11,6 +11,9 @@
<th>{% translate "Name" %}</th>
<th>{% translate "Customer" %}</th>
<th>{% translate "OS User" %}</th>
<th>{% translate "Disk space" %}</th>
<th>{% translate "Mailboxes" %}</th>
<th>{% translate "Databases" %}</th>
<th>{% translate "Setup date" %}</th>
</tr>
</thead>
@ -21,6 +24,22 @@
<td>
<a href="{% url 'customer_dashboard' slug=package.customer.username %}">{{ package.customer }}</a>
</td>
<td>
{% with diskspace=package.get_disk_space %}
<span title="{% blocktranslate trimmed %}
The reserved disk space for your hosting package is {{ diskspace }} bytes.
{% endblocktranslate %}">{{ diskspace|filesizeformat }}</span>
{% endwith %}
</td>
<td>
{% blocktranslate with num=package.used_mailbox_count total=package.mailbox_count trimmed %}
used {{ num }} of {{ total }}
{% endblocktranslate %}</td>
<td>{% for dbtype in package.get_databases %}
{{ dbtype.number }}
{% include "userdbs/snippets/db_type.html" with db_type=dbtype.db_type %}
{% if not forloop.last %} / {% endif %}
{% endfor %}</td>
<td>{{ package.osuser.username }}</td>
<td>{{ package.created }}</td>
</tr>

View file

@ -1,48 +0,0 @@
{% extends "hostingpackages/base.html" %}
{% load i18n %}
{% block title %}{{ block.super }} - {% spaceless %}
{% if user == customer %}
{% translate "Your hosting packages" %}
{% else %}
{% blocktranslate with customer=customer.get_full_name trimmed %}Hosting Packages of
{{ customer }}{% endblocktranslate %}
{% endif %}
{% endspaceless %}{% endblock title %}
{% block page_title %}{% spaceless %}
{% if user == customer %}
{% translate "Your hosting packages" %}
{% else %}
{% blocktranslate with customer=customer.get_full_name trimmed %}Hosting Packages
<small>of {{ customer }}</small>{% endblocktranslate %}
{% endif %}
{% endspaceless %}{% endblock page_title %}
{% block content %}
{% if customerhostingpackage_list %}
<table class="table table-condensed">
<thead>
<tr>
<th>{% translate "Name" %}</th>
<th>{% translate "Setup date" %}</th>
</tr>
</thead>
<tbody>
{% for package in customerhostingpackage_list %}
<tr>
<td><a href="{{ package.get_absolute_url }}">{{ package.name }}</a></td>
<td>{{ package.created }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p class="text-info">
{% if user == customer %}{% translate "You have no hosting packages setup yet." %}{% else %}
{% translate "There are no hosting packages setup for this customer yet." %}{% endif %}</p>
{% endif %}
{% if user.is_staff %}
<p><a href="{% url 'create_customer_hosting_package' user=customer.username %}"
class="btn btn-primary">{% translate "Add hosting package" %}</a></p>
{% endif %}
{% endblock content %}

View file

@ -12,7 +12,6 @@ from .views import (
CreateCustomerHostingPackage,
CreateHostingPackage,
CustomerHostingPackageDetails,
CustomerHostingPackageList,
HostingOptionChoices,
)
@ -23,11 +22,6 @@ urlpatterns = [
AllCustomerHostingPackageList.as_view(),
name="all_hosting_packages",
),
re_path(
r"^(?P<user>[-\w0-9@.+_]+)/$",
CustomerHostingPackageList.as_view(),
name="hosting_packages",
),
re_path(
r"^(?P<user>[-\w0-9@.+_]+)/create$",
CreateCustomerHostingPackage.as_view(),

View file

@ -149,35 +149,6 @@ class AllCustomerHostingPackageList(StaffUserRequiredMixin, ListView):
)
class CustomerHostingPackageList(StaffOrSelfLoginRequiredMixin, ListView):
"""
This view is used for showing a list of a customer's hosting packages.
"""
model = CustomerHostingPackage
customer = None
def get_customer_object(self):
if self.customer is None:
self.customer = get_object_or_404(
get_user_model(), username=self.kwargs["user"]
)
return self.customer
def get_context_data(self, **kwargs):
context = super(CustomerHostingPackageList, self).get_context_data(**kwargs)
context["customer"] = self.get_customer_object()
return context
def get_queryset(self):
return (
super(CustomerHostingPackageList, self)
.get_queryset()
.filter(customer__username=self.kwargs["user"])
)
class HostingOptionChoices(StaffUserRequiredMixin, DetailView):
"""
This view displays choices of hosting options for a customer hosting

View file

@ -4,72 +4,87 @@
{% block page_title %}{% translate "E-mail Addresses" %}{% endblock page_title %}
{% block content %}
{% if user.emailaddress_set.all %}
<p>{% translate 'The following e-mail addresses are associated with your account:' %}</p>
<form action="{% url 'account_email' %}" class="email_list" method="post">
{% csrf_token %}
<table class="table table-condensed">
<thead>
<tr>
<th>{% translate "Email address" %}</th>
<th>{% translate "Verified" %}</th>
<th>{% translate "Primary" %}</th>
</tr>
</thead>
<tbody>
{% for emailaddress in user.emailaddress_set.all %}
<tr>
<td>{{ emailaddress.email }}</td>
<td>
{% if emailaddress.verified %}
<span class="verified">{% translate "Verified" %}</span>
{% else %}
<span class="unverified">{% translate "Unverified" %}</span>
{% endif %}
</td>
<td>
{% if emailaddress.primary %}
<span class="glyphicon glyphicon-star" title="{% translate "This is the current primary Email address" %}"></span>
{% else %}
<span class="glyphicon glyphicon-star-empty"></span>
{% endif %}
<input id="email_radio_{{forloop.counter}}" type="radio" name="email" {% if emailaddress.primary %}checked="checked"{%endif %} value="{{emailaddress.email}}" />
</td>
</tr>
{% endfor %}
</tbody>
</table>
<p>
<button class="btn btn-default" type="submit" name="action_primary" >{% translate 'Make Primary' %}</button>
<button class="btn btn-default" type="submit" name="action_send" >{% translate 'Re-send Verification' %}</button>
<button class="btn btn-warning" type="submit" name="action_remove" >{% translate 'Remove' %}</button>
</p>
</form>
{% else %}
<p class="text-warning"><strong>{% translate 'Warning:'%}</strong> {% translate "You currently do not have any e-mail address set up. You should really add an e-mail address so you can receive notifications, reset your password, etc." %}</p>
{% endif %}
{% if user.emailaddress_set.all %}
<p>{% translate 'The following e-mail addresses are associated with your account:' %}</p>
<form action="{% url 'account_email' %}" class="email_list" method="post">
{% csrf_token %}
<table class="table table-condensed">
<thead>
<tr>
<th>{% translate "Email address" %}</th>
<th>{% translate "Verified" %}</th>
<th>{% translate "Primary" %}</th>
<th>{% translate "Selection" %}</th>
</tr>
</thead>
<tbody>
{% for emailaddress in user.emailaddress_set.all %}
<tr>
<td>{{ emailaddress.email }}</td>
<td>
{% if emailaddress.verified %}
<span class="text-success"><i class="bi-check-circle-fill" title="{% translate "Verified" %}"></i></span>
{% else %}
<span class="text-warning"><i class="bi-dash-circle-fill" title="{% translate "Unverified" %}"></i></span>
{% endif %}
</td>
<td>
{% if emailaddress.primary %}
<span class="text-success"><i class="bi-check-circle-fill" title="{% translate "This is the current primary Email address" %}"></i></span>
{% else %}
<span class="text-secondary"><i class="bi-circle"></i></span>
{% endif %}
</td>
<td>
<input id="email_radio_{{ forloop.counter }}" type="radio" name="email"
{% if emailaddress.primary %}checked="checked"{% endif %}
value="{{ emailaddress.email }}"/><label
for="email_radio_{{ forloop.counter }}"
aria-label="{% blocktranslate trimmed with address=emailaddress.email %}
Select {{ address }}
{% endblocktranslate %}"></label>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<p>
{% if user.emailaddress_set.count > 1 %}
<button class="btn btn-secondary" type="submit"
name="action_primary">{% translate 'Make Primary' %}</button>
{% endif %}
<button class="btn btn-secondary" type="submit"
name="action_send">{% translate 'Re-send Verification' %}</button>
<button class="btn btn-warning" type="submit" name="action_remove">{% translate 'Remove' %}</button>
</p>
</form>
{% else %}
<p class="text-warning">
<strong>{% translate 'Warning:' %}</strong> {% translate "You currently do not have any e-mail address set up. You should really add an e-mail address so you can receive notifications, reset your password, etc." %}
</p>
{% endif %}
<h2>{% translate "Add E-mail Address" %}</h2>
<h2>{% translate "Add E-mail Address" %}</h2>
<form method="post" action="{% url 'account_email' %}" class="add_email">
{% csrf_token %}
{{ form | crispy }}
<button name="action_add" type="submit" class="btn btn-primary">{% translate "Add E-mail" %}</button>
</form>
<form method="post" action="{% url 'account_email' %}" class="add_email">
{% csrf_token %}
{{ form | crispy }}
<button name="action_add" type="submit" class="btn btn-primary">{% translate "Add E-mail" %}</button>
</form>
{% endblock content %}
{% block extra_js %}
<script type="text/javascript">
(function() {
var message = "{% translate 'Do you really want to remove the selected e-mail address?' %}";
var actions = document.getElementsByName('action_remove');
if (actions.length) {
actions[0].addEventListener("click", function(e) {
if (! confirm(message)) {
e.preventDefault();
}
});
}
})();
</script>
<script type="text/javascript">
(function () {
const message = "{% translate 'Do you really want to remove the selected e-mail address?' %}";
let actions = document.getElementsByName('action_remove');
if (actions.length) {
actions[0].addEventListener("click", function (e) {
if (!confirm(message)) {
e.preventDefault();
}
});
}
})();
</script>
{% endblock extra_js %}

View file

@ -11,7 +11,7 @@
{% endblocktranslate %}</p>
<form method="post" action="{% url 'account_confirm_email' confirmation.key %}">
{% csrf_token %}
<button type="submit" class="btn btn-default">{% translate 'Confirm' %}</button>
<button type="submit" class="btn btn-primary">{% translate 'Confirm' %}</button>
</form>
{% else %}
{% url 'account_email' as email_url %}

View file

@ -14,7 +14,7 @@
{% if redirect_field_value %}
<input type="hidden" name="{{ redirect_field_name }}" value="{{ redirect_field_value }}"/>
{% endif %}
<a class="btn btn-default" href="{% url 'account_reset_password' %}">{% translate "Forgot Password?" %}</a>
<a class="btn btn-secondary" href="{% url 'account_reset_password' %}">{% translate "Forgot Password?" %}</a>
<button class="btn btn-primary" type="submit">{% translate "Sign In" %}</button>
</form>
</div>

View file

@ -23,13 +23,7 @@
<body>
<nav class="navbar navbar-expand-lg sticky-top navbar-dark bg-dark">
<div class="container">
<a class="navbar-brand" href="{% spaceless %}
{% if user.is_authenticated %}
{% url 'customer_dashboard' slug=user.username %}
{% else %}
{% url 'dashboard' %}
{% endif %}
{% endspaceless %}" title="{% translate "Dashboard" %}">gnuviechadmin</a>
<a class="navbar-brand" href="{% url 'dashboard' %}" title="{% translate "Dashboard" %}">gnuviechadmin</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarContent"
aria-controls="navbarContent" aria-expanded="false" aria-label="{% translate "Toggle navigation" %}">
<span class="navbar-toggler-icon"></span>
@ -37,41 +31,34 @@
<div class="collapes navbar-collapse" id="navbarContent">
<ul class="navbar-nav me-auto mb-2 mg-lg-0">
{% if user.is_staff %}
<li class="nav-item dropdown{% if active_item == 'hostingpackage' %} active{% endif %}">
<li class="nav-item{% if active_item == "hosting" %} active{% endif %}">
<a class="nav-link" href="{% url 'all_hosting_packages' %}">
<i class="bi-boxes"></i> {% translate "Hosting" %}</a>
</li>
{% endif %}
{% if user.is_authenticated %}
<li class="nav-item dropdown">
<a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" role="button"
aria-expanded="false"><i class="bi-server"></i> {% translate "Hosting" %}</a>
aria-expanded="false"><i class="bi-link"></i> {% translate "Links" %} </a>
<ul class="dropdown-menu" role="menu">
<li><a class="dropdown-item" href="{% url 'hosting_packages' user=user.username %}"><i
class="bi-box2-fill"></i> {% translate "Your hosting packages" %}</a></li>
<li><a class="dropdown-item" href="{% url 'all_hosting_packages' %}"><i
class="bi-boxes"></i> {% translate "All hosting packages" %}</a></li>
<li><a class="dropdown-item" href="{{ webmail_url }}"
title="{% translate "Web based mail system" %}"><i
class="bi-envelope-at"></i> {% translate "Webmail" %}</a></li>
<li><a class="dropdown-item" href="{{ phpmyadmin_url }}"
title="{% translate "phpMyAdmin - MySQL database administration tool" %}"><i
class="icon-mysql"></i> {% translate "phpMyAdmin" %}</a></li>
<li><a class="dropdown-item" href="{{ phppgadmin_url }}"
title="{% translate "phpPgAdmin - PostgreSQL database administration tool" %}"><i
class="icon-postgres"></i> {% translate "phpPgAdmin" %}</a></li>
</ul>
</li>
{% elif user.is_authenticated %}
<li class="nav-item{% if active_item == 'hostingpackage' %} active{% endif %}"><a
class="nav-link" href="{% url 'hosting_packages' user=user.username %}"><i
class="bi-server"></i> {% translate "Hosting" %}</a></li>
{% endif %}
<li class="nav-item dropdown">
<a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" role="button"
aria-expanded="false"><i class="bi-link"></i> {% translate "Links" %} </a>
<ul class="dropdown-menu" role="menu">
<li><a class="dropdown-item" href="{{ webmail_url }}"
title="{% translate "Web based mail system" %}"><i
class="bi-envelope-at"></i> {% translate "Webmail" %}</a></li>
<li><a class="dropdown-item" href="{{ phpmyadmin_url }}"
title="{% translate "phpMyAdmin - MySQL database administration tool" %}"><i
class="icon-mysql"></i> {% translate "phpMyAdmin" %}</a></li>
<li><a class="dropdown-item" href="{{ phppgadmin_url }}"
title="{% translate "phpPgAdmin - PostgreSQL database administration tool" %}"><i
class="icon-postgres"></i> {% translate "phpPgAdmin" %}</a></li>
</ul>
</li>
<li class="nav-item{% if active_item == 'imprint' %} active{% endif %}"><a
class="nav-link" href="{% url 'imprint' %}"><i class="bi-info"></i> {% translate "Imprint" %}
</a></li>
<li class="nav-item{% if active_item == 'privacy' %} active{% endif %}"><a
class="nav-link" href="{% url 'privacy' %}"><i class="bi-file-text"></i> {% translate "Privacy policy" %}
class="nav-link" href="{% url 'privacy' %}"><i
class="bi-file-text"></i> {% translate "Privacy policy" %}
</a></li>
<li class="nav-item{% if active_item == 'contact' %} active{% endif %}"><a
class="nav-link" href="{% url 'contact_form' %}"><i
@ -79,7 +66,7 @@
</ul>
{% if user.is_authenticated %}
{% user_display user as user_display %}
{% url 'user_profile' slug=user.username as profile_url %}
{% url 'customer_dashboard' slug=user.username as profile_url %}
{% if user.is_impersonate %}
{% user_display user.impersonator as impersonator_display %}
{% url 'impersonate-stop' as stop_impersonation_url %}
@ -87,7 +74,8 @@
Signed in as
<a href="{{ profile_url }}" class="navbar-link" title="My Profile">{{ user_display }}</a>
<i class="bi-incognito" title="impersonated by {{ impersonator_display }}"></i>
<a href="{{ stop_impersonation_url }}" class="navbar-link"><i class="bi-sign-stop" title="stop impersonation"></i></a>
<a href="{{ stop_impersonation_url }}" class="navbar-link"><i class="bi-sign-stop"
title="stop impersonation"></i></a>
{% endblocktranslate %}</span>
{% else %}
<span class="navbar-text justify-content-end">{% blocktranslate trimmed %}

View file

@ -10,8 +10,8 @@
{% if page.object_list %}
<ul class="list-group">
{% for user in page.object_list %}
<li class="list-group-item"><a href="{% url 'impersonate-start' user.pk %}{{ redirect }}">{{ user }}</a>
- Impersonate
<li class="list-group-item"><a href="{% url 'impersonate-start' user.pk %}{{ redirect }}">
{% blocktranslate %}Impersonate {{ user }}{% endblocktranslate %}</a>
</li>
{% endfor %}
</ul>

View file

@ -13,15 +13,15 @@
placeholder="{% translate "user name part" %}" value="{% if query %}{{ query }}{% endif %}">
</div>
<button type="submit" class="btn btn-primary">{% translate "Search" %}</button>
<a class="btn btn-secondary" href="{% url 'impersonate-list' %}">{% translate "List all users" %}</a>
<a class="btn btn-link" href="{% url 'impersonate-list' %}">{% translate "List all users" %}</a>
</form>
<p>
{% if query and page.object_list %}
<ul class="list-group">
{% for user in page.object_list %}
<li class="list-group-item"><a
href="{% url 'impersonate-start' user.pk %}{{ redirect }}">{{ user }}</a> - Impersonate
<li class="list-group-item"><a href="{% url 'impersonate-start' user.pk %}{{ redirect }}">
{% blocktranslate %}Impersonate {{ user }}{% endblocktranslate %}</a>
</li>
{% endfor %}
</ul>

View file

@ -31,7 +31,7 @@
method="post">
{% csrf_token %}
<input class="btn btn-warning" type="submit" value="{% translate "Yes, do it!" %}"/>
<a class="btn btn-default" href="{{ hostingpackage.get_absolute_url }}">{% translate "Cancel" %}</a>
<a class="btn btn-secondary" href="{{ hostingpackage.get_absolute_url }}">{% translate "Cancel" %}</a>
</form>
</div>
</div>

View file

@ -39,7 +39,7 @@
<form action="{% url 'delete_ssh_key' package=hostingpackage.id pk=key.id %}" method="post">
{% csrf_token %}
<input class="btn btn-warning" type="submit" value="{% translate "Yes, do it!" %}"/>
<a class="btn btn-default" href="{% url 'list_ssh_keys' package=hostingpackage.id %}"
<a class="btn btn-secondary" href="{% url 'list_ssh_keys' package=hostingpackage.id %}"
title="{% translate "Cancel and go back to the SSH key list" %}">{% translate "Cancel" %}</a>
</form>
</div>

View file

@ -40,7 +40,7 @@
method="post">
{% csrf_token %}
<input class="btn btn-warning" type="submit" value="{% translate "Yes, do it!" %}"/>
<a class="btn btn-default" href="{{ hostingpackage.get_absolute_url }}">{% translate "Cancel" %}</a>
<a class="btn btn-secondary" href="{{ hostingpackage.get_absolute_url }}">{% translate "Cancel" %}</a>
</form>
</div>
</div>

View file

@ -36,7 +36,7 @@
method="post" class="form">
{% csrf_token %}
<input class="btn btn-warning" type="submit" value="{% translate "Yes, do it!" %}"/>
<a class="btn btn-default" href="{{ hostingpackage.get_absolute_url }}">{% translate "Cancel" %}</a>
<a class="btn btn-secondary" href="{{ hostingpackage.get_absolute_url }}">{% translate "Cancel" %}</a>
</form>
</div>
</div>