Add ability to hide comments on levels and profiles

This commit is contained in:
jvyden 2022-08-06 14:23:37 -04:00
parent 0b8c0cbfb4
commit 8fe9bd4c57
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
12 changed files with 123 additions and 16 deletions

View file

@ -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<Comment> comments = await this.database.Comments.Include
(c => c.Poster)
.Where(c => c.TargetId == targetId && c.Type == type)

View file

@ -28,7 +28,7 @@ public class NewCasePage : BaseLayout
return this.Page();
}
public async Task<IActionResult> OnPost(CaseType? type, string reason, string modNotes, DateTime expires, int? affectedId)
public async Task<IActionResult> 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");
@ -36,6 +36,9 @@ public class NewCasePage : BaseLayout
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
if (!(await ((CaseType)type).IsIdValid((int)affectedId, this.Database))) return this.BadRequest();

View file

@ -223,7 +223,7 @@
</div>
</a>
@if (!(bool)Model.Slot?.Hidden)
@if (!Model.Slot!.Hidden)
{
<a href="/moderation/newCase?type=@((int)CaseType.LevelHide)&affectedId=@Model.Slot?.SlotId">
<div class="ui yellow button">
@ -232,5 +232,13 @@
</div>
</a>
}
@if (Model.Slot!.CommentsEnabled)
{
<a class="ui yellow button" href="/moderation/newCase?type=@((int)CaseType.LevelDisableComments)&affectedId=@Model.Slot?.SlotId">
<i class="lock icon"></i>
<span>Disable Comments</span>
</a>
}
</div>
}

View file

@ -17,7 +17,7 @@ public class SlotPage : BaseLayout
public List<Review> Reviews = new();
public List<Photo> 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)

View file

@ -132,6 +132,17 @@
<div class="ui fitted hidden divider"></div>
}
@if (Model.ProfileUser.CommentsEnabled)
{
<div>
<a class="ui yellow button" href="/moderation/newCase?type=@((int)CaseType.UserDisableComments)&affectedId=@Model.ProfileUser.UserId">
<i class="lock icon"></i>
<span>Disable Comments</span>
</a>
</div>
<div class="ui fitted hidden divider"></div>
}
<div>
<a class="ui red button" href="/moderation/user/@Model.ProfileUser.UserId/wipePlanets">
<i class="trash alternate icon"></i>

View file

@ -13,7 +13,7 @@ public class UserPage : BaseLayout
{
public List<Comment>? Comments;
public bool CommentsEnabled = ServerConfiguration.Instance.UserGeneratedContentLimits.ProfileCommentsEnabled;
public bool CommentsEnabled;
public bool IsProfileUserHearted;
@ -51,6 +51,8 @@ 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();
this.CommentsEnabled = ServerConfiguration.Instance.UserGeneratedContentLimits.LevelCommentsEnabled && this.ProfileUser.CommentsEnabled;
if(this.CommentsEnabled)
{
this.Comments = await this.Database.Comments.Include(p => p.Poster)

View file

@ -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,
};
}

View file

@ -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();
}
}

View file

@ -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);

View file

@ -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<bool>(
name: "CommentsEnabled",
table: "Users",
type: "tinyint(1)",
nullable: false,
defaultValue: true);
migrationBuilder.AddColumn<bool>(
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");
}
}
}

View file

@ -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) +

View file

@ -234,6 +234,9 @@ namespace ProjectLighthouse.Migrations
.IsRequired()
.HasColumnType("longtext");
b.Property<bool>("CommentsEnabled")
.HasColumnType("tinyint(1)");
b.Property<int>("CreatorId")
.HasColumnType("int");
@ -721,6 +724,9 @@ namespace ProjectLighthouse.Migrations
b.Property<string>("BooHash")
.HasColumnType("longtext");
b.Property<bool>("CommentsEnabled")
.HasColumnType("tinyint(1)");
b.Property<string>("EmailAddress")
.HasColumnType("longtext");