Skip to content
Snippets Groups Projects
Verified Commit 2de4d1a6 authored by Gabriel Zachmann's avatar Gabriel Zachmann
Browse files

fix some code smells

parent 75727537
No related branches found
No related tags found
No related merge requests found
Pipeline #370836 passed
......@@ -39,6 +39,8 @@ import (
"github.com/oidc-mytoken/server/internal/utils/logger"
)
var calendarNotFoundError = model.NotFoundErrorResponse("calendar not found")
// HandleGetICS returns a calendar ics by its id
func HandleGetICS(ctx *fiber.Ctx) error {
rlog := logger.GetRequestLogger(ctx)
......@@ -80,7 +82,7 @@ func HandleGetICS(ctx *fiber.Ctx) error {
if e != nil {
return model.ErrorToInternalServerErrorResponse(err).Send(ctx)
}
return model.NotFoundErrorResponse("calendar not found").Send(ctx)
return calendarNotFoundError.Send(ctx)
}
ctx.Set(fiber.HeaderContentType, "text/calendar")
ctx.Set(fiber.HeaderContentDisposition, fmt.Sprintf(`attachment; filename="%s"`, info.Name))
......@@ -247,7 +249,7 @@ func HandleGet(ctx *fiber.Ctx) error {
if e != nil {
return model.ErrorToInternalServerErrorResponse(err).Send(ctx)
}
return model.NotFoundErrorResponse("calendar not found").Send(ctx)
return calendarNotFoundError.Send(ctx)
}
return ctx.Redirect(info.ICSPath)
}
......@@ -472,7 +474,7 @@ func HandleAddMytoken(ctx *fiber.Ctx) error {
if e != nil {
res = model.ErrorToInternalServerErrorResponse(err)
}
res = model.NotFoundErrorResponse("calendar not found")
res = calendarNotFoundError
return err
}
if err = calendarrepo.AddMytokenToCalendar(rlog, tx, id, info.ID); err != nil {
......
......@@ -31,13 +31,16 @@ import (
"github.com/oidc-mytoken/server/internal/utils/logger"
)
var managementCodeNotValidError = model.NotFoundErrorResponse("management_code not valid")
var missingManagementCodeError = model.BadRequestErrorResponse("missing management_code")
// HandleGetByManagementCode returns the api.NotificationInfo for the notification linked to a management code
func HandleGetByManagementCode(ctx *fiber.Ctx) error {
rlog := logger.GetRequestLogger(ctx)
rlog.Debug("Handle notification get request for management code")
managementCode := ctx.Params("code")
if managementCode == "" {
return model.BadRequestErrorResponse("missing management_code").Send(ctx)
return missingManagementCodeError.Send(ctx)
}
var res *model.Response
......@@ -49,7 +52,7 @@ func HandleGetByManagementCode(ctx *fiber.Ctx) error {
return err
}
if info == nil {
res = model.NotFoundErrorResponse("management_code not valid")
res = managementCodeNotValidError
return errors.New("dummy")
}
res = &model.Response{
......@@ -68,7 +71,7 @@ func HandleDeleteByManagementCode(ctx *fiber.Ctx) error {
rlog.Debug("Handle notification get request for management code")
managementCode := ctx.Params("code")
if managementCode == "" {
return model.BadRequestErrorResponse("missing management_code").Send(ctx)
return missingManagementCodeError.Send(ctx)
}
err := notificationsrepo.Delete(rlog, nil, managementCode)
......@@ -284,7 +287,7 @@ func HandleNotificationUpdateClasses(ctx *fiber.Ctx) error {
rlog.Debug("Handle notification update classes request")
managementCode := ctx.Params("code")
if managementCode == "" {
return model.BadRequestErrorResponse("missing management_code").Send(ctx)
return missingManagementCodeError.Send(ctx)
}
var req api.NotificationUpdateNotificationClassesRequest
if err := ctx.BodyParser(&req); err != nil {
......@@ -298,7 +301,7 @@ func HandleNotificationUpdateClasses(ctx *fiber.Ctx) error {
return err
}
if info == nil {
res = model.NotFoundErrorResponse("management_code not valid")
res = managementCodeNotValidError
return nil
}
return notificationsrepo.UpdateNotificationClasses(rlog, tx, info.NotificationID, req.Classes)
......@@ -319,7 +322,7 @@ func HandleNotificationAddToken(ctx *fiber.Ctx) error {
rlog.Debug("Handle notification add token request")
managementCode := ctx.Params("code")
if managementCode == "" {
return model.BadRequestErrorResponse("missing management_code").Send(ctx)
return missingManagementCodeError.Send(ctx)
}
var req pkg.NotificationAddTokenRequest
if err := ctx.BodyParser(&req); err != nil {
......@@ -342,7 +345,7 @@ func HandleNotificationAddToken(ctx *fiber.Ctx) error {
return err
}
if info == nil {
res = model.NotFoundErrorResponse("management_code not valid")
res = managementCodeNotValidError
return nil
}
return notificationsrepo.AddTokenToNotification(rlog, tx, info.NotificationID, mtID, req.IncludeChildren)
......@@ -363,7 +366,7 @@ func HandleNotificationRemoveToken(ctx *fiber.Ctx) error {
rlog.Debug("Handle notification remove token request")
managementCode := ctx.Params("code")
if managementCode == "" {
return model.BadRequestErrorResponse("missing management_code").Send(ctx)
return missingManagementCodeError.Send(ctx)
}
var req pkg.NotificationRemoveTokenRequest
if err := ctx.BodyParser(&req); err != nil {
......@@ -386,7 +389,7 @@ func HandleNotificationRemoveToken(ctx *fiber.Ctx) error {
return err
}
if info == nil {
res = model.NotFoundErrorResponse("management_code not valid")
res = managementCodeNotValidError
return nil
}
return notificationsrepo.RemoveTokenFromNotification(rlog, tx, info.NotificationID, mtID)
......
......@@ -72,7 +72,9 @@ func HandleDeleteSSHKey(ctx *fiber.Ctx) error {
rlog.Trace("Parsed delete ssh key request")
if req.SSHKeyFingerprint == "" {
if req.SSHKey == "" {
return model.BadRequestErrorResponse("One of the required parameters 'ssh_key' or 'ssh_key_hash' must be given").Send(ctx)
return model.BadRequestErrorResponse(
"One of the required parameters 'ssh_key' or 'ssh_key_hash' must be given",
).Send(ctx)
}
sshKey, _, _, _, err := gossh.ParseAuthorizedKey([]byte(req.SSHKey))
if err != nil {
......
......@@ -21,7 +21,7 @@ $(document).ready(function () {
eventDidMount: function (info) {
let title = info.event.extendedProps.description;
title = title.replaceAll('\n', ' <br/> ');
title = title.replace(/(https?\:\/\/)\S+/g, function (matched) {
title = title.replace(/(https?:\/\/)\S+/g, function (matched) {
return `<a href="${matched}" target="_blank" rel="noopener noreferrer">${matched}</a>`;
});
info.event.setProp('url', '');
......
......@@ -245,7 +245,7 @@ function _notificationAddAllTokenList($container, hide_tokens = undefined) {
}
function toggleIncludeChildren() {
$input = $(this).find('input.include-children-switch');
let $input = $(this).find('input.include-children-switch');
if ($input.prop("disabled")) {
return;
}
......@@ -449,12 +449,10 @@ function fillNotificationInfo(notifications, notificationsSet, prefix = "") {
toggle_subscribe_notification_content(prefix);
}
$(`.${prefix}toggle-subscribe-notification-content-btn`).hideB();
} else if ($(prefixId('subscribe-mail-new', prefix)).hasClass("d-none")) {
$(prefixId("switch-to-new-mail-notification-btn", prefix)).showB();
} else {
if ($(prefixId('subscribe-mail-new', prefix)).hasClass("d-none")) {
$(prefixId("switch-to-new-mail-notification-btn", prefix)).showB();
} else {
$(prefixId("switch-to-existing-mail-notification-btn", prefix)).showB();
}
$(prefixId("switch-to-existing-mail-notification-btn", prefix)).showB();
}
$('[data-toggle="tooltip"]').tooltip();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment