Compare commits
No commits in common. "dd67ee91da68e563e9ffeac6c4345bd4163ca889" and "3452e2a8c2b55088f6d75b09c3b7c0b8e5003b89" have entirely different histories.
dd67ee91da
...
3452e2a8c2
9 changed files with 29 additions and 42 deletions
|
@ -14,17 +14,7 @@ TEST_PASSWORD = "secret"
|
||||||
|
|
||||||
|
|
||||||
class IndexViewTest(TestCase):
|
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):
|
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"))
|
response = self.client.get(reverse("dashboard"))
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertTemplateUsed(response, "dashboard/index.html")
|
self.assertTemplateUsed(response, "dashboard/index.html")
|
||||||
|
|
|
@ -3,14 +3,13 @@ This module defines the views for the gnuviechadmin customer dashboard.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
||||||
from django.views.generic import DetailView, TemplateView
|
from django.views.generic import DetailView, TemplateView
|
||||||
from gvacommon.viewmixins import StaffOrSelfLoginRequiredMixin
|
from gvacommon.viewmixins import StaffOrSelfLoginRequiredMixin
|
||||||
|
|
||||||
from hostingpackages.models import CustomerHostingPackage
|
from hostingpackages.models import CustomerHostingPackage
|
||||||
|
|
||||||
|
|
||||||
class IndexView(LoginRequiredMixin, TemplateView):
|
class IndexView(TemplateView):
|
||||||
"""
|
"""
|
||||||
This is the dashboard view.
|
This is the dashboard view.
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,8 @@ This module defines views related to domains.
|
||||||
"""
|
"""
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
from braces.views import StaffuserRequiredMixin
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.contrib.auth.mixins import PermissionRequiredMixin
|
|
||||||
from django.shortcuts import get_object_or_404, redirect
|
from django.shortcuts import get_object_or_404, redirect
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
from django.views.generic.edit import CreateView
|
from django.views.generic.edit import CreateView
|
||||||
|
@ -16,7 +16,7 @@ from .forms import CreateHostingDomainForm
|
||||||
from .models import HostingDomain
|
from .models import HostingDomain
|
||||||
|
|
||||||
|
|
||||||
class CreateHostingDomain(PermissionRequiredMixin, CreateView):
|
class CreateHostingDomain(StaffuserRequiredMixin, CreateView):
|
||||||
"""
|
"""
|
||||||
This view is used for creating a new HostingDomain instance for an existing
|
This view is used for creating a new HostingDomain instance for an existing
|
||||||
hosting package.
|
hosting package.
|
||||||
|
@ -24,7 +24,6 @@ class CreateHostingDomain(PermissionRequiredMixin, CreateView):
|
||||||
|
|
||||||
model = HostingDomain
|
model = HostingDomain
|
||||||
raise_exception = True
|
raise_exception = True
|
||||||
permission_required = 'domains.add_hostingdomain'
|
|
||||||
template_name_suffix = "_create"
|
template_name_suffix = "_create"
|
||||||
form_class = CreateHostingDomainForm
|
form_class = CreateHostingDomainForm
|
||||||
|
|
||||||
|
|
|
@ -18,16 +18,13 @@ from gnuviechadmin.context_processors import navigation
|
||||||
|
|
||||||
User = get_user_model()
|
User = get_user_model()
|
||||||
|
|
||||||
TEST_USER = "test"
|
|
||||||
TEST_PASSWORD = "secret"
|
|
||||||
|
|
||||||
|
|
||||||
class NavigationContextProcessorTest(TestCase):
|
class NavigationContextProcessorTest(TestCase):
|
||||||
|
|
||||||
EXPECTED_ITEMS = ("webmail_url", "phpmyadmin_url", "phppgadmin_url", "active_item")
|
EXPECTED_ITEMS = ("webmail_url", "phpmyadmin_url", "phppgadmin_url", "active_item")
|
||||||
|
|
||||||
def test_ajax_request(self):
|
def test_ajax_request(self):
|
||||||
response = self.client.get("/accounts/login/", HTTP_X_REQUESTED_WITH="XMLHttpRequest")
|
response = self.client.get("/", HTTP_X_REQUESTED_WITH="XMLHttpRequest")
|
||||||
for item in self.EXPECTED_ITEMS:
|
for item in self.EXPECTED_ITEMS:
|
||||||
self.assertNotIn(item, response.context)
|
self.assertNotIn(item, response.context)
|
||||||
|
|
||||||
|
@ -37,12 +34,6 @@ class NavigationContextProcessorTest(TestCase):
|
||||||
self.assertEqual(context["phppgadmin_url"], settings.GVA_LINK_PHPPGADMIN)
|
self.assertEqual(context["phppgadmin_url"], settings.GVA_LINK_PHPPGADMIN)
|
||||||
|
|
||||||
def test_index_page_context(self):
|
def test_index_page_context(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("/")
|
response = self.client.get("/")
|
||||||
for item in self.EXPECTED_ITEMS:
|
for item in self.EXPECTED_ITEMS:
|
||||||
self.assertIn(item, response.context)
|
self.assertIn(item, response.context)
|
||||||
|
@ -115,6 +106,6 @@ class NavigationContextProcessorTest(TestCase):
|
||||||
|
|
||||||
class VersionInfoContextProcessorTest(TestCase):
|
class VersionInfoContextProcessorTest(TestCase):
|
||||||
def test_version_info_in_context(self):
|
def test_version_info_in_context(self):
|
||||||
response = self.client.get("/accounts/login/")
|
response = self.client.get("/")
|
||||||
self.assertIn("gnuviechadmin_version", response.context)
|
self.assertIn("gnuviechadmin_version", response.context)
|
||||||
self.assertEqual(response.context["gnuviechadmin_version"], gvaversion)
|
self.assertEqual(response.context["gnuviechadmin_version"], gvaversion)
|
||||||
|
|
|
@ -4,10 +4,10 @@ This module defines views related to hosting packages.
|
||||||
"""
|
"""
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
from braces.views import LoginRequiredMixin, StaffuserRequiredMixin
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
from django.contrib.auth.mixins import PermissionRequiredMixin, UserPassesTestMixin
|
|
||||||
from django.http import Http404
|
from django.http import Http404
|
||||||
from django.shortcuts import get_object_or_404, redirect
|
from django.shortcuts import get_object_or_404, redirect
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
|
@ -30,7 +30,7 @@ from .models import (
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class CreateHostingPackage(PermissionRequiredMixin, CreateView):
|
class CreateHostingPackage(LoginRequiredMixin, StaffuserRequiredMixin, CreateView):
|
||||||
"""
|
"""
|
||||||
Create a hosting package.
|
Create a hosting package.
|
||||||
|
|
||||||
|
@ -38,7 +38,6 @@ class CreateHostingPackage(PermissionRequiredMixin, CreateView):
|
||||||
|
|
||||||
model = CustomerHostingPackage
|
model = CustomerHostingPackage
|
||||||
raise_exception = True
|
raise_exception = True
|
||||||
permission_required = 'domains.add_customerhostingpackage'
|
|
||||||
template_name_suffix = "_create"
|
template_name_suffix = "_create"
|
||||||
form_class = CreateHostingPackageForm
|
form_class = CreateHostingPackageForm
|
||||||
|
|
||||||
|
@ -121,16 +120,9 @@ class CustomerHostingPackageDetails(StaffOrSelfLoginRequiredMixin, DetailView):
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
class StaffUserRequiredMixin(UserPassesTestMixin):
|
class AllCustomerHostingPackageList(
|
||||||
"""
|
LoginRequiredMixin, StaffuserRequiredMixin, ListView
|
||||||
Mixin to make views available to staff members only.
|
):
|
||||||
|
|
||||||
"""
|
|
||||||
def test_func(self):
|
|
||||||
return self.request.user.is_staff
|
|
||||||
|
|
||||||
|
|
||||||
class AllCustomerHostingPackageList(StaffUserRequiredMixin, ListView):
|
|
||||||
"""
|
"""
|
||||||
This view is used for showing a list of all hosting packages.
|
This view is used for showing a list of all hosting packages.
|
||||||
|
|
||||||
|
@ -169,7 +161,7 @@ class CustomerHostingPackageList(StaffOrSelfLoginRequiredMixin, ListView):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class HostingOptionChoices(StaffUserRequiredMixin, DetailView):
|
class HostingOptionChoices(LoginRequiredMixin, StaffuserRequiredMixin, DetailView):
|
||||||
"""
|
"""
|
||||||
This view displays choices of hosting options for a customer hosting
|
This view displays choices of hosting options for a customer hosting
|
||||||
package.
|
package.
|
||||||
|
@ -213,7 +205,7 @@ class HostingOptionChoices(StaffUserRequiredMixin, DetailView):
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
class AddHostingOption(StaffUserRequiredMixin, FormView):
|
class AddHostingOption(LoginRequiredMixin, StaffuserRequiredMixin, FormView):
|
||||||
template_name = "hostingpackages/add_hosting_option.html"
|
template_name = "hostingpackages/add_hosting_option.html"
|
||||||
|
|
||||||
def get_form_class(self):
|
def get_form_class(self):
|
||||||
|
|
17
poetry.lock
generated
17
poetry.lock
generated
|
@ -638,6 +638,21 @@ python3-openid = ">=3.0.8"
|
||||||
requests = "*"
|
requests = "*"
|
||||||
requests-oauthlib = ">=0.3.0"
|
requests-oauthlib = ">=0.3.0"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "django-braces"
|
||||||
|
version = "1.15.0"
|
||||||
|
description = "Reusable, generic mixins for Django"
|
||||||
|
category = "main"
|
||||||
|
optional = false
|
||||||
|
python-versions = "*"
|
||||||
|
files = [
|
||||||
|
{file = "django-braces-1.15.0.tar.gz", hash = "sha256:f451d08ffc1078d81209a2e17f2219bce20196928853c82405451b18a46875e0"},
|
||||||
|
{file = "django_braces-1.15.0-py2.py3-none-any.whl", hash = "sha256:28f00b0f98368c9a37f30cce6087fc57127f0a24c5b8b449f9e1245bded6405d"},
|
||||||
|
]
|
||||||
|
|
||||||
|
[package.dependencies]
|
||||||
|
Django = ">=2.2"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "django-crispy-forms"
|
name = "django-crispy-forms"
|
||||||
version = "1.14.0"
|
version = "1.14.0"
|
||||||
|
@ -1742,4 +1757,4 @@ testing = ["big-O", "flake8 (<5)", "jaraco.functools", "jaraco.itertools", "more
|
||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "2.0"
|
lock-version = "2.0"
|
||||||
python-versions = "^3.7"
|
python-versions = "^3.7"
|
||||||
content-hash = "6041c8bb49cd1df098f1948f8ad2cbd48fd8f42ff44e410f3fecb61be7e80a18"
|
content-hash = "c11eec493daca3a228f3c99300d0ebf0fa35060624c93649e2dce4c71cdf67f2"
|
||||||
|
|
|
@ -12,6 +12,7 @@ django = "<4"
|
||||||
psycopg2-binary = "^2.9"
|
psycopg2-binary = "^2.9"
|
||||||
celery = "^5.2.7"
|
celery = "^5.2.7"
|
||||||
django-allauth = "^0.52.0"
|
django-allauth = "^0.52.0"
|
||||||
|
django-braces = "^1.15.0"
|
||||||
django-crispy-forms = "<2"
|
django-crispy-forms = "<2"
|
||||||
django-debug-toolbar = "^3.8"
|
django-debug-toolbar = "^3.8"
|
||||||
django-model-utils = "^4.1"
|
django-model-utils = "^4.1"
|
||||||
|
|
Loading…
Reference in a new issue