From e103738d3947c18f6c130f1c7d2946f9d7279177 Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Sun, 24 Jul 2022 19:26:36 -0400 Subject: [PATCH] Prevent deletion if theme is in use (#20) --- src/MyWebLog/Handlers/Admin.fs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/MyWebLog/Handlers/Admin.fs b/src/MyWebLog/Handlers/Admin.fs index 286b615..e8d8ceb 100644 --- a/src/MyWebLog/Handlers/Admin.fs +++ b/src/MyWebLog/Handlers/Admin.fs @@ -331,10 +331,17 @@ let saveTheme : HttpHandler = requireAccess Administrator >=> fun next ctx -> ta // POST /admin/theme/{id}/delete let deleteTheme themeId : HttpHandler = requireAccess Administrator >=> fun next ctx -> task { let data = ctx.Data - if themeId = "admin" || themeId = "default" then + match themeId with + | "admin" | "default" -> do! addMessage ctx { UserMessage.error with Message = $"You may not delete the {themeId} theme" } return! listThemes next ctx - else + | it when WebLogCache.isThemeInUse (ThemeId it) -> + do! addMessage ctx + { UserMessage.error with + Message = $"You may not delete the {themeId} theme, as it is currently in use" + } + return! listThemes next ctx + | _ -> match! data.Theme.Delete (ThemeId themeId) with | true -> let zippedTheme = $"{themeId}-theme.zip"