Allow using webhooks for notifications
This commit is contained in:
@@ -74,14 +74,26 @@ class NotificationSettingsForm(RestrictedFormMixin, ModelForm):
|
||||
class Meta:
|
||||
model = NotificationSettings
|
||||
fields = (
|
||||
"ntfy_topic",
|
||||
"ntfy_url",
|
||||
"topic",
|
||||
"url",
|
||||
"service",
|
||||
)
|
||||
help_texts = {
|
||||
"ntfy_topic": "The topic to send notifications to.",
|
||||
"ntfy_url": "Custom NTFY server. Leave blank to use the default server.",
|
||||
"topic": "The topic to send notifications to.",
|
||||
"url": "Custom NTFY server/webhook destination. Leave blank to use the default server for NTFY. For webhooks this field is required.",
|
||||
"service": "The service to use for notifications.",
|
||||
}
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super(NotificationSettingsForm, self).clean()
|
||||
if "service" in cleaned_data:
|
||||
if cleaned_data["service"] == "webhook":
|
||||
if not cleaned_data.get("url"):
|
||||
self.add_error(
|
||||
"url",
|
||||
"You must set a URL for webhooks.",
|
||||
)
|
||||
|
||||
|
||||
class NotificationRuleForm(RestrictedFormMixin, ModelForm):
|
||||
class Meta:
|
||||
@@ -92,12 +104,16 @@ class NotificationRuleForm(RestrictedFormMixin, ModelForm):
|
||||
"interval",
|
||||
"window",
|
||||
"priority",
|
||||
"service",
|
||||
"url",
|
||||
"topic",
|
||||
"enabled",
|
||||
)
|
||||
help_texts = {
|
||||
"name": "The name of the rule.",
|
||||
"priority": "The notification priority of the rule.",
|
||||
"url": "Custom NTFY server/webhook destination. Leave blank to use the default server for NTFY. For webhooks this field is required.",
|
||||
"service": "The service to use for notifications",
|
||||
"topic": "The topic to send notifications to. Leave blank for default.",
|
||||
"enabled": "Whether the rule is enabled.",
|
||||
"data": "The notification rule definition.",
|
||||
@@ -107,6 +123,13 @@ class NotificationRuleForm(RestrictedFormMixin, ModelForm):
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super(NotificationRuleForm, self).clean()
|
||||
if "service" in cleaned_data:
|
||||
if cleaned_data["service"] == "webhook":
|
||||
if not cleaned_data.get("url"):
|
||||
self.add_error(
|
||||
"url",
|
||||
"You must set a URL for webhooks.",
|
||||
)
|
||||
try:
|
||||
# Passing db to avoid circular import
|
||||
parsed_data = NotificationRuleData(self.request.user, cleaned_data, db=db)
|
||||
|
||||
Reference in New Issue
Block a user