Delete blogspot articles
This commit is contained in:
parent
b8446682e6
commit
4e92afb496
2 changed files with 10 additions and 49 deletions
|
|
@ -37,6 +37,7 @@ using Npgsql;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using IdentityServer8.EntityFramework.DbContexts;
|
using IdentityServer8.EntityFramework.DbContexts;
|
||||||
using IdentityServer8.EntityFramework.Mappers;
|
using IdentityServer8.EntityFramework.Mappers;
|
||||||
|
using System.IdentityModel.Tokens.Jwt;
|
||||||
|
|
||||||
namespace Yavsc.Extensions;
|
namespace Yavsc.Extensions;
|
||||||
|
|
||||||
|
|
@ -340,7 +341,7 @@ public static class HostingExtensions
|
||||||
|
|
||||||
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
|
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
|
||||||
|
|
||||||
|
JwtSecurityTokenHandler.DefaultMapInboundClaims = true;
|
||||||
if (app.Environment.IsDevelopment())
|
if (app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
// to fix Home/Error app.UseDeveloperExceptionPage();
|
// to fix Home/Error app.UseDeveloperExceptionPage();
|
||||||
|
|
@ -349,18 +350,7 @@ public static class HostingExtensions
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
app.UseExceptionHandler("/Home/Error");
|
app.UseExceptionHandler("/Home/Error");
|
||||||
try
|
app.InitializeDatabase();
|
||||||
{
|
|
||||||
using (var scope = app.Services.CreateScope())
|
|
||||||
{
|
|
||||||
var db = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
|
|
||||||
await db.Database.MigrateAsync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
logger.LogError("Error migrating the database : {0}", ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Use(async (context, next) =>
|
app.Use(async (context, next) =>
|
||||||
|
|
@ -399,7 +389,6 @@ public static class HostingExtensions
|
||||||
payPalSettings, googleAuthSettings, localization, loggerFactory,
|
payPalSettings, googleAuthSettings, localization, loggerFactory,
|
||||||
app.Environment.EnvironmentName);
|
app.Environment.EnvironmentName);
|
||||||
app.ConfigureFileServerApp();
|
app.ConfigureFileServerApp();
|
||||||
app.InitializeDatabase();
|
|
||||||
return app;
|
return app;
|
||||||
}
|
}
|
||||||
private static void InitializeDatabase(this IApplicationBuilder app)
|
private static void InitializeDatabase(this IApplicationBuilder app)
|
||||||
|
|
@ -412,37 +401,8 @@ public static class HostingExtensions
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
context.Database.Migrate();
|
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)
|
catch (InvalidOperationException ex)
|
||||||
{
|
{
|
||||||
app.Properties["DegradedDBContext"] = ex.Message;
|
app.Properties["DegradedDBContext"] = ex.Message;
|
||||||
|
|
|
||||||
|
|
@ -69,14 +69,15 @@ public class PermissionHandler : IAuthorizationHandler
|
||||||
else
|
else
|
||||||
if (resource is DefaultHttpContext httpContext)
|
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))
|
if (long.TryParse(postId, out long id))
|
||||||
{
|
{
|
||||||
BlogPost b = applicationDbContext.BlogSpot.FirstOrDefault(b => b.Id == id && b.AuthorId == user.GetUserId());
|
BlogPost b = applicationDbContext.BlogSpot.FirstOrDefault(b => b.Id == id && b.AuthorId == user.GetUserId());
|
||||||
return b != null;
|
return b != null;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue