Make notifications available to all users and clear database matches on reset

This commit is contained in:
Mark Veidemanis 2023-02-09 20:50:05 +00:00
parent 9519c1ac9f
commit 9a8bb9027f
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
2 changed files with 7 additions and 3 deletions

View File

@ -5,4 +5,4 @@ register = template.Library()
@register.filter @register.filter
def splitstr(value, arg): def splitstr(value, arg):
return value.split(arg) return value.split(arg)

View File

@ -2,15 +2,16 @@ from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMix
from django.shortcuts import render from django.shortcuts import render
from rest_framework.views import APIView from rest_framework.views import APIView
from core.db.storage import db
from core.forms import NotificationRuleForm, NotificationSettingsForm from core.forms import NotificationRuleForm, NotificationSettingsForm
from core.lib.rules import NotificationRuleData
from core.models import NotificationRule, NotificationSettings from core.models import NotificationRule, NotificationSettings
from core.views.helpers import ObjectCreate, ObjectDelete, ObjectList, ObjectUpdate from core.views.helpers import ObjectCreate, ObjectDelete, ObjectList, ObjectUpdate
# Notifications - we create a new notification settings object if there isn't one # Notifications - we create a new notification settings object if there isn't one
# Hence, there is only an update view, not a create view. # Hence, there is only an update view, not a create view.
class NotificationsUpdate(LoginRequiredMixin, PermissionRequiredMixin, ObjectUpdate): class NotificationsUpdate(LoginRequiredMixin, ObjectUpdate):
permission_required = "use_rules"
model = NotificationSettings model = NotificationSettings
form_class = NotificationSettingsForm form_class = NotificationSettingsForm
@ -76,6 +77,9 @@ class RuleClear(LoginRequiredMixin, PermissionRequiredMixin, APIView):
rule.match[index] = None rule.match[index] = None
rule.save() rule.save()
rule_data = NotificationRuleData(rule.user, rule, db=db)
rule_data.clear_database_matches()
cleared_indices = ", ".join(rule.match) cleared_indices = ", ".join(rule.match)
context = { context = {
"message": f"Cleared match status for indices: {cleared_indices}", "message": f"Cleared match status for indices: {cleared_indices}",