diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/CommentController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/CommentController.cs index b2c501ba..6c1a829a 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/CommentController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/CommentController.cs @@ -58,6 +58,19 @@ public class CommentController : ControllerBase if (type == CommentType.Level && slotType == "developer") targetId = await SlotHelper.GetPlaceholderSlotId(this.database, slotId, SlotType.Developer); + if (type == CommentType.Profile) + { + User? profile = await this.database.Users.FirstOrDefaultAsync(s => s.UserId == targetId); + if (profile == null) return this.BadRequest(); + if (!profile.CommentsEnabled) return this.NotFound(); + } + else + { + Slot? slot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == targetId); + if (slot == null) return this.BadRequest(); + if (!slot.CommentsEnabled) return this.NotFound(); + } + List comments = await this.database.Comments.Include (c => c.Poster) .Where(c => c.TargetId == targetId && c.Type == type) diff --git a/ProjectLighthouse.Servers.Website/Pages/Admin/NewCasePage.cshtml.cs b/ProjectLighthouse.Servers.Website/Pages/Admin/NewCasePage.cshtml.cs index b8727a16..4464503d 100644 --- a/ProjectLighthouse.Servers.Website/Pages/Admin/NewCasePage.cshtml.cs +++ b/ProjectLighthouse.Servers.Website/Pages/Admin/NewCasePage.cshtml.cs @@ -28,13 +28,16 @@ public class NewCasePage : BaseLayout return this.Page(); } - public async Task OnPost(CaseType? type, string reason, string modNotes, DateTime expires, int? affectedId) + public async Task OnPost(CaseType? type, string? reason, string? modNotes, DateTime expires, int? affectedId) { User? user = this.Database.UserFromWebRequest(this.Request); if (user == null || !user.IsModerator) return this.Redirect("/login"); if (type == null) return this.BadRequest(); if (affectedId == null) return this.BadRequest(); + + reason ??= string.Empty; + modNotes ??= string.Empty; // this is fucking ugly // if id is invalid then return bad request diff --git a/ProjectLighthouse.Servers.Website/Pages/SlotPage.cshtml b/ProjectLighthouse.Servers.Website/Pages/SlotPage.cshtml index f2e57af7..a4b59b22 100644 --- a/ProjectLighthouse.Servers.Website/Pages/SlotPage.cshtml +++ b/ProjectLighthouse.Servers.Website/Pages/SlotPage.cshtml @@ -223,7 +223,7 @@ - @if (!(bool)Model.Slot?.Hidden) + @if (!Model.Slot!.Hidden) {
@@ -232,5 +232,13 @@
} + + @if (Model.Slot!.CommentsEnabled) + { + + + Disable Comments + + } } \ No newline at end of file diff --git a/ProjectLighthouse.Servers.Website/Pages/SlotPage.cshtml.cs b/ProjectLighthouse.Servers.Website/Pages/SlotPage.cshtml.cs index 9128a58a..e77c53cd 100644 --- a/ProjectLighthouse.Servers.Website/Pages/SlotPage.cshtml.cs +++ b/ProjectLighthouse.Servers.Website/Pages/SlotPage.cshtml.cs @@ -17,7 +17,7 @@ public class SlotPage : BaseLayout public List Reviews = new(); public List Photos = new(); - public readonly bool CommentsEnabled = ServerConfiguration.Instance.UserGeneratedContentLimits.LevelCommentsEnabled; + public bool CommentsEnabled; public readonly bool ReviewsEnabled = ServerConfiguration.Instance.UserGeneratedContentLimits.LevelReviewsEnabled; public Slot? Slot; @@ -58,6 +58,7 @@ public class SlotPage : BaseLayout this.Slot = slot; + this.CommentsEnabled = ServerConfiguration.Instance.UserGeneratedContentLimits.LevelCommentsEnabled && this.Slot.CommentsEnabled; if (this.CommentsEnabled) { this.Comments = await this.Database.Comments.Include(p => p.Poster) diff --git a/ProjectLighthouse.Servers.Website/Pages/UserPage.cshtml b/ProjectLighthouse.Servers.Website/Pages/UserPage.cshtml index 785184b9..6c0f3045 100644 --- a/ProjectLighthouse.Servers.Website/Pages/UserPage.cshtml +++ b/ProjectLighthouse.Servers.Website/Pages/UserPage.cshtml @@ -132,6 +132,17 @@ } + @if (Model.ProfileUser.CommentsEnabled) + { + + + } +
diff --git a/ProjectLighthouse.Servers.Website/Pages/UserPage.cshtml.cs b/ProjectLighthouse.Servers.Website/Pages/UserPage.cshtml.cs index 4d6d941e..63a7c6e0 100644 --- a/ProjectLighthouse.Servers.Website/Pages/UserPage.cshtml.cs +++ b/ProjectLighthouse.Servers.Website/Pages/UserPage.cshtml.cs @@ -13,7 +13,7 @@ public class UserPage : BaseLayout { public List? Comments; - public bool CommentsEnabled = ServerConfiguration.Instance.UserGeneratedContentLimits.ProfileCommentsEnabled; + public bool CommentsEnabled; public bool IsProfileUserHearted; @@ -51,7 +51,9 @@ public class UserPage : BaseLayout } this.Photos = await this.Database.Photos.Include(p => p.Slot).OrderByDescending(p => p.Timestamp).Where(p => p.CreatorId == userId).Take(6).ToListAsync(); - if (this.CommentsEnabled) + + this.CommentsEnabled = ServerConfiguration.Instance.UserGeneratedContentLimits.LevelCommentsEnabled && this.ProfileUser.CommentsEnabled; + if(this.CommentsEnabled) { this.Comments = await this.Database.Comments.Include(p => p.Poster) .OrderByDescending(p => p.Timestamp) diff --git a/ProjectLighthouse/Administration/CaseType.cs b/ProjectLighthouse/Administration/CaseType.cs index 23c7a0ea..2c39178a 100644 --- a/ProjectLighthouse/Administration/CaseType.cs +++ b/ProjectLighthouse/Administration/CaseType.cs @@ -4,7 +4,7 @@ using LBPUnion.ProjectLighthouse.Extensions; namespace LBPUnion.ProjectLighthouse.Administration; -// Next available ID for use: 7 +// Next available ID for use: 6 // PLEASE UPDATE THIS WHEN YOU ADD SOMETHING HERE! // IF YOU DO NOT ADD THIS IN ORDER PROPERLY THEN THERE WILL BE DATA CORRUPTION! // THE VALUE MUST ALWAYS BE EXPLICITLY SET. @@ -13,10 +13,10 @@ public enum CaseType UserSilence = 0, UserRestriction = 1, UserBan = 2, - UserCommentsDisabled = 3, + UserDisableComments = 3, LevelHide = 4, - LevelCommentsDisabled = 5, + LevelDisableComments = 5, } public static class CaseTypeExtensions @@ -28,7 +28,7 @@ public static class CaseTypeExtensions CaseType.UserSilence => true, CaseType.UserRestriction => true, CaseType.UserBan => true, - CaseType.UserCommentsDisabled => true, + CaseType.UserDisableComments => true, _ => false, }; } @@ -38,7 +38,7 @@ public static class CaseTypeExtensions return type switch { CaseType.LevelHide => true, - CaseType.LevelCommentsDisabled => true, + CaseType.LevelDisableComments => true, _ => false, }; } diff --git a/ProjectLighthouse/Administration/Maintenance/RepeatingTasks/PerformCaseActionsTask.cs b/ProjectLighthouse/Administration/Maintenance/RepeatingTasks/PerformCaseActionsTask.cs index 8dcc46cf..ba17e54c 100644 --- a/ProjectLighthouse/Administration/Maintenance/RepeatingTasks/PerformCaseActionsTask.cs +++ b/ProjectLighthouse/Administration/Maintenance/RepeatingTasks/PerformCaseActionsTask.cs @@ -40,7 +40,11 @@ public class PerformCaseActionsTask : IRepeatingTask user!.PermissionLevel = PermissionLevel.Default; break; }; - case CaseType.UserCommentsDisabled: break; + case CaseType.UserDisableComments: + { + user!.CommentsEnabled = true; + break; + } case CaseType.LevelHide: { @@ -49,7 +53,11 @@ public class PerformCaseActionsTask : IRepeatingTask break; } - case CaseType.LevelCommentsDisabled: break; + case CaseType.LevelDisableComments: + { + slot!.CommentsEnabled = true; + break; + } default: throw new ArgumentOutOfRangeException(); } } @@ -76,7 +84,11 @@ public class PerformCaseActionsTask : IRepeatingTask database.WebTokens.RemoveRange(database.WebTokens.Where(t => t.UserId == user.UserId)); break; } - case CaseType.UserCommentsDisabled: break; + case CaseType.UserDisableComments: + { + user!.CommentsEnabled = false; + break; + } case CaseType.LevelHide: { @@ -85,7 +97,11 @@ public class PerformCaseActionsTask : IRepeatingTask break; } - case CaseType.LevelCommentsDisabled: break; + case CaseType.LevelDisableComments: + { + slot!.CommentsEnabled = false; + break; + } default: throw new ArgumentOutOfRangeException(); } } diff --git a/ProjectLighthouse/Levels/Slot.cs b/ProjectLighthouse/Levels/Slot.cs index 566fe053..23a45fb0 100644 --- a/ProjectLighthouse/Levels/Slot.cs +++ b/ProjectLighthouse/Levels/Slot.cs @@ -283,6 +283,9 @@ public class Slot return LbpSerializer.TaggedStringElement("slot", slotData, "type", "developer"); } + // should not be adjustable by user + public bool CommentsEnabled { get; set; } = true; + public string Serialize ( GameVersion gameVersion = GameVersion.LittleBigPlanet1, @@ -340,7 +343,7 @@ public class Slot LbpSerializer.StringElement("yourlbp3PlayCount", yourVisitedStats?.PlaysLBP3) + yourReview?.Serialize("yourReview") + LbpSerializer.StringElement("reviewsEnabled", ServerConfiguration.Instance.UserGeneratedContentLimits.LevelReviewsEnabled) + - LbpSerializer.StringElement("commentsEnabled", ServerConfiguration.Instance.UserGeneratedContentLimits.LevelCommentsEnabled) + + LbpSerializer.StringElement("commentsEnabled", ServerConfiguration.Instance.UserGeneratedContentLimits.LevelCommentsEnabled && CommentsEnabled) + LbpSerializer.StringElement("playerCount", playerCount) + LbpSerializer.StringElement("reviewCount", this.ReviewCount); diff --git a/ProjectLighthouse/Migrations/20220806181028_AddCommentsEnabledToSlotsAndUsers.cs b/ProjectLighthouse/Migrations/20220806181028_AddCommentsEnabledToSlotsAndUsers.cs new file mode 100644 index 00000000..baeb4401 --- /dev/null +++ b/ProjectLighthouse/Migrations/20220806181028_AddCommentsEnabledToSlotsAndUsers.cs @@ -0,0 +1,41 @@ +using LBPUnion.ProjectLighthouse; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ProjectLighthouse.Migrations +{ + [DbContext(typeof(Database))] + [Migration("20220806181028_AddCommentsEnabledToSlotsAndUsers")] + public partial class AddCommentsEnabledToSlotsAndUsers : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "CommentsEnabled", + table: "Users", + type: "tinyint(1)", + nullable: false, + defaultValue: true); + + migrationBuilder.AddColumn( + name: "CommentsEnabled", + table: "Slots", + type: "tinyint(1)", + nullable: false, + defaultValue: true); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "CommentsEnabled", + table: "Users"); + + migrationBuilder.DropColumn( + name: "CommentsEnabled", + table: "Slots"); + } + } +} diff --git a/ProjectLighthouse/PlayerData/Profiles/User.cs b/ProjectLighthouse/PlayerData/Profiles/User.cs index 926ebe6e..9c024713 100644 --- a/ProjectLighthouse/PlayerData/Profiles/User.cs +++ b/ProjectLighthouse/PlayerData/Profiles/User.cs @@ -173,6 +173,9 @@ public class User public PrivacyType ProfileVisibility { get; set; } = PrivacyType.All; + // should not be adjustable by user + public bool CommentsEnabled { get; set; } = true; + public string Serialize(GameVersion gameVersion = GameVersion.LittleBigPlanet1) { string user = LbpSerializer.TaggedStringElement("npHandle", this.Username, "icon", this.IconHash) + @@ -189,7 +192,7 @@ public class User LbpSerializer.StringElement("commentCount", this.Comments) + LbpSerializer.StringElement("photosByMeCount", this.PhotosByMe) + LbpSerializer.StringElement("photosWithMeCount", this.PhotosWithMe) + - LbpSerializer.StringElement("commentsEnabled", ServerConfiguration.Instance.UserGeneratedContentLimits.ProfileCommentsEnabled) + + LbpSerializer.StringElement("commentsEnabled", ServerConfiguration.Instance.UserGeneratedContentLimits.ProfileCommentsEnabled && CommentsEnabled) + LbpSerializer.StringElement("location", this.Location.Serialize()) + LbpSerializer.StringElement("favouriteSlotCount", this.HeartedLevels) + LbpSerializer.StringElement("favouriteUserCount", this.HeartedUsers) + diff --git a/ProjectLighthouse/ProjectLighthouse/Migrations/DatabaseModelSnapshot.cs b/ProjectLighthouse/ProjectLighthouse/Migrations/DatabaseModelSnapshot.cs index 41940fd2..543da4f0 100644 --- a/ProjectLighthouse/ProjectLighthouse/Migrations/DatabaseModelSnapshot.cs +++ b/ProjectLighthouse/ProjectLighthouse/Migrations/DatabaseModelSnapshot.cs @@ -234,6 +234,9 @@ namespace ProjectLighthouse.Migrations .IsRequired() .HasColumnType("longtext"); + b.Property("CommentsEnabled") + .HasColumnType("tinyint(1)"); + b.Property("CreatorId") .HasColumnType("int"); @@ -721,6 +724,9 @@ namespace ProjectLighthouse.Migrations b.Property("BooHash") .HasColumnType("longtext"); + b.Property("CommentsEnabled") + .HasColumnType("tinyint(1)"); + b.Property("EmailAddress") .HasColumnType("longtext");