From 9a8bb9027ffc742da0a16d0b5467ffa246a37028 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Thu, 9 Feb 2023 20:50:05 +0000 Subject: [PATCH] Make notifications available to all users and clear database matches on reset --- core/templatetags/splitstr.py | 2 +- core/views/notifications.py | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/core/templatetags/splitstr.py b/core/templatetags/splitstr.py index fa0d11c..2519895 100644 --- a/core/templatetags/splitstr.py +++ b/core/templatetags/splitstr.py @@ -5,4 +5,4 @@ register = template.Library() @register.filter def splitstr(value, arg): - return value.split(arg) \ No newline at end of file + return value.split(arg) diff --git a/core/views/notifications.py b/core/views/notifications.py index 74398fc..e6d61f5 100644 --- a/core/views/notifications.py +++ b/core/views/notifications.py @@ -2,15 +2,16 @@ from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMix from django.shortcuts import render from rest_framework.views import APIView +from core.db.storage import db from core.forms import NotificationRuleForm, NotificationSettingsForm +from core.lib.rules import NotificationRuleData from core.models import NotificationRule, NotificationSettings from core.views.helpers import ObjectCreate, ObjectDelete, ObjectList, ObjectUpdate # Notifications - we create a new notification settings object if there isn't one # Hence, there is only an update view, not a create view. -class NotificationsUpdate(LoginRequiredMixin, PermissionRequiredMixin, ObjectUpdate): - permission_required = "use_rules" +class NotificationsUpdate(LoginRequiredMixin, ObjectUpdate): model = NotificationSettings form_class = NotificationSettingsForm @@ -76,6 +77,9 @@ class RuleClear(LoginRequiredMixin, PermissionRequiredMixin, APIView): rule.match[index] = None rule.save() + rule_data = NotificationRuleData(rule.user, rule, db=db) + rule_data.clear_database_matches() + cleared_indices = ", ".join(rule.match) context = { "message": f"Cleared match status for indices: {cleared_indices}",