Website announcements fixes and additions (#818)

* Render line breaks in announcement content

* Track announcement publisher

* Change paragraph tag to a div for consistency

* Fix bottom padding for announcement content

* Track publisher user entity rather than just the username

* Potentially fix a migration failure

* Final code cleanup

* Fix linq statement chaining style

---------

Co-authored-by: Dagg <daggintosh@outlook.com>
This commit is contained in:
koko 2023-06-26 23:02:11 -04:00 committed by GitHub
parent 14ebad07f3
commit f965be88b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 96 additions and 11 deletions

View file

@ -37,11 +37,21 @@
@foreach (WebsiteAnnouncementEntity announcement in Model.Announcements) @foreach (WebsiteAnnouncementEntity announcement in Model.Announcements)
{ {
<div class="ui blue segment" style="position: relative;"> <div class="ui blue segment" style="position: relative;">
<h3>@announcement.Title</h3> <div>
<p style="white-space: initial;"> <h3>@announcement.Title</h3>
@announcement.Content <div style="padding-bottom: 2em;">
</p> <span style="white-space: pre-line; ">@announcement.Content</span>
</div>
@if (announcement.Publisher != null)
{
<div class="ui tiny bottom left attached label">
Posted by
<a style="color: black" href="~/user/@announcement.Publisher.UserId">
@announcement.Publisher.Username
</a>
</div>
}
</div>
@if (Model.User != null && Model.User.IsAdmin) @if (Model.User != null && Model.User.IsAdmin)
{ {
<form method="post"> <form method="post">
@ -57,7 +67,7 @@
</form> </form>
} }
</div> </div>
} }
} }
else else
{ {

View file

@ -22,6 +22,7 @@ public class AnnouncePage : BaseLayout
public async Task<IActionResult> OnGet() public async Task<IActionResult> OnGet()
{ {
this.Announcements = await this.Database.WebsiteAnnouncements this.Announcements = await this.Database.WebsiteAnnouncements
.Include(a => a.Publisher)
.OrderByDescending(a => a.AnnouncementId) .OrderByDescending(a => a.AnnouncementId)
.ToListAsync(); .ToListAsync();
@ -42,8 +43,9 @@ public class AnnouncePage : BaseLayout
WebsiteAnnouncementEntity announcement = new() WebsiteAnnouncementEntity announcement = new()
{ {
Title = title, Title = title.Trim(),
Content = content, Content = content.Trim(),
PublisherId = user.UserId,
}; };
await this.Database.WebsiteAnnouncements.AddAsync(announcement); await this.Database.WebsiteAnnouncements.AddAsync(announcement);
@ -55,8 +57,7 @@ public class AnnouncePage : BaseLayout
? content[..250] + $"... [read more]({ServerConfiguration.Instance.ExternalUrl}/announce)" ? content[..250] + $"... [read more]({ServerConfiguration.Instance.ExternalUrl}/announce)"
: content; : content;
await WebhookHelper.SendWebhook($":mega: {title}", await WebhookHelper.SendWebhook($":mega: {title}", truncatedAnnouncement);
truncatedAnnouncement);
} }
return this.RedirectToPage(); return this.RedirectToPage();

View file

@ -0,0 +1,49 @@
using LBPUnion.ProjectLighthouse.Database;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ProjectLighthouse.Migrations
{
[DbContext(typeof(DatabaseContext))]
[Migration("20230624203015_AddPostedByToWebAnnouncements")]
public partial class AddPostedByToWebAnnouncements : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "PublisherId",
table: "WebsiteAnnouncements",
type: "int",
nullable: true);
migrationBuilder.CreateIndex(
name: "IX_WebsiteAnnouncements_PublisherId",
table: "WebsiteAnnouncements",
column: "PublisherId");
migrationBuilder.AddForeignKey(
name: "FK_WebsiteAnnouncements_Users_PublisherId",
table: "WebsiteAnnouncements",
column: "PublisherId",
principalTable: "Users",
principalColumn: "UserId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_WebsiteAnnouncements_Users_PublisherId",
table: "WebsiteAnnouncements");
migrationBuilder.DropIndex(
name: "IX_WebsiteAnnouncements_PublisherId",
table: "WebsiteAnnouncements");
migrationBuilder.DropColumn(
name: "PublisherId",
table: "WebsiteAnnouncements");
}
}
}

View file

@ -1033,10 +1033,15 @@ namespace ProjectLighthouse.Migrations
b.Property<string>("Content") b.Property<string>("Content")
.HasColumnType("longtext"); .HasColumnType("longtext");
b.Property<int?>("PublisherId")
.HasColumnType("int");
b.Property<string>("Title") b.Property<string>("Title")
.HasColumnType("longtext"); .HasColumnType("longtext");
b.HasKey("Identifier"); b.HasKey("AnnouncementId");
b.HasIndex("PublisherId");
b.ToTable("WebsiteAnnouncements"); b.ToTable("WebsiteAnnouncements");
}); });
@ -1394,6 +1399,15 @@ namespace ProjectLighthouse.Migrations
b.Navigation("User"); b.Navigation("User");
}); });
modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Entities.Website.WebsiteAnnouncementEntity", b =>
{
b.HasOne("LBPUnion.ProjectLighthouse.Types.Entities.Profile.UserEntity", "Publisher")
.WithMany()
.HasForeignKey("PublisherId");
b.Navigation("Publisher");
});
modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Entities.Profile.PhotoEntity", b => modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Entities.Profile.PhotoEntity", b =>
{ {
b.Navigation("PhotoSubjects"); b.Navigation("PhotoSubjects");

View file

@ -1,4 +1,6 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
namespace LBPUnion.ProjectLighthouse.Types.Entities.Website; namespace LBPUnion.ProjectLighthouse.Types.Entities.Website;
@ -10,4 +12,13 @@ public class WebsiteAnnouncementEntity
public string Title { get; set; } public string Title { get; set; }
public string Content { get; set; } public string Content { get; set; }
#nullable enable
public int? PublisherId { get; set; }
[ForeignKey(nameof(PublisherId))]
public UserEntity? Publisher { get; set; }
#nullable disable
} }