diff --git a/gnuviechadmin/dashboard/templates/dashboard/index.html b/gnuviechadmin/dashboard/templates/dashboard/index.html new file mode 100644 index 0000000..8cfcd8d --- /dev/null +++ b/gnuviechadmin/dashboard/templates/dashboard/index.html @@ -0,0 +1,11 @@ +{% extends "base.html" %} +{% load i18n %} +{% block title %}{{ block.super }} - {% translate "Welcome" %}{% endblock title %} +{% block page_title %}{% translate "Welcome to our customer self service" %}{% endblock page_title %} +{% block content %} +

{% url 'customer_dashboard' slug=user.username as dashboard_url %} + {% blocktranslate with full_name=user.get_full_name trimmed %} + Hello {{ full_name }},
+ You can visit your Dashboard to view and modify your hosting options. + {% endblocktranslate %}

+{% endblock content %} \ No newline at end of file diff --git a/gnuviechadmin/dashboard/templates/dashboard/user_dashboard.html b/gnuviechadmin/dashboard/templates/dashboard/user_dashboard.html index 538003f..19d05cd 100644 --- a/gnuviechadmin/dashboard/templates/dashboard/user_dashboard.html +++ b/gnuviechadmin/dashboard/templates/dashboard/user_dashboard.html @@ -1,9 +1,9 @@ {% extends "base.html" %} {% load i18n %} -{% block title %}{{ block.super }} - {% blocktranslate with full_name=request.user.get_full_name trimmed %} +{% block title %}{{ block.super }} - {% blocktranslate with full_name=dashboard_user.get_full_name trimmed %} Dashboard for {{ full_name }} {% endblocktranslate %}{% endblock title %} -{% block page_title %}{% blocktranslate with full_name=request.user.get_full_name trimmed %} +{% block page_title %}{% blocktranslate with full_name=dashboard_user.get_full_name trimmed %} Dashboard for {{ full_name }} {% endblocktranslate %}{% endblock page_title %} {% block content %} @@ -15,20 +15,37 @@ {% translate "Name" %} - {% translate "Setup date" %} + {% translate "Disk space" %} + {% translate "Mailboxes" %} + {% translate "Databases" %} {% translate "Actions" %} {% for package in hosting_packages %} - {{ package.name }} - - {{ package.created }} - + + + {% with diskspace=package.get_disk_space %} + {{ diskspace|filesizeformat }} + {% endwith %} + + + {% blocktranslate with num=package.used_mailbox_count total=package.mailbox_count trimmed %} + used {{ num }} of {{ total }} + {% endblocktranslate %} + {% 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 %} + {% endfor %} @@ -39,7 +56,7 @@ {% translate "This user has no hosting packages assigned yet." %}{% endif %}

{% endif %} {% if user.is_staff %} - {% translate "Add hosting package" %} {% endif %} diff --git a/gnuviechadmin/dashboard/tests/test_views.py b/gnuviechadmin/dashboard/tests/test_views.py index 8827a80..dc1dde5 100644 --- a/gnuviechadmin/dashboard/tests/test_views.py +++ b/gnuviechadmin/dashboard/tests/test_views.py @@ -2,7 +2,7 @@ Tests for :py:mod:`dashboard.views`. """ -from django import http + from django.contrib.auth import get_user_model from django.test import TestCase from django.urls import reverse @@ -13,35 +13,65 @@ TEST_USER = "test" TEST_PASSWORD = "secret" +class IndexViewTest(TestCase): + def test_index_view_anonymous(self): + response = self.client.get(reverse("dashboard")) + self.assertRedirects(response, "/accounts/login/?next=/") + + def test_index_view(self): + user = User.objects.create(username=TEST_USER) + user.set_password(TEST_PASSWORD) + user.save() + + self.client.login(username=TEST_USER, password=TEST_PASSWORD) + + response = self.client.get(reverse("dashboard")) + self.assertEqual(response.status_code, 200) + self.assertTemplateUsed(response, "dashboard/index.html") + + class UserDashboardViewTest(TestCase): def _create_test_user(self): self.user = User.objects.create(username=TEST_USER) self.user.set_password(TEST_PASSWORD) self.user.save() + def test_user_dashboard_view_no_user(self): + response = self.client.get( + reverse("customer_dashboard", kwargs={"slug": TEST_USER}) + ) + self.assertEqual(response.status_code, 404) + def test_user_dashboard_view_anonymous(self): User.objects.create(username=TEST_USER) - response = self.client.get(reverse("customer_dashboard")) - self.assertEqual(response.status_code, 302) - self.assertRedirects(response, "/accounts/login/?next=/") + response = self.client.get( + reverse("customer_dashboard", kwargs={"slug": TEST_USER}) + ) + self.assertEqual(response.status_code, 403) def test_user_dashboard_view_logged_in_ok(self): self._create_test_user() self.assertTrue(self.client.login(username=TEST_USER, password=TEST_PASSWORD)) - response = self.client.get(reverse("customer_dashboard")) + response = self.client.get( + reverse("customer_dashboard", kwargs={"slug": TEST_USER}) + ) self.assertEqual(response.status_code, 200) def test_user_dashboard_view_logged_in_template(self): self._create_test_user() self.assertTrue(self.client.login(username=TEST_USER, password=TEST_PASSWORD)) response = self.client.get( - reverse("customer_dashboard") + reverse("customer_dashboard", kwargs={"slug": TEST_USER}) ) self.assertTemplateUsed(response, "dashboard/user_dashboard.html") def test_user_dashboard_view_logged_in_context_fresh(self): self._create_test_user() self.assertTrue(self.client.login(username=TEST_USER, password=TEST_PASSWORD)) - response = self.client.get(reverse("customer_dashboard")) + response = self.client.get( + reverse("customer_dashboard", kwargs={"slug": TEST_USER}) + ) + self.assertIn("dashboard_user", response.context) + self.assertEqual(self.user, response.context["dashboard_user"]) self.assertIn("hosting_packages", response.context) self.assertEqual(len(response.context["hosting_packages"]), 0) diff --git a/gnuviechadmin/dashboard/urls.py b/gnuviechadmin/dashboard/urls.py index 6ba8ff4..59e98d4 100644 --- a/gnuviechadmin/dashboard/urls.py +++ b/gnuviechadmin/dashboard/urls.py @@ -1,9 +1,14 @@ from __future__ import absolute_import -from django.urls import path +from django.urls import re_path -from .views import UserDashboardView +from .views import IndexView, UserDashboardView urlpatterns = [ - path("", UserDashboardView.as_view(), name="customer_dashboard"), + re_path(r"^$", IndexView.as_view(), name="dashboard"), + re_path( + r"^user/(?P[\w0-9@.+-_]+)/$", + UserDashboardView.as_view(), + name="customer_dashboard", + ), ] diff --git a/gnuviechadmin/dashboard/views.py b/gnuviechadmin/dashboard/views.py index d92eb7e..7f30316 100644 --- a/gnuviechadmin/dashboard/views.py +++ b/gnuviechadmin/dashboard/views.py @@ -4,24 +4,42 @@ 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 from hostingpackages.models import CustomerHostingPackage -class UserDashboardView(LoginRequiredMixin, TemplateView): +class IndexView(LoginRequiredMixin, TemplateView): + """ + This is the dashboard view. + + """ + + template_name = "dashboard/index.html" + + +class UserDashboardView(StaffOrSelfLoginRequiredMixin, DetailView): """ This is the user dashboard view. """ + model = get_user_model() + context_object_name = "dashboard_user" + slug_field = "username" template_name = "dashboard/user_dashboard.html" def get_context_data(self, **kwargs): context = super(UserDashboardView, self).get_context_data(**kwargs) context["hosting_packages"] = CustomerHostingPackage.objects.filter( - customer=self.request.user + customer=self.object ) return context + + def get_customer_object(self): + """ + Returns the customer object. + + """ + return self.get_object() diff --git a/gnuviechadmin/gnuviechadmin/tests/test_contextprocessors.py b/gnuviechadmin/gnuviechadmin/tests/test_contextprocessors.py index 43b5060..94578cd 100644 --- a/gnuviechadmin/gnuviechadmin/tests/test_contextprocessors.py +++ b/gnuviechadmin/gnuviechadmin/tests/test_contextprocessors.py @@ -56,6 +56,15 @@ class NavigationContextProcessorTest(TestCase): self._check_static_urls(response.context) self.assertEqual(response.context["active_item"], "contact") + def test_hostingpackage_page_context(self): + User.objects.create_user("test", password="test") + self.client.login(username="test", password="test") + response = self.client.get(reverse("hosting_packages", kwargs={"user": "test"})) + for item in self.EXPECTED_ITEMS: + self.assertIn(item, response.context) + self._check_static_urls(response.context) + self.assertEqual(response.context["active_item"], "hostingpackage") + def _test_page_context_by_viewmodule(self, viewmodule, expecteditem): request = HttpRequest() request.resolver_match = MagicMock() diff --git a/gnuviechadmin/hostingpackages/templates/hostingpackages/customerhostingpackage_admin_list.html b/gnuviechadmin/hostingpackages/templates/hostingpackages/customerhostingpackage_admin_list.html index cf13634..a4b7727 100644 --- a/gnuviechadmin/hostingpackages/templates/hostingpackages/customerhostingpackage_admin_list.html +++ b/gnuviechadmin/hostingpackages/templates/hostingpackages/customerhostingpackage_admin_list.html @@ -11,9 +11,6 @@ {% translate "Name" %} {% translate "Customer" %} {% translate "OS User" %} - {% translate "Disk space" %} - {% translate "Mailboxes" %} - {% translate "Databases" %} {% translate "Setup date" %} @@ -21,24 +18,10 @@ {% for package in customerhostingpackage_list %} {{ package.name }} - {{ package.customer }} - {{ package.osuser.username }} - {% with diskspace=package.get_disk_space %} - {{ diskspace|filesizeformat }} - {% endwith %} + {{ package.customer }} - - {% blocktranslate with num=package.used_mailbox_count total=package.mailbox_count trimmed %} - used {{ num }} of {{ total }} - {% endblocktranslate %} - {% 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 %} + {{ package.osuser.username }} {{ package.created }} {% endfor %} diff --git a/gnuviechadmin/hostingpackages/templates/hostingpackages/customerhostingpackage_list.html b/gnuviechadmin/hostingpackages/templates/hostingpackages/customerhostingpackage_list.html new file mode 100644 index 0000000..940b2b4 --- /dev/null +++ b/gnuviechadmin/hostingpackages/templates/hostingpackages/customerhostingpackage_list.html @@ -0,0 +1,48 @@ +{% 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 + of {{ customer }}{% endblocktranslate %} + {% endif %} +{% endspaceless %}{% endblock page_title %} + +{% block content %} + {% if customerhostingpackage_list %} + + + + + + + + + {% for package in customerhostingpackage_list %} + + + + + {% endfor %} + +
{% translate "Name" %}{% translate "Setup date" %}
{{ package.name }}{{ package.created }}
+ {% else %} +

+ {% if user == customer %}{% translate "You have no hosting packages setup yet." %}{% else %} + {% translate "There are no hosting packages setup for this customer yet." %}{% endif %}

+ {% endif %} + {% if user.is_staff %} +

{% translate "Add hosting package" %}

+ {% endif %} +{% endblock content %} diff --git a/gnuviechadmin/hostingpackages/urls.py b/gnuviechadmin/hostingpackages/urls.py index fe3faa6..9f1dfb7 100644 --- a/gnuviechadmin/hostingpackages/urls.py +++ b/gnuviechadmin/hostingpackages/urls.py @@ -12,6 +12,7 @@ from .views import ( CreateCustomerHostingPackage, CreateHostingPackage, CustomerHostingPackageDetails, + CustomerHostingPackageList, HostingOptionChoices, ) @@ -22,6 +23,11 @@ urlpatterns = [ AllCustomerHostingPackageList.as_view(), name="all_hosting_packages", ), + re_path( + r"^(?P[-\w0-9@.+_]+)/$", + CustomerHostingPackageList.as_view(), + name="hosting_packages", + ), re_path( r"^(?P[-\w0-9@.+_]+)/create$", CreateCustomerHostingPackage.as_view(), diff --git a/gnuviechadmin/hostingpackages/views.py b/gnuviechadmin/hostingpackages/views.py index 37ff280..d94f296 100644 --- a/gnuviechadmin/hostingpackages/views.py +++ b/gnuviechadmin/hostingpackages/views.py @@ -149,6 +149,35 @@ 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 diff --git a/gnuviechadmin/osusers/tests/test_models.py b/gnuviechadmin/osusers/tests/test_models.py index c76178a..8770263 100644 --- a/gnuviechadmin/osusers/tests/test_models.py +++ b/gnuviechadmin/osusers/tests/test_models.py @@ -212,7 +212,7 @@ class GroupTest(TestCaseWithCeleryTasks): group.delete() self.assertEqual(len(Group.objects.all()), 0) self.assertEqual(len(TaskResult.objects.all()), 2) - tr = TaskResult.objects.order_by("created").first() + tr = TaskResult.objects.first() self.assertEqual(tr.creator, "handle_group_created") diff --git a/gnuviechadmin/taskresults/tests/management/commands/test_fetch_taskresults.py b/gnuviechadmin/taskresults/tests/management/commands/test_fetch_taskresults.py index f395037..a7d10ff 100644 --- a/gnuviechadmin/taskresults/tests/management/commands/test_fetch_taskresults.py +++ b/gnuviechadmin/taskresults/tests/management/commands/test_fetch_taskresults.py @@ -32,7 +32,7 @@ class FetchTaskResultsCommandTest(TestCase): aresult.state = "PENDING" aresult.ready.return_value = False - Command().handle(verbosity=0) + Command().handle() tr = TaskResult.objects.get(task_id=TEST_TASK_UUID) self.assertTrue(asyncresult.called_with(TEST_TASK_UUID)) @@ -55,7 +55,7 @@ class FetchTaskResultsCommandTest(TestCase): aresult.ready.return_value = True aresult.get.return_value = TEST_TASK_RESULT - Command().handle(verbosity=0) + Command().handle() tr = TaskResult.objects.get(task_id=TEST_TASK_UUID) self.assertTrue(asyncresult.called_with(TEST_TASK_UUID)) diff --git a/gnuviechadmin/templates/account/email.html b/gnuviechadmin/templates/account/email.html index 23a15cd..fc66cf3 100644 --- a/gnuviechadmin/templates/account/email.html +++ b/gnuviechadmin/templates/account/email.html @@ -4,87 +4,72 @@ {% block page_title %}{% translate "E-mail Addresses" %}{% endblock page_title %} {% block content %} - {% if user.emailaddress_set.all %} -

{% translate 'The following e-mail addresses are associated with your account:' %}

- - {% else %} -

- {% translate 'Warning:' %} {% 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." %} -

- {% endif %} +{% if user.emailaddress_set.all %} +

{% translate 'The following e-mail addresses are associated with your account:' %}

+ +{% else %} +

{% translate 'Warning:'%} {% 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." %}

+{% endif %} -

{% translate "Add E-mail Address" %}

+

{% translate "Add E-mail Address" %}

-
- {% csrf_token %} - {{ form | crispy }} - -
+
+ {% csrf_token %} + {{ form | crispy }} + +
{% endblock content %} {% block extra_js %} - + {% endblock extra_js %} diff --git a/gnuviechadmin/templates/account/email_confirm.html b/gnuviechadmin/templates/account/email_confirm.html index e70246c..c91da96 100644 --- a/gnuviechadmin/templates/account/email_confirm.html +++ b/gnuviechadmin/templates/account/email_confirm.html @@ -11,7 +11,7 @@ {% endblocktranslate %}

{% csrf_token %} - +
{% else %} {% url 'account_email' as email_url %} diff --git a/gnuviechadmin/templates/account/login.html b/gnuviechadmin/templates/account/login.html index bbc211d..0a7ccad 100644 --- a/gnuviechadmin/templates/account/login.html +++ b/gnuviechadmin/templates/account/login.html @@ -14,7 +14,7 @@ {% if redirect_field_value %} {% endif %} - {% translate "Forgot Password?" %} + {% translate "Forgot Password?" %} diff --git a/gnuviechadmin/templates/base.html b/gnuviechadmin/templates/base.html index 4521c43..127b6e1 100644 --- a/gnuviechadmin/templates/base.html +++ b/gnuviechadmin/templates/base.html @@ -23,7 +23,13 @@