|
|
|
@ -1,4 +1,6 @@
|
|
|
|
|
from django.contrib.auth.mixins import LoginRequiredMixin, PermissionRequiredMixin
|
|
|
|
|
from django.shortcuts import render
|
|
|
|
|
from rest_framework.views import APIView
|
|
|
|
|
|
|
|
|
|
from core.forms import NotificationRuleForm, NotificationSettingsForm
|
|
|
|
|
from core.models import NotificationRule, NotificationSettings
|
|
|
|
@ -61,3 +63,24 @@ class RuleUpdate(LoginRequiredMixin, PermissionRequiredMixin, ObjectUpdate):
|
|
|
|
|
class RuleDelete(LoginRequiredMixin, PermissionRequiredMixin, ObjectDelete):
|
|
|
|
|
permission_required = "use_rules"
|
|
|
|
|
model = NotificationRule
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RuleClear(LoginRequiredMixin, PermissionRequiredMixin, APIView):
|
|
|
|
|
permission_required = "use_rules"
|
|
|
|
|
|
|
|
|
|
def post(self, request, type, pk):
|
|
|
|
|
template_name = "partials/notify.html"
|
|
|
|
|
rule = NotificationRule.objects.get(pk=pk, user=request.user)
|
|
|
|
|
if isinstance(rule.match, dict):
|
|
|
|
|
for index in rule.match:
|
|
|
|
|
rule.match[index] = False
|
|
|
|
|
rule.save()
|
|
|
|
|
|
|
|
|
|
cleared_indices = ", ".join(rule.match)
|
|
|
|
|
context = {
|
|
|
|
|
"message": f"Cleared match status for indices: {cleared_indices}",
|
|
|
|
|
"class": "success",
|
|
|
|
|
}
|
|
|
|
|
response = render(request, template_name, context)
|
|
|
|
|
response["HX-Trigger"] = "notificationruleEvent"
|
|
|
|
|
return response
|
|
|
|
|