Compare commits

...

4 commits

11 changed files with 948 additions and 28 deletions

View file

@ -6,7 +6,7 @@
@if (ShowCloseButton) { @if (ShowCloseButton) {
<form method="dialog"> <form method="dialog">
<!-- if there is a button in form, it will close the modal --> <!-- if there is a button in form, it will close the modal -->
<button class="btn" type="submit">Close</button> <button class="btn" type="submit" autofocus>Close</button>
</form> </form>
} }
</div> </div>

View file

@ -12,6 +12,27 @@
<h1 class="text-3xl lg:text-5xl font-light mb-6 text-primary">@Localizer["Title"]</h1> <h1 class="text-3xl lg:text-5xl font-light mb-6 text-primary">@Localizer["Title"]</h1>
<ModalComponent Id="@ModalId">
<ChildContent>
<form method="post" id="ConfirmDelete" @formname="ConfirmDelete" @onsubmit="DeleteAll">
<AntiforgeryToken />
<h2 class="text-xl">@Localizer["Confirm_Title"]</h2>
<p class="my-3">@Localizer["Confirm_Description"]</p>
</form>
</ChildContent>
<Actions>
<button type="submit" form="ConfirmDelete" class="btn btn-error">
@Localizer["Confirm_Submit"]
</button>
</Actions>
</ModalComponent>
<div class="flex gap-2 mb-3">
<button class="btn btn-sm btn-error" onclick="@(ModalId).showModal()">
@Localizer["Delete_Label"]
</button>
</div>
<ArticleCardList Articles="Articles" HasArticleLink="false"> <ArticleCardList Articles="Articles" HasArticleLink="false">
<Action Context="article"> <Action Context="article">
<form method="post" @formname="@article.Id.ToString()" @onsubmit="Restore" class="w-full"> <form method="post" @formname="@article.Id.ToString()" @onsubmit="Restore" class="w-full">
@ -25,6 +46,7 @@
@code { @code {
[CascadingParameter(Name = "TitlePostfix")] [CascadingParameter(Name = "TitlePostfix")]
private string TitlePostfix { get; set; } = default!; private string TitlePostfix { get; set; } = default!;
private static string ModalId => "ConfirmDeleteDialog";
private List<Article> Articles { get; } = []; private List<Article> Articles { get; } = [];
@ -55,4 +77,15 @@
Articles.RemoveAt(Articles.FindIndex(a => a.Id == article.Id)); Articles.RemoveAt(Articles.FindIndex(a => a.Id == article.Id));
} }
private async Task DeleteAll() {
await using var context = await ContextFactory.CreateDbContextAsync();
context.RemoveRange(await context.Set<Article>()
.IgnoreQueryFilters().IgnoreAutoIncludes()
.Where(a => a.IsDeleted)
.ToListAsync());
await context.SaveChangesAsync();
Articles.Clear();
}
} }

View file

@ -80,7 +80,7 @@
await Email.ClearToken(Id, Token); await Email.ClearToken(Id, Token);
var articles = await context.Set<EmailNewsletter>() var articles = await context.Set<EmailNewsletter>()
.IgnoreAutoIncludes().IgnoreQueryFilters().Where(n => n.IsSend) .IgnoreAutoIncludes().IgnoreQueryFilters().Where(n => n.IsSend && !n.Article.IsDeleted)
.Include(a => a.Article).ThenInclude(a => a.Author) .Include(a => a.Article).ThenInclude(a => a.Author)
.OrderByDescending(a => a.DistributionDateTime) .OrderByDescending(a => a.DistributionDateTime)
.Take(3) .Take(3)

View file

@ -15,16 +15,15 @@ public class WebhookController(ILogger<WebhookController> logger, ApplicationDbC
[HttpPost("mailtrap/{apiKey}")] [HttpPost("mailtrap/{apiKey}")]
[Authorize("EmailApi", AuthenticationSchemes = "ApiKeyInRoute")] [Authorize("EmailApi", AuthenticationSchemes = "ApiKeyInRoute")]
public async Task<IActionResult> Mailtrap(Webhook webhook, string apiKey) { public async Task<IActionResult> Mailtrap(Webhook webhook, string apiKey) {
logger.LogDebug("Start processing webhook events");
foreach (var webhookEvent in webhook.Events) { foreach (var webhookEvent in webhook.Events) {
metrics.WebhookEventReceived("Mailtrap", webhookEvent.Type.ToString()); metrics.WebhookEventReceived("Mailtrap", webhookEvent.Type.ToString());
var subscriber = await context.Set<EmailSubscriber>().FirstOrDefaultAsync(s => s.Email == webhookEvent.Email); var subscriber = await context.Set<EmailSubscriber>().FirstOrDefaultAsync(s => s.Email == webhookEvent.Email);
logger.LogDebug("Received Webhook event {EventType} for {email}", logger.LogDebug("Received {WebhookEvent} event for {email}", webhookEvent.Type, webhookEvent.Email);
webhookEvent.Type, webhookEvent.Email);
if (subscriber is null) { if (subscriber is null) {
logger.LogWarning( logger.LogWarning(
"Received webhook event from mailtrap of type {EventType}, " + "Received {WebhookEvent} from Mailtrap " +
"but failed to find subscriber with E-Mail {email}.", "but failed to find subscriber with E-Mail {email}.",
webhookEvent.Type, webhookEvent.Email); webhookEvent.Type, webhookEvent.Email);
metrics.WebhookEventError("Mailtrap", webhookEvent.Type.ToString(), "unknown email"); metrics.WebhookEventError("Mailtrap", webhookEvent.Type.ToString(), "unknown email");
@ -39,38 +38,38 @@ public class WebhookController(ILogger<WebhookController> logger, ApplicationDbC
case WebhookEventType.Open: case WebhookEventType.Open:
subscriber.LastMailOpened = webhookEvent.EventDateTime; subscriber.LastMailOpened = webhookEvent.EventDateTime;
break; break;
case WebhookEventType.Bounce: case WebhookEventType.SoftBounce:
// Store this message in case it develops into a suspension subscriber.UnsubscribeReason = webhookEvent.Response ?? webhookEvent.Type.Humanize(LetterCasing.Title);
subscriber.UnsubscribeReason = webhookEvent.Response;
break; break;
case WebhookEventType.Suspension: case WebhookEventType.Suspension:
subscriber.Unsubscribed = true; logger.LogWarning(
subscriber.UnsubscribeReason ??= "unknown"; "Received Suspension event, you may have send from an unverified domain or exceeded your hourly rate.");
break; continue;
case WebhookEventType.Unsubscribe: case WebhookEventType.Unsubscribe:
subscriber.Unsubscribed = true; subscriber.Unsubscribed = true;
subscriber.UnsubscribeReason ??= "User Unsubscribed"; subscriber.UnsubscribeReason = "User Unsubscribed";
break; break;
case WebhookEventType.SpamComplaint: case WebhookEventType.SpamComplaint:
subscriber.Unsubscribed = true; subscriber.Unsubscribed = true;
subscriber.UnsubscribeReason ??= "User reported as Spam"; subscriber.UnsubscribeReason = "User reported as Spam";
break; break;
case WebhookEventType.Bounce:
case WebhookEventType.Reject: case WebhookEventType.Reject:
subscriber.Unsubscribed = true; subscriber.Unsubscribed = true;
subscriber.UnsubscribeReason ??= webhookEvent.Reason?.Humanize().Titleize() ?? "Rejected"; subscriber.UnsubscribeReason = webhookEvent.Reason ?? webhookEvent.Type.Humanize(LetterCasing.Title);
break; break;
case WebhookEventType.SoftBounce:
case WebhookEventType.Click: case WebhookEventType.Click:
default: default:
logger.LogInformation("Received unsupported event {EventType} for {email}. Skipping.", webhookEvent.Type, webhookEvent.Email); logger.LogInformation("Received unsupported event {EventType} for {email}. Skipping.", webhookEvent.Type, webhookEvent.Email);
metrics.WebhookEventError("Mailtrap", webhookEvent.Type.ToString(), "unknown type"); metrics.WebhookEventError("Mailtrap", webhookEvent.Type.ToString(), "unknown type");
return Ok(); continue;
} }
await context.SaveChangesAsync();
logger.LogDebug("Webhook event {EventType} for {email} processed successfully.", logger.LogDebug("Webhook event {EventType} for {email} processed successfully.",
webhookEvent.Type, webhookEvent.Email); webhookEvent.Type, webhookEvent.Email);
} }
await context.SaveChangesAsync();
logger.LogDebug("All webhook events processed and saved");
return Ok(); return Ok();

View file

@ -1,14 +1,18 @@
using System.Text.Json.Serialization; using System.Runtime.Serialization;
using System.Text.Json.Serialization;
namespace Wave.Data.Api.Mailtrap; namespace Wave.Data.Api.Mailtrap;
[JsonConverter(typeof(JsonStringEnumConverter<WebhookEventType>))]
public enum WebhookEventType { public enum WebhookEventType {
Delivery, Delivery,
[EnumMember(Value = "soft bounce")]
SoftBounce, SoftBounce,
Bounce, Bounce,
Suspension, Suspension,
Unsubscribe, Unsubscribe,
Open, Open,
[EnumMember(Value = "spam complaint")]
SpamComplaint, SpamComplaint,
Click, Click,
Reject Reject
@ -34,7 +38,7 @@ public record WebhookEvent(
[property:JsonPropertyName("response_code")] [property:JsonPropertyName("response_code")]
int? ResponseCode) { int? ResponseCode) {
public WebhookEventType Type => Enum.Parse<WebhookEventType>(EventTypeString.Replace("_", ""), true); public WebhookEventType Type => Enum.Parse<WebhookEventType>(EventTypeString.Replace("_", "").Replace(" ", ""), true);
public DateTimeOffset EventDateTime => DateTimeOffset.FromUnixTimeSeconds(Timestamp); public DateTimeOffset EventDateTime => DateTimeOffset.FromUnixTimeSeconds(Timestamp);
} }

View file

@ -74,8 +74,8 @@ public class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options
category.HasMany(c => c.Articles).WithMany(a => a.Categories) category.HasMany(c => c.Articles).WithMany(a => a.Categories)
.UsingEntity<ArticleCategory>( .UsingEntity<ArticleCategory>(
ac => ac.HasOne(a => a.Article).WithMany().OnDelete(DeleteBehavior.NoAction), ac => ac.HasOne(a => a.Article).WithMany().OnDelete(DeleteBehavior.Cascade),
ac => ac.HasOne(a => a.Category).WithMany().OnDelete(DeleteBehavior.NoAction), ac => ac.HasOne(a => a.Category).WithMany().OnDelete(DeleteBehavior.Restrict),
articleCategory => { articleCategory => {
articleCategory.HasKey(ac => ac.Id); articleCategory.HasKey(ac => ac.Id);
articleCategory.ToTable("ArticleCategories"); articleCategory.ToTable("ArticleCategories");

View file

@ -0,0 +1,752 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
using Wave.Data;
#nullable disable
namespace Wave.Data.Migrations.postgres
{
[DbContext(typeof(ApplicationDbContext))]
[Migration("20240604123612_HardDeleteArticles")]
partial class HardDeleteArticles
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Npgsql:CollationDefinition:default-case-insensitive", "und-u-kf-upper-ks-level1,und-u-kf-upper-ks-level1,icu,False")
.HasAnnotation("ProductVersion", "8.0.0")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedName")
.IsUnique()
.HasDatabaseName("RoleNameIndex");
b.ToTable("AspNetRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("RoleId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text");
b.Property<string>("ClaimValue")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("ProviderKey")
.HasColumnType("text");
b.Property<string>("ProviderDisplayName")
.HasColumnType("text");
b.Property<string>("UserId")
.IsRequired()
.HasColumnType("text");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("RoleId")
.HasColumnType("text");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles", (string)null);
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.Property<string>("UserId")
.HasColumnType("text");
b.Property<string>("LoginProvider")
.HasColumnType("text");
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Value")
.HasColumnType("text");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens", (string)null);
});
modelBuilder.Entity("Wave.Data.ApiClaim", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ApiKeyKey")
.HasColumnType("character varying(128)");
b.Property<string>("Type")
.IsRequired()
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b.Property<string>("Value")
.IsRequired()
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b.HasKey("Id");
b.HasIndex("ApiKeyKey");
b.ToTable("ApiClaim");
});
modelBuilder.Entity("Wave.Data.ApiKey", b =>
{
b.Property<string>("Key")
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b.Property<string>("OwnerName")
.IsRequired()
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b.HasKey("Key");
b.ToTable("ApiKey");
});
modelBuilder.Entity("Wave.Data.ApplicationUser", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<string>("AboutTheAuthor")
.IsRequired()
.HasMaxLength(512)
.HasColumnType("character varying(512)");
b.Property<int>("AccessFailedCount")
.HasColumnType("integer");
b.Property<string>("Biography")
.IsRequired()
.HasMaxLength(4096)
.HasColumnType("character varying(4096)");
b.Property<string>("BiographyHtml")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text");
b.Property<string>("ContactEmail")
.IsRequired()
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b.Property<string>("ContactPhone")
.IsRequired()
.HasMaxLength(64)
.HasColumnType("character varying(64)");
b.Property<string>("ContactPhoneBusiness")
.IsRequired()
.HasMaxLength(64)
.HasColumnType("character varying(64)");
b.Property<string>("ContactWebsite")
.IsRequired()
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<bool>("EmailConfirmed")
.HasColumnType("boolean");
b.Property<string>("FullName")
.HasMaxLength(64)
.HasColumnType("character varying(64)");
b.Property<bool>("LockoutEnabled")
.HasColumnType("boolean");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("timestamp with time zone");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<string>("PasswordHash")
.HasColumnType("text");
b.Property<string>("PhoneNumber")
.HasColumnType("text");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("boolean");
b.Property<string>("SecurityStamp")
.HasColumnType("text");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("boolean");
b.Property<string>("UserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("NormalizedEmail")
.HasDatabaseName("EmailIndex");
b.HasIndex("NormalizedUserName")
.IsUnique()
.HasDatabaseName("UserNameIndex");
b.ToTable("AspNetUsers", (string)null);
});
modelBuilder.Entity("Wave.Data.Article", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("AuthorId")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Body")
.IsRequired()
.HasColumnType("text");
b.Property<string>("BodyHtml")
.IsRequired()
.HasColumnType("text");
b.Property<string>("BodyPlain")
.IsRequired()
.ValueGeneratedOnAdd()
.HasColumnType("text")
.HasDefaultValue("");
b.Property<bool>("CanBePublic")
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("boolean")
.HasComputedColumnSql("\"IsDeleted\" = false AND \"Status\" = 2", true);
b.Property<DateTimeOffset>("CreationDate")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasDefaultValueSql("now()");
b.Property<bool>("IsDeleted")
.HasColumnType("boolean");
b.Property<DateTimeOffset>("LastModified")
.ValueGeneratedOnAdd()
.HasColumnType("timestamp with time zone")
.HasDefaultValueSql("now()");
b.Property<DateTimeOffset>("PublishDate")
.HasColumnType("timestamp with time zone");
b.Property<string>("ReviewerId")
.HasColumnType("text");
b.Property<string>("Slug")
.IsRequired()
.ValueGeneratedOnAdd()
.HasMaxLength(64)
.HasColumnType("character varying(64)")
.HasDefaultValue("");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<string>("Title")
.IsRequired()
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.HasKey("Id");
b.HasIndex("AuthorId");
b.HasIndex("ReviewerId");
b.ToTable("Articles", (string)null);
});
modelBuilder.Entity("Wave.Data.ArticleCategory", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<Guid>("ArticleId")
.HasColumnType("uuid");
b.Property<Guid>("CategoryId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ArticleId");
b.HasIndex("CategoryId");
b.ToTable("ArticleCategories", (string)null);
});
modelBuilder.Entity("Wave.Data.ArticleImage", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<Guid?>("ArticleId")
.HasColumnType("uuid");
b.Property<string>("ImageDescription")
.IsRequired()
.HasMaxLength(2048)
.HasColumnType("character varying(2048)");
b.HasKey("Id");
b.HasIndex("ArticleId");
b.ToTable("Images", (string)null);
});
modelBuilder.Entity("Wave.Data.Category", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<int>("Color")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasDefaultValue(25);
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(128)
.HasColumnType("character varying(128)")
.UseCollation("default-case-insensitive");
b.HasKey("Id");
b.HasIndex("Name")
.IsUnique();
b.ToTable("Categories", (string)null);
});
modelBuilder.Entity("Wave.Data.EmailNewsletter", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<Guid>("ArticleId")
.HasColumnType("uuid");
b.Property<DateTimeOffset>("DistributionDateTime")
.HasColumnType("timestamp with time zone");
b.Property<bool>("IsSend")
.HasColumnType("boolean");
b.HasKey("Id");
b.HasIndex("ArticleId")
.IsUnique();
b.ToTable("Newsletter", (string)null);
});
modelBuilder.Entity("Wave.Data.EmailSubscriber", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Email")
.IsRequired()
.HasMaxLength(256)
.HasColumnType("character varying(256)")
.UseCollation("default-case-insensitive");
b.Property<string>("Language")
.IsRequired()
.ValueGeneratedOnAdd()
.HasMaxLength(8)
.HasColumnType("character varying(8)")
.HasDefaultValue("en-US");
b.Property<DateTimeOffset?>("LastMailOpened")
.HasColumnType("timestamp with time zone");
b.Property<DateTimeOffset?>("LastMailReceived")
.HasColumnType("timestamp with time zone");
b.Property<string>("Name")
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b.Property<string>("UnsubscribeReason")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<bool>("Unsubscribed")
.HasColumnType("boolean");
b.HasKey("Id");
b.HasIndex("Email")
.IsUnique();
b.HasIndex("Unsubscribed");
b.ToTable("NewsletterSubscribers", (string)null);
});
modelBuilder.Entity("Wave.Data.ProfilePicture", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ApplicationUserId")
.HasColumnType("text");
b.Property<Guid>("ImageId")
.HasColumnType("uuid");
b.HasKey("Id");
b.HasIndex("ApplicationUserId")
.IsUnique();
b.ToTable("ProfilePictures", (string)null);
});
modelBuilder.Entity("Wave.Data.UserLink", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ApplicationUserId")
.HasColumnType("text");
b.Property<string>("UrlString")
.IsRequired()
.HasMaxLength(1024)
.HasColumnType("character varying(1024)");
b.HasKey("Id");
b.HasIndex("ApplicationUserId");
b.ToTable("UserLink");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
{
b.HasOne("Wave.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
{
b.HasOne("Wave.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Wave.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
{
b.HasOne("Wave.Data.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Wave.Data.ApiClaim", b =>
{
b.HasOne("Wave.Data.ApiKey", null)
.WithMany("ApiClaims")
.HasForeignKey("ApiKeyKey")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Wave.Data.Article", b =>
{
b.HasOne("Wave.Data.ApplicationUser", "Author")
.WithMany("Articles")
.HasForeignKey("AuthorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Wave.Data.ApplicationUser", "Reviewer")
.WithMany()
.HasForeignKey("ReviewerId")
.OnDelete(DeleteBehavior.SetNull);
b.OwnsMany("Wave.Data.ArticleHeading", "Headings", b1 =>
{
b1.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b1.Property<int>("Id"));
b1.Property<string>("Anchor")
.IsRequired()
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b1.Property<Guid?>("ArticleId")
.HasColumnType("uuid");
b1.Property<string>("Label")
.IsRequired()
.HasMaxLength(128)
.HasColumnType("character varying(128)");
b1.Property<int>("Order")
.HasColumnType("integer");
b1.HasKey("Id");
b1.HasIndex("ArticleId");
b1.ToTable("ArticleHeading");
b1.WithOwner()
.HasForeignKey("ArticleId");
});
b.Navigation("Author");
b.Navigation("Headings");
b.Navigation("Reviewer");
});
modelBuilder.Entity("Wave.Data.ArticleCategory", b =>
{
b.HasOne("Wave.Data.Article", "Article")
.WithMany()
.HasForeignKey("ArticleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Wave.Data.Category", "Category")
.WithMany()
.HasForeignKey("CategoryId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("Article");
b.Navigation("Category");
});
modelBuilder.Entity("Wave.Data.ArticleImage", b =>
{
b.HasOne("Wave.Data.Article", null)
.WithMany("Images")
.HasForeignKey("ArticleId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Wave.Data.EmailNewsletter", b =>
{
b.HasOne("Wave.Data.Article", "Article")
.WithOne()
.HasForeignKey("Wave.Data.EmailNewsletter", "ArticleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Article");
});
modelBuilder.Entity("Wave.Data.ProfilePicture", b =>
{
b.HasOne("Wave.Data.ApplicationUser", null)
.WithOne("ProfilePicture")
.HasForeignKey("Wave.Data.ProfilePicture", "ApplicationUserId")
.OnDelete(DeleteBehavior.SetNull);
});
modelBuilder.Entity("Wave.Data.UserLink", b =>
{
b.HasOne("Wave.Data.ApplicationUser", null)
.WithMany("Links")
.HasForeignKey("ApplicationUserId")
.OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity("Wave.Data.ApiKey", b =>
{
b.Navigation("ApiClaims");
});
modelBuilder.Entity("Wave.Data.ApplicationUser", b =>
{
b.Navigation("Articles");
b.Navigation("Links");
b.Navigation("ProfilePicture");
});
modelBuilder.Entity("Wave.Data.Article", b =>
{
b.Navigation("Images");
});
#pragma warning restore 612, 618
}
}
}

View file

@ -0,0 +1,106 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Wave.Data.Migrations.postgres;
/// <inheritdoc />
public partial class HardDeleteArticles : Migration {
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder) {
migrationBuilder.DropForeignKey(
name: "FK_ArticleCategories_Articles_ArticleId",
table: "ArticleCategories");
migrationBuilder.DropForeignKey(
name: "FK_ArticleCategories_Categories_CategoryId",
table: "ArticleCategories");
migrationBuilder.DropPrimaryKey(
name: "PK_ArticleHeading",
table: "ArticleHeading");
migrationBuilder.AlterColumn<Guid>(
name: "ArticleId",
table: "ArticleHeading",
type: "uuid",
nullable: true,
oldClrType: typeof(Guid),
oldType: "uuid");
migrationBuilder.AddPrimaryKey(
name: "PK_ArticleHeading",
table: "ArticleHeading",
column: "Id");
migrationBuilder.CreateIndex(
name: "IX_ArticleHeading_ArticleId",
table: "ArticleHeading",
column: "ArticleId");
migrationBuilder.AddForeignKey(
name: "FK_ArticleCategories_Articles_ArticleId",
table: "ArticleCategories",
column: "ArticleId",
principalTable: "Articles",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_ArticleCategories_Categories_CategoryId",
table: "ArticleCategories",
column: "CategoryId",
principalTable: "Categories",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder) {
migrationBuilder.DropForeignKey(
name: "FK_ArticleCategories_Articles_ArticleId",
table: "ArticleCategories");
migrationBuilder.DropForeignKey(
name: "FK_ArticleCategories_Categories_CategoryId",
table: "ArticleCategories");
migrationBuilder.DropPrimaryKey(
name: "PK_ArticleHeading",
table: "ArticleHeading");
migrationBuilder.DropIndex(
name: "IX_ArticleHeading_ArticleId",
table: "ArticleHeading");
migrationBuilder.AlterColumn<Guid>(
name: "ArticleId",
table: "ArticleHeading",
type: "uuid",
nullable: false,
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"),
oldClrType: typeof(Guid),
oldType: "uuid",
oldNullable: true);
migrationBuilder.AddPrimaryKey(
name: "PK_ArticleHeading",
table: "ArticleHeading",
columns: new[] {"ArticleId", "Id"});
migrationBuilder.AddForeignKey(
name: "FK_ArticleCategories_Articles_ArticleId",
table: "ArticleCategories",
column: "ArticleId",
principalTable: "Articles",
principalColumn: "Id");
migrationBuilder.AddForeignKey(
name: "FK_ArticleCategories_Categories_CategoryId",
table: "ArticleCategories",
column: "CategoryId",
principalTable: "Categories",
principalColumn: "Id");
}
}

View file

@ -632,9 +632,6 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.OwnsMany("Wave.Data.ArticleHeading", "Headings", b1 => b.OwnsMany("Wave.Data.ArticleHeading", "Headings", b1 =>
{ {
b1.Property<Guid>("ArticleId")
.HasColumnType("uuid");
b1.Property<int>("Id") b1.Property<int>("Id")
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("integer"); .HasColumnType("integer");
@ -646,6 +643,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.HasMaxLength(256) .HasMaxLength(256)
.HasColumnType("character varying(256)"); .HasColumnType("character varying(256)");
b1.Property<Guid?>("ArticleId")
.HasColumnType("uuid");
b1.Property<string>("Label") b1.Property<string>("Label")
.IsRequired() .IsRequired()
.HasMaxLength(128) .HasMaxLength(128)
@ -654,7 +654,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b1.Property<int>("Order") b1.Property<int>("Order")
.HasColumnType("integer"); .HasColumnType("integer");
b1.HasKey("ArticleId", "Id"); b1.HasKey("Id");
b1.HasIndex("ArticleId");
b1.ToTable("ArticleHeading"); b1.ToTable("ArticleHeading");
@ -674,13 +676,13 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.HasOne("Wave.Data.Article", "Article") b.HasOne("Wave.Data.Article", "Article")
.WithMany() .WithMany()
.HasForeignKey("ArticleId") .HasForeignKey("ArticleId")
.OnDelete(DeleteBehavior.NoAction) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("Wave.Data.Category", "Category") b.HasOne("Wave.Data.Category", "Category")
.WithMany() .WithMany()
.HasForeignKey("CategoryId") .HasForeignKey("CategoryId")
.OnDelete(DeleteBehavior.NoAction) .OnDelete(DeleteBehavior.Restrict)
.IsRequired(); .IsRequired();
b.Navigation("Article"); b.Navigation("Article");

View file

@ -104,4 +104,16 @@
<data name="Restore_Submit" xml:space="preserve"> <data name="Restore_Submit" xml:space="preserve">
<value>Artikel Wiederherstellen</value> <value>Artikel Wiederherstellen</value>
</data> </data>
<data name="Delete_Label" xml:space="preserve">
<value>Artikel Löschen</value>
</data>
<data name="Confirm_Title" xml:space="preserve">
<value>Sind Sie sich sicher?</value>
</data>
<data name="Confirm_Submit" xml:space="preserve">
<value>Ja, Artikel unwiederruflich löschen</value>
</data>
<data name="Confirm_Description" xml:space="preserve">
<value>Diese Operation ist unwiederruflich</value>
</data>
</root> </root>

View file

@ -104,4 +104,16 @@
<data name="Restore_Submit" xml:space="preserve"> <data name="Restore_Submit" xml:space="preserve">
<value>Restore Article</value> <value>Restore Article</value>
</data> </data>
<data name="Delete_Label" xml:space="preserve">
<value>Delete Articles</value>
</data>
<data name="Confirm_Title" xml:space="preserve">
<value>Are you sure?</value>
</data>
<data name="Confirm_Description" xml:space="preserve">
<value>This action is irreversible.</value>
</data>
<data name="Confirm_Submit" xml:space="preserve">
<value>Yes, permanently delete articles</value>
</data>
</root> </root>