Skip to content

Commit a845721

Browse files
authored
Merge branch 'master' into issues/204-sortedm2m-queries
2 parents 9088448 + 957c4a3 commit a845721

File tree

8 files changed

+35
-142
lines changed

8 files changed

+35
-142
lines changed

docs/user/rest-api.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -275,28 +275,28 @@ Get Device Connection Detail
275275

276276
.. code-block:: text
277277
278-
GET /api/v1/controller/device/{id}/connection/{id}/
278+
GET /api/v1/controller/device/{device_id}/connection/{connection_id}/
279279
280280
Change Device Connection Detail
281281
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
282282

283283
.. code-block:: text
284284
285-
PUT /api/v1/controller/device/{id}/connection/{id}/
285+
PUT /api/v1/controller/device/{device_id}/connection/{connection_id}/
286286
287287
Patch Device Connection Detail
288288
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
289289

290290
.. code-block:: text
291291
292-
PATCH /api/v1/controller/device/{id}/connection/{id}/
292+
PATCH /api/v1/controller/device/{device_id}/connection/{connection_id}/
293293
294294
Delete Device Connection
295295
~~~~~~~~~~~~~~~~~~~~~~~~
296296

297297
.. code-block:: text
298298
299-
DELETE /api/v1/controller/device/{id}/connection/{id}/
299+
DELETE /api/v1/controller/device/{device_id}/connection/{connection_id}/
300300
301301
List Credentials
302302
~~~~~~~~~~~~~~~~
@@ -345,14 +345,14 @@ List Commands of a Device
345345

346346
.. code-block:: text
347347
348-
GET /api/v1/controller/device/{id}/command/
348+
GET /api/v1/controller/device/{device_id}/command/
349349
350-
Execute a Command a Device
351-
~~~~~~~~~~~~~~~~~~~~~~~~~~
350+
Execute a Command on a Device
351+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
352352

353353
.. code-block:: text
354354
355-
POST /api/v1/controller/device/{id}/command/
355+
POST /api/v1/controller/device/{device_id}/command/
356356
357357
Get Command Details
358358
~~~~~~~~~~~~~~~~~~~

openwisp_controller/config/tests/test_notifications.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from django.apps.registry import apps
55
from django.conf import settings
66
from django.test import TransactionTestCase
7+
from django.urls import reverse
78
from requests.exceptions import RequestException
89
from swapper import load_model
910

@@ -40,6 +41,7 @@ def setUp(self):
4041

4142
def test_config_problem_notification(self):
4243
config = self._create_config()
44+
device = config.device
4345
config.set_status_error()
4446

4547
self.assertEqual(config.status, 'error')
@@ -53,8 +55,15 @@ def test_config_problem_notification(self):
5355
f'[example.com] ERROR: "{config.device}"'
5456
' configuration encountered an error',
5557
)
56-
self.assertIn('encountered an error', notification.message)
57-
self.assertEqual(notification.target_url.endswith('#config-group'), True)
58+
expected_target_url = ('https://example.com{}#config-group').format(
59+
reverse(f'admin:{self.app_label}_device_change', args=[device.id])
60+
)
61+
self.assertEqual(
62+
notification.message,
63+
f'<p>The configuration of <a href="{expected_target_url}">{device.name}</a>'
64+
' has encountered an error. The last working configuration has been'
65+
' restored from a backup present on the filesystem of the device.</p>',
66+
)
5867

5968
def test_device_registered(self):
6069
# To avoid adding repetitive code for registering a device,

openwisp_controller/config/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,5 +203,5 @@ def get_default_templates_queryset(
203203

204204

205205
def get_config_error_notification_target_url(obj, field, absolute_url=True):
206-
url = _get_object_link(obj, field, absolute_url)
206+
url = _get_object_link(obj._related_object(field), absolute_url)
207207
return f'{url}#config-group'

openwisp_controller/connection/api/urls.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ def get_api_urls(api_views):
1111
"""
1212
return [
1313
path(
14-
'api/v1/controller/device/<uuid:device_pk>/command/',
14+
'api/v1/controller/device/<uuid:device_id>/command/',
1515
api_views.command_list_create_view,
1616
name='device_command_list',
1717
),
1818
path(
19-
'api/v1/controller/device/<uuid:device_pk>/command/<uuid:pk>/',
19+
'api/v1/controller/device/<uuid:device_id>/command/<uuid:pk>/',
2020
api_views.command_details_view,
2121
name='device_command_details',
2222
),
@@ -31,12 +31,12 @@ def get_api_urls(api_views):
3131
name='credential_detail',
3232
),
3333
path(
34-
'api/v1/controller/device/<uuid:device_pk>/connection/',
34+
'api/v1/controller/device/<uuid:device_id>/connection/',
3535
api_views.deviceconnection_list_create_view,
3636
name='deviceconnection_list',
3737
),
3838
path(
39-
'api/v1/controller/device/<uuid:device_pk>/connection/<uuid:pk>/',
39+
'api/v1/controller/device/<uuid:device_id>/connection/<uuid:pk>/',
4040
api_views.deviceconnection_details_view,
4141
name='deviceconnection_detail',
4242
),

openwisp_controller/connection/api/views.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ def get_permissions(self):
4949

5050
def get_parent_queryset(self):
5151
return Device.objects.filter(
52-
pk=self.kwargs['device_pk'],
52+
pk=self.kwargs['device_id'],
5353
)
5454

5555
def get_queryset(self):
56-
return super().get_queryset().filter(device_id=self.kwargs['device_pk'])
56+
return super().get_queryset().filter(device_id=self.kwargs['device_id'])
5757

5858
def get_serializer_context(self):
5959
context = super().get_serializer_context()
60-
context['device_id'] = self.kwargs['device_pk']
60+
context['device_id'] = self.kwargs['device_id']
6161
return context
6262

6363

@@ -101,7 +101,7 @@ def get_queryset(self):
101101

102102
def get_serializer_context(self):
103103
context = super().get_serializer_context()
104-
context['device_id'] = self.kwargs['device_pk']
104+
context['device_id'] = self.kwargs['device_id']
105105
return context
106106

107107
def initial(self, *args, **kwargs):
@@ -112,11 +112,11 @@ def assert_parent_exists(self):
112112
try:
113113
assert self.get_parent_queryset().exists()
114114
except (AssertionError, ValidationError):
115-
device_id = self.kwargs['device_pk']
115+
device_id = self.kwargs['device_id']
116116
raise NotFound(detail=f'Device with ID "{device_id}" not found.')
117117

118118
def get_parent_queryset(self):
119-
return Device.objects.filter(pk=self.kwargs['device_pk'])
119+
return Device.objects.filter(pk=self.kwargs['device_id'])
120120

121121

122122
class DeviceConnenctionListCreateView(BaseDeviceConnection, ListCreateAPIView):
@@ -126,7 +126,7 @@ def get_queryset(self):
126126
return (
127127
super()
128128
.get_queryset()
129-
.filter(device_id=self.kwargs['device_pk'])
129+
.filter(device_id=self.kwargs['device_id'])
130130
.order_by('-created')
131131
)
132132

openwisp_controller/connection/apps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ def command_save_receiver(cls, sender, created, instance, **kwargs):
8181
)
8282

8383
@classmethod
84-
def _launch_update_config(cls, device_pk):
84+
def _launch_update_config(cls, device_id):
8585
"""
8686
Calls the background task update_config only if
8787
no other tasks are running for the same device
8888
"""
8989
from .tasks import update_config
9090

91-
update_config.delay(device_pk)
91+
update_config.delay(device_id)
9292

9393
@classmethod
9494
def is_working_changed_receiver(

openwisp_controller/connection/tasks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
_TASK_NAME = 'openwisp_controller.connection.tasks.update_config'
1616

1717

18-
def _is_update_in_progress(device_pk):
18+
def _is_update_in_progress(device_id):
1919
active = current_app.control.inspect().active()
2020
if not active:
2121
return False
2222
# check if there's any other running task before adding it
2323
for task_list in active.values():
2424
for task in task_list:
25-
if task['name'] == _TASK_NAME and str(device_pk) in task['args']:
25+
if task['name'] == _TASK_NAME and str(device_id) in task['args']:
2626
return True
2727
return False
2828

openwisp_controller/geo/static/leaflet/draw/leaflet.draw.i18n.js

Lines changed: 0 additions & 116 deletions
This file was deleted.

0 commit comments

Comments
 (0)