Skip to content

Commit

Permalink
[change] Configured target_link for config error notification
Browse files Browse the repository at this point in the history
  • Loading branch information
pandafy authored Jul 14, 2022
1 parent 97769b3 commit 231ae58
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions openwisp_controller/config/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ def register_notification_types(self):
'The last working configuration has been restored from a backup '
'present on the filesystem of the device.'
),
'target_link': (
'openwisp_controller.config.utils'
'.get_config_error_notification_target_url'
),
},
models=[self.device_model, self.config_model],
)
Expand Down
1 change: 1 addition & 0 deletions openwisp_controller/config/tests/test_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def test_config_problem_notification(self):
' configuration encountered an error',
)
self.assertIn('encountered an error', notification.message)
self.assertEqual(notification.target_url.endswith('#config-group'), True)

def test_device_registered(self):
# To avoid adding repetitive code for registering a device,
Expand Down
6 changes: 6 additions & 0 deletions openwisp_controller/config/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.http import Http404, HttpResponse
from django.shortcuts import get_object_or_404 as base_get_object_or_404
from django.urls import path, re_path
from openwisp_notifications.utils import _get_object_link

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -199,3 +200,8 @@ def get_default_templates_queryset(
if backend:
queryset = queryset.filter(backend=backend)
return queryset


def get_config_error_notification_target_url(obj, field, absolute_url=True):
url = _get_object_link(obj, field, absolute_url)
return f'{url}#config-group'

0 comments on commit 231ae58

Please sign in to comment.