From f7c7cd627b33171e1d88fa82a1cc1317d4ec05aa Mon Sep 17 00:00:00 2001
From: zachmann <gabriel.zachmann@kit.edu>
Date: Fri, 16 Feb 2024 12:13:32 +0100
Subject: [PATCH] fix ics_invite

---
 internal/notifier/server/notifier_server.go   |   1 +
 .../server/web/static/js/notifications.js     | 192 +++++++++++++++++-
 internal/server/web/static/js/tokeninfo.js    | 186 -----------------
 3 files changed, 192 insertions(+), 187 deletions(-)

diff --git a/internal/notifier/server/notifier_server.go b/internal/notifier/server/notifier_server.go
index 8ee8a543..b51de6e3 100644
--- a/internal/notifier/server/notifier_server.go
+++ b/internal/notifier/server/notifier_server.go
@@ -28,6 +28,7 @@ func HandleEmailRequest(req pkg.EmailNotificationRequest) error {
 			log.WithError(err).Error("error while sending ics mail invite")
 			return err
 		}
+		return nil
 	}
 	sender := mailing.PlainTextMailSender
 	if req.PreferHTML {
diff --git a/internal/server/web/static/js/notifications.js b/internal/server/web/static/js/notifications.js
index 7351f66c..b50b1760 100644
--- a/internal/server/web/static/js/notifications.js
+++ b/internal/server/web/static/js/notifications.js
@@ -180,4 +180,194 @@ function copyTokenTr($tr, force, tokens) {
         copyTokenTr($child, true, tokens);
     })
 
-}
\ No newline at end of file
+}
+
+
+const $notificationTypeSelector = $('#notification-type-selector');
+
+function notificationModal(doesExpire) {
+    let id = this.id.replace("notify-", "");
+    $notificationMOMID.val(id);
+    $('.notification-type-option').attr("disabled", false);
+    if (!doesExpire) {
+        $('#notification-type-option-calendar').attr("disabled", true);
+        $('#notification-type-option-entry').attr("disabled", true);
+        $notificationTypeSelector.val("email");
+    }
+    $notificationTypeSelector.trigger('change');
+    $notificationsModal.modal();
+}
+
+const $notificationTypeEmailContent = $('.notify-email-content');
+const $notificationTypeEntryContent = $('.notify-entry-content');
+const $notificationTypeCalendarContent = $('.notify-calendar-content');
+
+const $calendarSelector = $('#notify-calendar-selector');
+const $calendarURL = $('#notify-calendar-url');
+
+let calendarURLs = {};
+
+let cachedNotificationsTypeData = {};
+
+$notificationTypeSelector.on('change', function () {
+    let t = $(this).val();
+    switch (t) {
+        case 'email':
+            $notificationTypeEntryContent.hideB();
+            $notificationTypeCalendarContent.hideB();
+            $notificationTypeEmailContent.showB();
+            break;
+        case 'entry':
+            $notificationTypeCalendarContent.hideB();
+            $notificationTypeEmailContent.hideB();
+            $notificationTypeEntryContent.showB();
+
+            let email_ok = cachedNotificationsTypeData["email_ok"];
+            if (email_ok !== undefined && email_ok !== null && email_ok) {
+                break;
+            }
+            $('.notify-entry-content-element').hideB();
+            $.ajax({
+                type: "GET",
+                url: storageGet('usersettings_endpoint') + "/email",
+                success: function (res) {
+                    let email = res["email_address"];
+                    let email_verified = res["email_verified"];
+                    if (email === undefined || email === null || email === "") {
+                        $('#email-not-verified-hint').showB();
+                        cachedNotificationsTypeData["email_ok"] = false;
+                        return;
+                    }
+                    if (email_verified === undefined || !email_verified) {
+                        $('#email-not-set-hint').showB();
+                        cachedNotificationsTypeData["email_ok"] = false;
+                        return;
+                    }
+                    $('#notify-entry-content-normal').showB();
+                    cachedNotificationsTypeData["email_ok"] = true;
+                },
+                error: function (errRes) {
+                    $errorModalMsg.text(getErrorMessage(errRes));
+                    $errorModal.modal();
+                },
+            });
+            break;
+        case 'calendar':
+            $notificationTypeEntryContent.hideB();
+            $notificationTypeEmailContent.hideB();
+            $notificationTypeCalendarContent.showB();
+
+        function fillCals(cals) {
+            let options = "";
+            if (cals !== undefined && cals !== null) {
+                cals.forEach(function (cal) {
+                    let name = cal["name"];
+                    calendarURLs[name] = cal["ics_path"];
+                    options += `<option value=${name}>${name}</option>`;
+                });
+                cachedNotificationsTypeData["calendars"] = cals;
+            }
+            $calendarSelector.html(options);
+            $calendarSelector.trigger('change');
+        }
+
+            let cals = cachedNotificationsTypeData["calendars"];
+            if (cals !== undefined && cals !== null && cals.length > 0) {
+                fillCals(cals);
+                break;
+            }
+            $.ajax({
+                type: "GET",
+                url: storageGet('notifications_endpoint') + "/calendars",
+                success: function (res) {
+                    let cals = res["calendars"];
+                    fillCals(cals);
+                },
+                error: function (errRes) {
+                    $settingsErrorModalMsg.text(getErrorMessage(errRes));
+                    $settingsErrorModal.modal();
+                },
+            });
+            break;
+    }
+})
+
+$('#sent-entry').on('click', function () {
+    let data = {
+        "mom_id": $notificationMOMID.val(),
+        "notification_type": "ics_invite"
+    };
+    let comment = $('#notify-entry-comment').val();
+    if (comment !== undefined && comment !== null && comment !== "") {
+        data["comment"] = comment;
+    }
+    data = JSON.stringify(data);
+    $.ajax({
+        type: "POST",
+        data: data,
+        dataType: "json",
+        contentType: "application/json",
+        url: storageGet('notifications_endpoint'),
+        success: function () {
+            $notificationsModal.modal("hide");
+        },
+        error: function (errRes) {
+            $errorModalMsg.text(getErrorMessage(errRes));
+            $errorModal.modal();
+        },
+    });
+})
+
+$calendarSelector.on('change', function () {
+    let url = calendarURLs[$(this).val()];
+    $calendarURL.text(url);
+    $calendarURL.attr("href", url);
+})
+
+$('#sent-calendar-add').on('click', function () {
+    let data = {"mom_id": $notificationMOMID.val()};
+    let comment = $('#notify-calendar-comment').val();
+    if (comment !== undefined && comment !== null && comment !== "") {
+        data["comment"] = comment;
+    }
+    let calendar = $calendarSelector.val();
+    data = JSON.stringify(data);
+    $.ajax({
+        type: "POST",
+        data: data,
+        dataType: "json",
+        contentType: "application/json",
+        url: storageGet('notifications_endpoint') + "/calendars/" + calendar,
+        success: function () {
+            $notificationsModal.modal("hide");
+        },
+        error: function (errRes) {
+            $errorModalMsg.text(getErrorMessage(errRes));
+            $errorModal.modal();
+        },
+    });
+})
+
+$('#sent-create-mail-notification').on('click', function () {
+    let data = {
+        "mom_id": $notificationMOMID.val(),
+        "notification_type": "mail",
+        "notification_classes": getCheckedCapabilities("notifications-"),
+        "include_children": $('#notification-req-include-children').prop("checked")
+    };
+    data = JSON.stringify(data);
+    $.ajax({
+        type: "POST",
+        data: data,
+        dataType: "json",
+        contentType: "application/json",
+        url: storageGet('notifications_endpoint'),
+        success: function () {
+            $notificationsModal.modal("hide");
+        },
+        error: function (errRes) {
+            $errorModalMsg.text(getErrorMessage(errRes));
+            $errorModal.modal();
+        },
+    });
+})
diff --git a/internal/server/web/static/js/tokeninfo.js b/internal/server/web/static/js/tokeninfo.js
index 2f2ef45d..edcb2201 100644
--- a/internal/server/web/static/js/tokeninfo.js
+++ b/internal/server/web/static/js/tokeninfo.js
@@ -323,189 +323,3 @@ $('#revoke-tokeninfo').on('click', function () {
     $revocationFormID.addClass(revocationClassFromTokeninfo);
     $revocationModal.modal();
 })
-
-const $notificationTypeSelector = $('#notification-type-selector');
-
-function notificationModal(doesExpire) {
-    let id = this.id.replace("notify-", "");
-    $notificationMOMID.val(id);
-    $('.notification-type-option').attr("disabled", false);
-    if (!doesExpire) {
-        $('#notification-type-option-calendar').attr("disabled", true);
-        $('#notification-type-option-entry').attr("disabled", true);
-        $notificationTypeSelector.val("email");
-    }
-    $notificationTypeSelector.trigger('change');
-    $notificationsModal.modal();
-}
-
-const $notificationTypeEmailContent = $('.notify-email-content');
-const $notificationTypeEntryContent = $('.notify-entry-content');
-const $notificationTypeCalendarContent = $('.notify-calendar-content');
-
-const $calendarSelector = $('#notify-calendar-selector');
-const $calendarURL = $('#notify-calendar-url');
-
-let calendarURLs = {};
-
-let cachedNotificationsTypeData = {};
-
-$notificationTypeSelector.on('change', function () {
-    let t = $(this).val();
-    switch (t) {
-        case 'email':
-            $notificationTypeEntryContent.hideB();
-            $notificationTypeCalendarContent.hideB();
-            $notificationTypeEmailContent.showB();
-            break;
-        case 'entry':
-            $notificationTypeCalendarContent.hideB();
-            $notificationTypeEmailContent.hideB();
-            $notificationTypeEntryContent.showB();
-
-            let email_ok = cachedNotificationsTypeData["email_ok"];
-            if (email_ok !== undefined && email_ok !== null && email_ok) {
-                break;
-            }
-            $('.notify-entry-content-element').hideB();
-            $.ajax({
-                type: "GET",
-                url: storageGet('usersettings_endpoint') + "/email",
-                success: function (res) {
-                    let email = res["email_address"];
-                    let email_verified = res["email_verified"];
-                    if (email === undefined || email === null || email === "") {
-                        $('#email-not-verified-hint').showB();
-                        cachedNotificationsTypeData["email_ok"] = false;
-                        return;
-                    }
-                    if (email_verified === undefined || !email_verified) {
-                        $('#email-not-set-hint').showB();
-                        cachedNotificationsTypeData["email_ok"] = false;
-                        return;
-                    }
-                    $('#notify-entry-content-normal').showB();
-                    cachedNotificationsTypeData["email_ok"] = true;
-                },
-                error: function (errRes) {
-                    $errorModalMsg.text(getErrorMessage(errRes));
-                    $errorModal.modal();
-                },
-            });
-            break;
-        case 'calendar':
-            $notificationTypeEntryContent.hideB();
-            $notificationTypeEmailContent.hideB();
-            $notificationTypeCalendarContent.showB();
-
-        function fillCals(cals) {
-            let options = "";
-            if (cals !== undefined && cals !== null) {
-                cals.forEach(function (cal) {
-                    let name = cal["name"];
-                    calendarURLs[name] = cal["ics_path"];
-                    options += `<option value=${name}>${name}</option>`;
-                });
-                cachedNotificationsTypeData["calendars"] = cals;
-            }
-            $calendarSelector.html(options);
-            $calendarSelector.trigger('change');
-        }
-
-            let cals = cachedNotificationsTypeData["calendars"];
-            if (cals !== undefined && cals !== null && cals.length > 0) {
-                fillCals(cals);
-                break;
-            }
-            $.ajax({
-                type: "GET",
-                url: storageGet('notifications_endpoint') + "/calendars",
-                success: function (res) {
-                    let cals = res["calendars"];
-                    fillCals(cals);
-                },
-                error: function (errRes) {
-                    $settingsErrorModalMsg.text(getErrorMessage(errRes));
-                    $settingsErrorModal.modal();
-                },
-            });
-            break;
-    }
-})
-
-$('#sent-entry').on('click', function () {
-    let data = {"mom_id": $notificationMOMID.val()};
-    let comment = $('#notify-entry-comment').val();
-    if (comment !== undefined && comment !== null && comment !== "") {
-        data["comment"] = comment;
-    }
-    data = JSON.stringify(data);
-    $.ajax({
-        type: "POST",
-        data: data,
-        dataType: "json",
-        contentType: "application/json",
-        url: storageGet('notifications_endpoint'),
-        success: function () {
-            $notificationsModal.modal("hide");
-        },
-        error: function (errRes) {
-            $errorModalMsg.text(getErrorMessage(errRes));
-            $errorModal.modal();
-        },
-    });
-})
-
-$calendarSelector.on('change', function () {
-    let url = calendarURLs[$(this).val()];
-    $calendarURL.text(url);
-    $calendarURL.attr("href", url);
-})
-
-$('#sent-calendar-add').on('click', function () {
-    let data = {"mom_id": $notificationMOMID.val()};
-    let comment = $('#notify-calendar-comment').val();
-    if (comment !== undefined && comment !== null && comment !== "") {
-        data["comment"] = comment;
-    }
-    let calendar = $calendarSelector.val();
-    data = JSON.stringify(data);
-    $.ajax({
-        type: "POST",
-        data: data,
-        dataType: "json",
-        contentType: "application/json",
-        url: storageGet('notifications_endpoint') + "/calendars/" + calendar,
-        success: function () {
-            $notificationsModal.modal("hide");
-        },
-        error: function (errRes) {
-            $errorModalMsg.text(getErrorMessage(errRes));
-            $errorModal.modal();
-        },
-    });
-})
-
-$('#sent-create-mail-notification').on('click', function () {
-    let data = {
-        "mom_id": $notificationMOMID.val(),
-        "notification_type": "mail",
-        "notification_classes": getCheckedCapabilities("notifications-"),
-        "include_children": $('#notification-req-include-children').prop("checked")
-    };
-    data = JSON.stringify(data);
-    $.ajax({
-        type: "POST",
-        data: data,
-        dataType: "json",
-        contentType: "application/json",
-        url: storageGet('notifications_endpoint'),
-        success: function () {
-            $notificationsModal.modal("hide");
-        },
-        error: function (errRes) {
-            $errorModalMsg.text(getErrorMessage(errRes));
-            $errorModal.modal();
-        },
-    });
-})
-- 
GitLab