Skip to content

Commit f3e3866

Browse files
committed
[chores:fix] Fixed recent duplication of routes and urls #608
The recent changes to implement asynchronous batches, duplicated the websocket routes and URL routes for the notification module. URL and websocket routes must be added at project level. I took advantage to update the extending docs page too. Related to #608
1 parent 82b99f8 commit f3e3866

File tree

5 files changed

+26
-27
lines changed

5 files changed

+26
-27
lines changed

docs/developer/extending.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,13 @@ Now you need to add ``myradius`` to ``INSTALLED_APPS`` in your
9090
# social login
9191
"allauth.socialaccount.providers.facebook", # optional, can be removed if social login is not needed
9292
"allauth.socialaccount.providers.google", # optional, can be removed if social login is not needed
93-
# SAML login
94-
"djangosaml2", # optional, can be removed if SAML login is not needed
93+
# openwisp notifications
94+
"openwisp_notifications",
9595
# openwisp
9696
# 'myradius', <-- replace with your app-name here
9797
"openwisp_users",
98+
# SAML login
99+
"djangosaml2", # optional, can be removed if SAML login is not needed
98100
"private_storage",
99101
"drf_yasg",
100102
]
@@ -105,7 +107,8 @@ Now you need to add ``myradius`` to ``INSTALLED_APPS`` in your
105107
106108
AUTHENTICATION_BACKENDS = (
107109
"openwisp_users.backends.UsersAuthenticationBackend",
108-
"openwisp_radius.saml.backends.OpenwispRadiusSaml2Backend", # optional, can be removed if SAML login is not needed
110+
"openwisp_radius.saml.backends.OpenwispRadiusSaml2Backend",
111+
"sesame.backends.ModelBackend",
109112
)
110113
111114
4. Add ``EXTENDED_APPS``
@@ -154,6 +157,8 @@ Add ``openwisp_utils.loaders.DependencyLoader`` to ``TEMPLATES`` in your
154157
"django.template.context_processors.request",
155158
"django.contrib.auth.context_processors.auth",
156159
"django.contrib.messages.context_processors.messages",
160+
"openwisp_utils.admin_theme.context_processor.menu_groups",
161+
"openwisp_notifications.context_processors.notification_api_settings",
157162
],
158163
},
159164
}
@@ -445,9 +450,10 @@ comments):
445450
urlpatterns = [
446451
# ... other urls in your project ...
447452
path("admin/", admin.site.urls),
448-
# openwisp-radius urls
453+
# URLs of other OpenWISP modules
449454
path("accounts/", include("openwisp_users.accounts.urls")),
450455
path("api/v1/", include("openwisp_utils.api.urls")),
456+
path("", include("openwisp_notifications.urls", namespace="notifications")),
451457
# Use only when extending views (discussed below)
452458
# path('', include((get_urls(api_views, social_views, saml_views), 'radius'), namespace='radius')),
453459
# Remove when extending views

openwisp_radius/routing.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
from django.urls import path
2-
from openwisp_notifications.websockets.routing import (
3-
get_routes as get_notification_routes,
4-
)
52

63
from . import consumers
74

@@ -10,4 +7,4 @@
107
"ws/radius/batch/<uuid:batch_id>/",
118
consumers.RadiusBatchConsumer.as_asgi(),
129
),
13-
] + get_notification_routes()
10+
]

openwisp_radius/urls.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,4 @@ def get_urls(api_views=None, social_views=None, saml_views=None):
2828
namespace = "radius"
2929
urlpatterns = [
3030
path("", include((get_urls(), namespace), namespace=namespace)),
31-
path(
32-
"",
33-
include(
34-
("openwisp_notifications.urls", "openwisp_notifications"),
35-
namespace="notifications",
36-
),
37-
),
3831
]

tests/openwisp2/routing.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@
44
from channels.routing import ProtocolTypeRouter, URLRouter
55
from channels.security.websocket import AllowedHostsOriginValidator
66
from django.core.asgi import get_asgi_application
7+
from openwisp_notifications.websockets.routing import (
8+
get_routes as get_notification_routes,
9+
)
710

811
from openwisp_radius.routing import (
912
websocket_urlpatterns as radius_websocket_urlpatterns,
1013
)
1114

12-
ws_routes = list(radius_websocket_urlpatterns)
15+
ws_routes = radius_websocket_urlpatterns + get_notification_routes()
1316

1417
if os.environ.get("MONITORING_INTEGRATION"):
15-
from openwisp_controller.routing import get_routes
18+
from openwisp_controller.routing import get_routes as get_controller_routes
1619

17-
ws_routes.extend(get_routes())
20+
ws_routes.extend(get_controller_routes())
1821

1922
application = ProtocolTypeRouter(
2023
{

tests/openwisp2/urls.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,6 @@
3333
path("api/v1/", include("openwisp_users.api.urls")),
3434
path("accounts/", include("openwisp_users.accounts.urls")),
3535
radius_urls,
36-
path(
37-
"",
38-
include(
39-
("openwisp_notifications.urls", "openwisp_notifications"),
40-
namespace="notifications",
41-
),
42-
),
4336
path(
4437
"captive-portal-mock/login/",
4538
views.captive_portal_login,
@@ -55,10 +48,17 @@
5548
urlpatterns += staticfiles_urlpatterns()
5649

5750
if os.environ.get("MONITORING_INTEGRATION"):
58-
urlpatterns = [
51+
urlpatterns += [
5952
path("", include("openwisp_controller.urls")),
6053
path("", include("openwisp_monitoring.urls")),
61-
] + urlpatterns
54+
]
55+
else:
56+
# openwisp_controller.urls ships notification URLs,
57+
# if monitoring integration is not enabled we need
58+
# to add the URLs here
59+
urlpatterns += [
60+
path("", include("openwisp_notifications.urls", namespace="notifications")),
61+
]
6262

6363
if settings.DEBUG and "debug_toolbar" in settings.INSTALLED_APPS:
6464
import debug_toolbar

0 commit comments

Comments
 (0)