mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
Merge pull request #3630 from modoboa/show-frontend-apps-if-enabled
Only show frontend user apps if they are enabled.
This commit is contained in:
@@ -19,7 +19,6 @@ from modoboa.admin import (
|
||||
from modoboa.core import models, constants
|
||||
from modoboa.core.tests import utils
|
||||
from modoboa.lib.tests import ModoAPITestCase
|
||||
from rest_framework.authtoken.models import Token
|
||||
|
||||
DOVEADM_TEST_PATH = utils.get_doveadm_test_path()
|
||||
DOVECOT_USER = getpass.getuser()
|
||||
@@ -183,6 +182,13 @@ class ParametersAPITestCase(ModoAPITestCase):
|
||||
|
||||
|
||||
class AccountViewSetTestCase(ModoAPITestCase):
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create test data."""
|
||||
super().setUpTestData()
|
||||
factories.populate_database()
|
||||
|
||||
def test_me(self):
|
||||
url = reverse("v2:account-me")
|
||||
resp = self.client.get(url)
|
||||
@@ -261,6 +267,57 @@ class AccountViewSetTestCase(ModoAPITestCase):
|
||||
user.refresh_from_db()
|
||||
self.assertEqual(user.totp_enabled, False)
|
||||
|
||||
def test_available_applications(self):
|
||||
url = reverse("v2:account-available-applications")
|
||||
resp = self.client.get(url)
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
# admin -> only 1 app.
|
||||
self.assertEqual(len(resp.json()), 1)
|
||||
|
||||
# Domain admin with mailbox
|
||||
dadmin = models.User.objects.get(username="admin@test.com")
|
||||
self.authenticate_user(dadmin)
|
||||
resp = self.client.get(url)
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
self.assertEqual(len(resp.json()), 4)
|
||||
|
||||
# Simple user
|
||||
user = models.User.objects.get(username="user@test.com")
|
||||
self.authenticate_user(user)
|
||||
resp = self.client.get(url)
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
self.assertEqual(len(resp.json()), 3)
|
||||
|
||||
@override_settings(
|
||||
MODOBOA_APPS=[
|
||||
"modoboa",
|
||||
"modoboa.core",
|
||||
"modoboa.lib",
|
||||
"modoboa.admin",
|
||||
"modoboa.transport",
|
||||
"modoboa.relaydomains",
|
||||
"modoboa.limits",
|
||||
"modoboa.parameters",
|
||||
"modoboa.dnstools",
|
||||
"modoboa.policyd",
|
||||
"modoboa.maillog",
|
||||
"modoboa.pdfcredentials",
|
||||
"modoboa.dmarc",
|
||||
"modoboa.imap_migration",
|
||||
"modoboa.autoreply",
|
||||
"modoboa.sievefilters",
|
||||
"modoboa.rspamd",
|
||||
]
|
||||
)
|
||||
def test_available_applications_with_disabled(self):
|
||||
url = reverse("v2:account-available-applications")
|
||||
# Domain admin with mailbox
|
||||
dadmin = models.User.objects.get(username="admin@test.com")
|
||||
self.authenticate_user(dadmin)
|
||||
resp = self.client.get(url)
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
self.assertEqual(len(resp.json()), 1)
|
||||
|
||||
|
||||
class PasswordResetTestCase(AccountViewSetTestCase):
|
||||
def __init__(self, *args, **kwargs):
|
||||
@@ -268,15 +325,6 @@ class PasswordResetTestCase(AccountViewSetTestCase):
|
||||
self.id = 0
|
||||
self.sms_token = 0
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls): # NOQA:N802
|
||||
"""Create test data."""
|
||||
super().setUpTestData()
|
||||
factories.populate_database()
|
||||
cls.da_token = Token.objects.create(
|
||||
user=models.User.objects.get(username="admin@test.com")
|
||||
)
|
||||
|
||||
@mock.patch("ovh.Client.get")
|
||||
@mock.patch("ovh.Client.post")
|
||||
def test_reset_password(self, client_post, client_get):
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"""Core API v2 viewsets."""
|
||||
|
||||
from django.conf import settings
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from django_otp.plugins.otp_static.models import StaticDevice, StaticToken
|
||||
@@ -166,29 +167,37 @@ class AccountViewSet(core_v1_viewsets.AccountViewSet):
|
||||
}
|
||||
)
|
||||
if hasattr(request.user, "mailbox"):
|
||||
apps += [
|
||||
{
|
||||
"name": "calendar",
|
||||
"label": _("Calendars"),
|
||||
"icon": "mdi-calendar",
|
||||
"description": _("Calendar"),
|
||||
"url": "/user/calendars",
|
||||
},
|
||||
{
|
||||
"name": "contacts",
|
||||
"label": _("Contacts"),
|
||||
"icon": "mdi-contacts-outline",
|
||||
"description": _("Address book"),
|
||||
"url": "/user/contacts",
|
||||
},
|
||||
{
|
||||
"name": "webmail",
|
||||
"label": _("Webmail"),
|
||||
"icon": "mdi-at",
|
||||
"description": _("Webmail"),
|
||||
"url": "/user/webmail",
|
||||
},
|
||||
]
|
||||
if "modoboa.contacts" in settings.MODOBOA_APPS:
|
||||
apps += [
|
||||
{
|
||||
"name": "contacts",
|
||||
"label": _("Contacts"),
|
||||
"icon": "mdi-contacts-outline",
|
||||
"description": _("Address book"),
|
||||
"url": "/user/contacts",
|
||||
}
|
||||
]
|
||||
if "modoboa.calendars" in settings.MODOBOA_APPS:
|
||||
apps += [
|
||||
{
|
||||
"name": "calendar",
|
||||
"label": _("Calendars"),
|
||||
"icon": "mdi-calendar",
|
||||
"description": _("Calendar"),
|
||||
"url": "/user/calendars",
|
||||
}
|
||||
]
|
||||
if "modoboa.webmail" in settings.MODOBOA_APPS:
|
||||
apps += [
|
||||
{
|
||||
"name": "webmail",
|
||||
"label": _("Webmail"),
|
||||
"icon": "mdi-at",
|
||||
"description": _("Webmail"),
|
||||
"url": "/user/webmail",
|
||||
}
|
||||
]
|
||||
|
||||
apps += exts_pool.get_available_apps()
|
||||
serializer = serializers.ModoboaApplicationSerializer(apps, many=True)
|
||||
return response.Response(serializer.data)
|
||||
|
||||
Reference in New Issue
Block a user