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

@ -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}",