kopia lustrzana https://github.com/dgtlmoon/changedetection.io
"Send Test Notification" button from watch form edit should respect global settings and tag/group settings ( #2289, #2263 )
rodzic
1ae59551be
commit
8e5bf91965
|
@ -516,21 +516,35 @@ def changedetection_app(config=None, datastore_o=None):
|
||||||
|
|
||||||
watch = datastore.data['watching'].get(watch_uuid) if watch_uuid else None
|
watch = datastore.data['watching'].get(watch_uuid) if watch_uuid else None
|
||||||
|
|
||||||
# validate URLS
|
notification_urls = request.form['notification_urls'].strip().splitlines()
|
||||||
if not len(request.form['notification_urls'].strip()):
|
|
||||||
|
if not notification_urls:
|
||||||
|
logger.debug("Test notification - Trying by group/tag")
|
||||||
|
if request.form['tags'].strip():
|
||||||
|
for k in request.form['tags'].split(','):
|
||||||
|
tag = datastore.tag_exists_by_name(k.strip())
|
||||||
|
notification_urls = tag.get('notifications_urls') if tag and tag.get('notifications_urls') else None
|
||||||
|
|
||||||
|
if not notification_urls:
|
||||||
|
logger.debug("Test notification - Trying by global system settings notifications")
|
||||||
|
if datastore.data['settings']['application'].get('notification_urls'):
|
||||||
|
notification_urls = datastore.data['settings']['application']['notification_urls']
|
||||||
|
|
||||||
|
|
||||||
|
if not notification_urls:
|
||||||
return make_response({'error': 'No Notification URLs set'}, 400)
|
return make_response({'error': 'No Notification URLs set'}, 400)
|
||||||
|
|
||||||
for server_url in request.form['notification_urls'].splitlines():
|
for n_url in notification_urls:
|
||||||
if len(server_url.strip()):
|
if len(n_url.strip()):
|
||||||
if not apobj.add(server_url):
|
if not apobj.add(n_url):
|
||||||
message = '{} is not a valid AppRise URL.'.format(server_url)
|
message = '{} is not a valid AppRise URL.'.format(n_url)
|
||||||
return make_response({'error': message}, 400)
|
return make_response({'error': message}, 400)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# use the same as when it is triggered, but then override it with the form test values
|
# use the same as when it is triggered, but then override it with the form test values
|
||||||
n_object = {
|
n_object = {
|
||||||
'watch_url': request.form['window_url'],
|
'watch_url': request.form['window_url'],
|
||||||
'notification_urls': request.form['notification_urls'].splitlines()
|
'notification_urls': notification_urls
|
||||||
}
|
}
|
||||||
|
|
||||||
# Only use if present, if not set in n_object it should use the default system value
|
# Only use if present, if not set in n_object it should use the default system value
|
||||||
|
|
|
@ -28,15 +28,11 @@ $(document).ready(function() {
|
||||||
notification_format: $('#notification_format').val(),
|
notification_format: $('#notification_format').val(),
|
||||||
notification_title: $('#notification_title').val(),
|
notification_title: $('#notification_title').val(),
|
||||||
notification_urls: $('.notification-urls').val(),
|
notification_urls: $('.notification-urls').val(),
|
||||||
|
tags: $('#tags').val(),
|
||||||
window_url: window.location.href,
|
window_url: window.location.href,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!data['notification_urls'].length) {
|
|
||||||
alert("Notification URL list is empty, cannot send test.")
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: notification_base_url,
|
url: notification_base_url,
|
||||||
|
|
|
@ -657,7 +657,10 @@ class ChangeDetectionStore:
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def tag_exists_by_name(self, tag_name):
|
def tag_exists_by_name(self, tag_name):
|
||||||
return any(v.get('title', '').lower() == tag_name.lower() for k, v in self.__data['settings']['application']['tags'].items())
|
# Check if any tag dictionary has a 'title' attribute matching the provided tag_name
|
||||||
|
tags = self.__data['settings']['application']['tags'].values()
|
||||||
|
return next((v for v in tags if v.get('title', '').lower() == tag_name.lower()),
|
||||||
|
None)
|
||||||
|
|
||||||
def get_updates_available(self):
|
def get_updates_available(self):
|
||||||
import inspect
|
import inspect
|
||||||
|
|
Ładowanie…
Reference in New Issue