From 1084bb3f3c14fd217b753e0bf17736374f4ffb95 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Sun, 14 Sep 2025 23:52:21 +0100 Subject: [PATCH] Delete blogspot articles --- src/Yavsc/Extensions/HostingExtensions.cs | 48 ++--------------------- src/Yavsc/Extensions/PermissionHandler.cs | 11 +++--- 2 files changed, 10 insertions(+), 49 deletions(-) diff --git a/src/Yavsc/Extensions/HostingExtensions.cs b/src/Yavsc/Extensions/HostingExtensions.cs index 0ba1e21b..b0f3f63f 100644 --- a/src/Yavsc/Extensions/HostingExtensions.cs +++ b/src/Yavsc/Extensions/HostingExtensions.cs @@ -37,6 +37,7 @@ using Npgsql; using System.Reflection; using IdentityServer8.EntityFramework.DbContexts; using IdentityServer8.EntityFramework.Mappers; +using System.IdentityModel.Tokens.Jwt; namespace Yavsc.Extensions; @@ -340,7 +341,7 @@ public static class HostingExtensions AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); - + JwtSecurityTokenHandler.DefaultMapInboundClaims = true; if (app.Environment.IsDevelopment()) { // to fix Home/Error app.UseDeveloperExceptionPage(); @@ -349,18 +350,7 @@ public static class HostingExtensions else { app.UseExceptionHandler("/Home/Error"); - try - { - using (var scope = app.Services.CreateScope()) - { - var db = scope.ServiceProvider.GetRequiredService(); - await db.Database.MigrateAsync(); - } - } - catch (Exception ex) - { - logger.LogError("Error migrating the database : {0}", ex); - } + app.InitializeDatabase(); } app.Use(async (context, next) => @@ -399,7 +389,6 @@ public static class HostingExtensions payPalSettings, googleAuthSettings, localization, loggerFactory, app.Environment.EnvironmentName); app.ConfigureFileServerApp(); - app.InitializeDatabase(); return app; } private static void InitializeDatabase(this IApplicationBuilder app) @@ -412,37 +401,8 @@ public static class HostingExtensions try { - - context.Database.Migrate(); - - if (!context.Clients.Any()) - { - foreach (var client in Config.Clients) - { - context.Clients.Add(client.ToEntity()); - } - context.SaveChanges(); - } - - if (!context.IdentityResources.Any()) - { - foreach (var resource in Config.IdentityResources) - { - context.IdentityResources.Add(resource.ToEntity()); - } - context.SaveChanges(); - } - - if (!context.ApiScopes.Any()) - { - foreach (var resource in Config.ApiScopes) - { - context.ApiScopes.Add(resource.ToEntity()); - } - context.SaveChanges(); - } - } + } catch (InvalidOperationException ex) { app.Properties["DegradedDBContext"] = ex.Message; diff --git a/src/Yavsc/Extensions/PermissionHandler.cs b/src/Yavsc/Extensions/PermissionHandler.cs index b669e1b9..7e4e7a3f 100644 --- a/src/Yavsc/Extensions/PermissionHandler.cs +++ b/src/Yavsc/Extensions/PermissionHandler.cs @@ -69,14 +69,15 @@ public class PermissionHandler : IAuthorizationHandler else if (resource is DefaultHttpContext httpContext) { - if (httpContext.Request.Path.StartsWithSegments("/blogpost/Delete", StringComparison.OrdinalIgnoreCase)) + if (httpContext.Request.Path.StartsWithSegments( + "/Blogspot/Delete", + StringComparison.OrdinalIgnoreCase)) { - string postId = (string)httpContext.GetRouteValue("id"); + string postId = (string) httpContext.GetRouteValue("id"); if (long.TryParse(postId, out long id)) { - BlogPost b = applicationDbContext.BlogSpot.FirstOrDefault(b => b.Id == id && b.AuthorId == user.GetUserId()); - return b != null; - + BlogPost b = applicationDbContext.BlogSpot.FirstOrDefault(b => b.Id == id && b.AuthorId == user.GetUserId()); + return b != null; } } }