🤬
Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
  • ■ ■ ■ ■ ■ ■
    changedetectionio/forms.py
    skipped 354 lines
    355 355   filter_failure_notification_send = BooleanField(
    356 356   'Send a notification when the filter can no longer be found on the page', default=False)
    357 357   
     358 + notification_use_default = BooleanField('Use default/system notification settings', default=True)
     359 + 
    358 360   def validate(self, **kwargs):
    359 361   if not super().validate():
    360 362   return False
    skipped 48 lines
  • ■ ■ ■ ■ ■
    changedetectionio/model/Watch.py
    skipped 34 lines
    35 35   'notification_title': default_notification_title,
    36 36   'notification_body': default_notification_body,
    37 37   'notification_format': default_notification_format,
     38 + 'notification_use_default': True, # Use default for new
    38 39   'notification_muted': False,
    39 40   'css_filter': '',
    40 41   'last_error': False,
    skipped 216 lines
  • ■ ■ ■ ■ ■ ■
    changedetectionio/static/js/watch-settings.js
    1  -$(document).ready(function() {
    2  - function toggle() {
     1 +$(document).ready(function () {
     2 + function toggle_fetch_backend() {
    3 3   if ($('input[name="fetch_backend"]:checked').val() == 'html_webdriver') {
    4  - if(playwright_enabled) {
     4 + if (playwright_enabled) {
    5 5   // playwright supports headers, so hide everything else
    6 6   // See #664
    7 7   $('#requests-override-options #request-method').hide();
    skipped 5 lines
    13 13   // selenium/webdriver doesnt support anything afaik, hide it all
    14 14   $('#requests-override-options').hide();
    15 15   }
    16  - 
    17  - 
    18 16   $('#webdriver-override-options').show();
    19  - 
    20 17   } else {
    21  - 
    22 18   $('#requests-override-options').show();
    23 19   $('#requests-override-options *:hidden').show();
    24 20   $('#webdriver-override-options').hide();
    skipped 1 lines
    26 22   }
    27 23   
    28 24   $('input[name="fetch_backend"]').click(function (e) {
    29  - toggle();
     25 + toggle_fetch_backend();
    30 26   });
    31  - toggle();
     27 + toggle_fetch_backend();
     28 + 
     29 + function toggle_default_notifications() {
     30 + var n=$('#notification_urls, #notification_title, #notification_body, #notification_format');
     31 + if ($('#notification_use_default').is(':checked')) {
     32 + $('#notification-field-group').fadeOut();
     33 + $(n).each(function (e) {
     34 + $(this).attr('readonly', true);
     35 + });
     36 + } else {
     37 + $('#notification-field-group').show();
     38 + $(n).each(function (e) {
     39 + $(this).attr('readonly', false);
     40 + });
     41 + }
     42 + }
    32 43   
     44 + $('#notification_use_default').click(function (e) {
     45 + toggle_default_notifications();
     46 + });
     47 + toggle_default_notifications();
    33 48  });
    34 49   
  • ■ ■ ■ ■ ■ ■
    changedetectionio/store.py
    skipped 535 lines
    536 536   except:
    537 537   continue
    538 538   return
     539 + 
     540 + 
     541 + def update_5(self):
     542 + 
     543 + from changedetectionio.notification import (
     544 + default_notification_body,
     545 + default_notification_format,
     546 + default_notification_title,
     547 + )
     548 + 
     549 + for uuid, watch in self.data['watching'].items():
     550 + try:
     551 + # If it's all the same to the system settings, then prefer system notification settings
     552 + # include \r\n -> \n incase they already hit submit and the browser put \r in
     553 + if watch.get('notification_body').replace('\r\n', '\n') == default_notification_body.replace('\r\n', '\n') and \
     554 + watch.get('notification_format') == default_notification_format and \
     555 + watch.get('notification_title').replace('\r\n', '\n') == default_notification_title.replace('\r\n', '\n') and \
     556 + watch.get('notification_urls') == self.__data['settings']['application']['notification_urls']:
     557 + watch['notification_use_default'] = True
     558 + else:
     559 + watch['notification_use_default'] = False
     560 + except:
     561 + continue
     562 + return
  • ■ ■ ■ ■ ■ ■
    changedetectionio/templates/edit.html
    skipped 134 lines
    135 135   </div>
    136 136   
    137 137   <div class="tab-pane-inner" id="notifications">
    138  - <strong>Note: <i>These settings override the global settings for this watch.</i></strong>
    139 138   <fieldset>
    140  - <div class="field-group">
     139 + <div class="pure-control-group inline-radio">
     140 + {{ render_checkbox_field(form.notification_use_default) }}
     141 + </div>
     142 + <div class="field-group" id="notification-field-group">
    141 143   {{ render_common_settings_form(form, current_base_url, emailprefix) }}
    142 144   </div>
    143 145   </fieldset>
    skipped 180 lines
  • ■ ■ ■ ■ ■ ■
    changedetectionio/tests/test_notification.py
    skipped 70 lines
    71 71   "url": test_url,
    72 72   "tag": "my tag",
    73 73   "title": "my title",
     74 + # No 'notification_use_default' here, so it's effectively False/off
    74 75   "headers": "",
    75 76   "fetch_backend": "html_requests"})
    76 77   
    skipped 139 lines
    216 217   follow_redirects=True
    217 218   )
    218 219   
     220 +# Check that the default VS watch specific notification is hit
     221 +def test_check_notification_use_default(client, live_server):
     222 + set_original_response()
     223 + notification_url = url_for('test_notification_endpoint', _external=True).replace('http', 'json')
     224 + test_url = url_for('test_endpoint', _external=True)
     225 + 
     226 + res = client.post(
     227 + url_for("form_quick_watch_add"),
     228 + data={"url": test_url, "tag": ''},
     229 + follow_redirects=True
     230 + )
     231 + assert b"Watch added" in res.data
     232 + 
     233 + ## Setup the local one and enable it
     234 + res = client.post(
     235 + url_for("edit_page", uuid="first"),
     236 + data={"notification_urls": notification_url,
     237 + "notification_title": "watch-notification",
     238 + "notification_body": "watch-body",
     239 + 'notification_use_default': "True",
     240 + "notification_format": "Text",
     241 + "url": test_url,
     242 + "tag": "my tag",
     243 + "title": "my title",
     244 + "headers": "",
     245 + "fetch_backend": "html_requests"},
     246 + follow_redirects=True
     247 + )
     248 + 
     249 + res = client.post(
     250 + url_for("settings_page"),
     251 + data={"application-notification_title": "global-notifications-title",
     252 + "application-notification_body": "global-notifications-body\n",
     253 + "application-notification_format": "Text",
     254 + "application-notification_urls": notification_url,
     255 + "requests-time_between_check-minutes": 180,
     256 + "fetch_backend": "html_requests"
     257 + },
     258 + follow_redirects=True
     259 + )
     260 + 
     261 + # A change should by default trigger a notification of the global-notifications
     262 + time.sleep(1)
     263 + set_modified_response()
     264 + client.get(url_for("form_watch_checknow"), follow_redirects=True)
     265 + time.sleep(2)
     266 + with open("test-datastore/notification.txt", "r") as f:
     267 + assert 'global-notifications-title' in f.read()
     268 + 
     269 + ## Setup the local one and enable it
     270 + res = client.post(
     271 + url_for("edit_page", uuid="first"),
     272 + data={"notification_urls": notification_url,
     273 + "notification_title": "watch-notification",
     274 + "notification_body": "watch-body",
     275 + # No 'notification_use_default' here, so it's effectively False/off = "dont use default, use this one"
     276 + "notification_format": "Text",
     277 + "url": test_url,
     278 + "tag": "my tag",
     279 + "title": "my title",
     280 + "headers": "",
     281 + "fetch_backend": "html_requests"},
     282 + follow_redirects=True
     283 + )
     284 + set_original_response()
     285 + 
     286 + client.get(url_for("form_watch_checknow"), follow_redirects=True)
     287 + time.sleep(2)
     288 + assert os.path.isfile("test-datastore/notification.txt")
     289 + with open("test-datastore/notification.txt", "r") as f:
     290 + assert 'watch-notification' in f.read()
     291 + 
     292 + 
     293 + # cleanup for the next
     294 + client.get(
     295 + url_for("form_delete", uuid="all"),
     296 + follow_redirects=True
     297 + )
  • ■ ■ ■ ■ ■ ■
    changedetectionio/update_worker.py
    skipped 40 lines
    41 41   )
    42 42   
    43 43   # Did it have any notification alerts to hit?
    44  - if len(watch['notification_urls']):
     44 + if not watch.get('notification_use_default') and len(watch['notification_urls']):
    45 45   print(">>> Notifications queued for UUID from watch {}".format(watch_uuid))
    46 46   n_object['notification_urls'] = watch['notification_urls']
    47 47   n_object['notification_title'] = watch['notification_title']
    skipped 1 lines
    49 49   n_object['notification_format'] = watch['notification_format']
    50 50   
    51 51   # No? maybe theres a global setting, queue them all
    52  - elif len(self.datastore.data['settings']['application']['notification_urls']):
     52 + elif watch.get('notification_use_default') and len(self.datastore.data['settings']['application']['notification_urls']):
    53 53   print(">>> Watch notification URLs were empty, using GLOBAL notifications for UUID: {}".format(watch_uuid))
    54 54   n_object['notification_urls'] = self.datastore.data['settings']['application']['notification_urls']
    55 55   n_object['notification_title'] = self.datastore.data['settings']['application']['notification_title']
    skipped 243 lines
Please wait...
Page is in error, reload to recover