Compare commits

...

4 commits

11 changed files with 948 additions and 28 deletions

View file

@ -6,7 +6,7 @@
@if (ShowCloseButton) {
<form method="dialog">
<!-- 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>
}
</div>

View file

@ -12,6 +12,27 @@
<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">
<Action Context="article">
<form method="post" @formname="@article.Id.ToString()" @onsubmit="Restore" class="w-full">
@ -25,6 +46,7 @@
@code {
[CascadingParameter(Name = "TitlePostfix")]
private string TitlePostfix { get; set; } = default!;
private static string ModalId => "ConfirmDeleteDialog";
private List<Article> Articles { get; } = [];
@ -55,4 +77,15 @@
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);
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)
.OrderByDescending(a => a.DistributionDateTime)
.Take(3)

View file

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

View file

@ -74,8 +74,8 @@ public class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options
category.HasMany(c => c.Articles).WithMany(a => a.Categories)
.UsingEntity<ArticleCategory>(
ac => ac.HasOne(a => a.Article).WithMany().OnDelete(DeleteBehavior.NoAction),
ac => ac.HasOne(a => a.Category).WithMany().OnDelete(DeleteBehavior.NoAction),
ac => ac.HasOne(a => a.Article).WithMany().OnDelete(DeleteBehavior.Cascade),
ac => ac.HasOne(a => a.Category).WithMany().OnDelete(DeleteBehavior.Restrict),
articleCategory => {
articleCategory.HasKey(ac => ac.Id);
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 =>
{
b1.Property<Guid>("ArticleId")
.HasColumnType("uuid");
b1.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
@ -646,6 +643,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b1.Property<Guid?>("ArticleId")
.HasColumnType("uuid");
b1.Property<string>("Label")
.IsRequired()
.HasMaxLength(128)
@ -654,7 +654,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b1.Property<int>("Order")
.HasColumnType("integer");
b1.HasKey("ArticleId", "Id");
b1.HasKey("Id");
b1.HasIndex("ArticleId");
b1.ToTable("ArticleHeading");
@ -674,13 +676,13 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.HasOne("Wave.Data.Article", "Article")
.WithMany()
.HasForeignKey("ArticleId")
.OnDelete(DeleteBehavior.NoAction)
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Wave.Data.Category", "Category")
.WithMany()
.HasForeignKey("CategoryId")
.OnDelete(DeleteBehavior.NoAction)
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("Article");

View file

@ -104,4 +104,16 @@
<data name="Restore_Submit" xml:space="preserve">
<value>Artikel Wiederherstellen</value>
</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>

View file

@ -104,4 +104,16 @@
<data name="Restore_Submit" xml:space="preserve">
<value>Restore Article</value>
</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>