Implement profile and level privacy settings (#841)

* Create interactions management page and basic GET logic

* Fix client side query and add blocked count as well as comments nitpick

* Implement basic backend logic for interactions management

* Remove errant null/whitespace checks and add border to blocked users partials

* Implement user page's respect to profile privacy settings

* Fix issue where user can't view their own profile if privacy settings are tightened

* Fix other issues with profile access

* Remove excess conditional expression from PSN privtype check

* Check if access is allowed within request handler and hide bio/RA if private

* Fix PSN privacy level check

* Display private users in search and add base UI class to level lock icon

* Rename everything from interactions to privacy for clarity

* Dagg requested an eyeball

Co-authored-by: vilijur <69403080+vilijur@users.noreply.github.com>

* Clarify profile settings page title

* Implement level privacy settings

* Formatting nitpicks within UserPrivacyPage

* Add discard changes buttons

* Apply suggestion from code review

* Consolidate privacy settings areas together

* Grammar nitpick for comments enable/disable dropdown

* Remove un-needed blue UI segment

* Allow mods to issue disable comments case regardless of privacy settings

Also addresses a few frontend and backend nitpicks left unaddressed by previous commits

* Remove limiting AND operator expression

* Grammar clarity on disable comments button

* Add missing hidden button divider under Wipe Earth Decorations

* No eyeball -m88youngling

Removes eyeball from actual privacy settings page to match styling

* Use long-text description for privacy type dropdowns

* Use long-text description for comments toggle dropdown

* Implement slot page privacy

* Grammar nitpicks with Daggintosh

* Daggintosh grammar review second edition

* Once again put request handler arguments on one line

* Rename LevelsPrivate variable to SlotsPrivate for internal consistency

* Fix issue with PSN slot privacy type

* Un-break comments

* Apply most of the suggestions from code review

* Correct form dropdown values for privacy types

* Potentially fix broken privacy type extension

* Slightly rework access calculation extension method

* Fix issues with if statements

* Apply suggestions from code review

* Make everything translatable

---------

Co-authored-by: vilijur <69403080+vilijur@users.noreply.github.com>
This commit is contained in:
koko 2023-07-22 17:49:56 -04:00 committed by GitHub
parent f084189a29
commit 6558d09c8d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 645 additions and 353 deletions

View file

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="enable_comments" xml:space="preserve">
<value>Enable commenting on your profile.</value>
</data>
<data name="disable_comments" xml:space="preserve">
<value>Disable commenting on your profile.</value>
</data>
<data name="no_blocked_users" xml:space="preserve">
<value>You have not blocked any users.</value>
</data>
<data name="blocked_users" xml:space="preserve">
<value>You have blocked {0} user(s).</value>
</data>
<data name="privacy_all" xml:space="preserve">
<value>Share your {0} with everyone!</value>
</data>
<data name="privacy_psn" xml:space="preserve">
<value>Only share your {0} with users who are playing in-game.</value>
</data>
<data name="privacy_game" xml:space="preserve">
<value>Only share your {0} with users who are signed into the website or playing in-game.</value>
</data>
</root>

View file

@ -48,6 +48,10 @@
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Moderation.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Update="Privacy.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Privacy.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project>

View file

@ -0,0 +1,16 @@
namespace LBPUnion.ProjectLighthouse.Localization.StringLists;
public static class PrivacyStrings
{
public static readonly TranslatableString BlockedUsers = create("blocked_users");
public static readonly TranslatableString NoBlockedUsers = create("no_blocked_users");
public static readonly TranslatableString EnableComments = create("enable_comments");
public static readonly TranslatableString DisableComments = create("disable_comments");
public static readonly TranslatableString PrivacyAll = create("privacy_all");
public static readonly TranslatableString PrivacyPSN = create("privacy_psn");
public static readonly TranslatableString PrivacyGame = create("privacy_game");
private static TranslatableString create(string key) => new(TranslationAreas.Privacy, key);
}

View file

@ -13,4 +13,5 @@ public enum TranslationAreas
ModPanel,
TwoFactor,
Moderation,
Privacy,
}

View file

@ -5,7 +5,7 @@ namespace LBPUnion.ProjectLighthouse.Servers.Website.Extensions;
public static class FormattingExtensions
{
public static string GetLevelLockIcon(this SlotEntity slot) => slot.InitiallyLocked ? "icon lock" : "";
public static string GetLevelLockIcon(this SlotEntity slot) => slot.InitiallyLocked ? "ui icon lock" : "";
public static string ToHtmlColor(this PermissionLevel permissionLevel)
{

View file

@ -1,5 +1,4 @@
@using System.Web
@using System.IO
@using LBPUnion.ProjectLighthouse.Database
@using LBPUnion.ProjectLighthouse.Localization
@using LBPUnion.ProjectLighthouse.Servers.Website.Extensions
@ -17,11 +16,11 @@
<div class="ui yellow segment" id="comments">
@if (Model.Comments.Count == 0 && Model.CommentsEnabled)
{
<p><i>There are no comments.</i></p>
<span><i>There are no comments.</i></span>
}
else if (!Model.CommentsEnabled)
{
<p><i>Comments are disabled.</i></p>
<span><i>Comments are disabled.</i></span>
}
else
{
@ -51,10 +50,9 @@
CommentEntity comment = commentAndReaction.Key;
int yourThumb = commentAndReaction.Value?.Rating ?? 0;
DateTimeOffset timestamp = DateTimeOffset.FromUnixTimeSeconds(comment.Timestamp / 1000).ToLocalTime();
StringWriter messageWriter = new();
HttpUtility.HtmlDecode(comment.GetCommentMessage(Database), messageWriter);
string decodedMessage = messageWriter.ToString();
string decodedMessage = HttpUtility.HtmlDecode(comment.GetCommentMessage(Database));
string? url = Url.RouteUrl(ViewContext.RouteData.Values);
if (url == null) continue;

View file

@ -58,129 +58,139 @@
@await Model.Slot.ToHtml(Html, ViewData, Model.User, $"~/slot/{Model.Slot?.SlotId}", language, timeZone, isMobile)
<br>
<div class="@(isMobile ? "" : "ui grid")">
<div class="eight wide column">
<div class="ui blue segment">
<h2>Description</h2>
<p style="overflow-wrap: anywhere">@HttpUtility.HtmlDecode(string.IsNullOrEmpty(Model.Slot?.Description) ? "This level has no description." : Model.Slot.Description)</p>
</div>
@if (!Model.CanViewSlot)
{
<div class="ui red segment">
<p>
<i>The creator's privacy settings prevent you from viewing this page.</i>
</p>
</div>
@if (isMobile)
{
<br/>
}
<div class="eight wide column">
<div class="ui red segment">
<h2>Tags</h2>
@{
string[] authorLabels;
if (Model.Slot?.GameVersion == GameVersion.LittleBigPlanet1)
{
authorLabels = Model.Slot.LevelTags(Database);
}
else
{
authorLabels = Model.Slot?.AuthorLabels.Split(",", StringSplitOptions.RemoveEmptyEntries) ?? Array.Empty<string>();
}
if (authorLabels.Length == 0)
{
<p>This level has no tags.</p>
}
else
{
foreach (string label in authorLabels.Where(label => !string.IsNullOrEmpty(label)))
}
else
{
<div class="@(isMobile ? "" : "ui grid")">
<div class="eight wide column">
<div class="ui blue segment">
<h2>Description</h2>
<p style="overflow-wrap: anywhere">@HttpUtility.HtmlDecode(string.IsNullOrEmpty(Model.Slot?.Description) ? "This level has no description." : Model.Slot.Description)</p>
</div>
</div>
@if (isMobile)
{
<br/>
}
<div class="eight wide column">
<div class="ui red segment">
<h2>Tags</h2>
@{
string[] authorLabels;
if (Model.Slot?.GameVersion == GameVersion.LittleBigPlanet1)
{
<div class="ui blue label">@LabelHelper.TranslateTag(label)</div>
authorLabels = Model.Slot.LevelTags(Database);
}
}
}
</div>
</div>
@if (isMobile)
{
<br/>
}
</div>
<div class="ui grid">
@{
string outerDiv = isMobile ?
"horizontal-scroll" :
"three wide column";
string innerDiv = isMobile ?
"ui top attached tabular menu horizontal-scroll" :
"ui vertical fluid tabular menu";
}
<div class="@outerDiv">
<div class="@innerDiv">
<a class="item active lh-sidebar" target="lh-comments">
Comments
</a>
<a class="item lh-sidebar" target="lh-photos">
@Model.Translate(BaseLayoutStrings.HeaderPhotos)
</a>
<a class="item lh-sidebar" target="lh-reviews">
Reviews
</a>
<a class="item lh-sidebar" target="lh-scores">
Scores
</a>
</div>
</div>
@{
string divLength = isMobile ? "sixteen" : "thirteen";
}
<div class="@divLength wide stretched column">
<div class="lh-content" id="lh-comments">
@await Html.PartialAsync("Partials/CommentsPartial", new ViewDataDictionary(ViewData.WithLang(language).WithTime(timeZone))
{ { "PageOwner", Model.Slot?.CreatorId }, })
</div>
<div class="lh-content" id="lh-photos">
<div class="ui purple segment" id="photos">
@if (Model.Photos.Count != 0)
{
<div class="ui center aligned grid">
@foreach (PhotoEntity photo in Model.Photos)
else
{
authorLabels = Model.Slot?.AuthorLabels.Split(",", StringSplitOptions.RemoveEmptyEntries) ?? Array.Empty<string>();
}
if (authorLabels.Length == 0)
{
<p>This level has no tags.</p>
}
else
{
foreach (string label in authorLabels.Where(label => !string.IsNullOrEmpty(label)))
{
string width = isMobile ? "sixteen" : "eight";
bool canDelete = Model.User != null && (Model.User.IsModerator || Model.User.UserId == photo.CreatorId);
<div class="@width wide column">
@await photo.ToHtml(Html, ViewData, language, timeZone, canDelete)
</div>
<div class="ui blue label">@LabelHelper.TranslateTag(label)</div>
}
</div>
@if (isMobile)
{
<br/>
}
}
else
{
<p>This level has no photos yet.</p>
}
</div>
</div>
<div class="lh-content" id="lh-reviews">
@await Html.PartialAsync("Partials/ReviewPartial", new ViewDataDictionary(ViewData)
{
{
"isMobile", isMobile
},
{
"CanDelete", Model.User?.IsModerator ?? false
},
})
@if (isMobile)
{
<br/>
}
</div>
<div class="ui grid">
@{
string outerDiv = isMobile ? "horizontal-scroll" : "three wide column";
string innerDiv = isMobile ? "ui top attached tabular menu horizontal-scroll" : "ui vertical fluid tabular menu";
}
<div class="@outerDiv">
<div class="@innerDiv">
<a class="item active lh-sidebar" target="lh-comments">
Comments
</a>
<a class="item lh-sidebar" target="lh-photos">
@Model.Translate(BaseLayoutStrings.HeaderPhotos)
</a>
<a class="item lh-sidebar" target="lh-reviews">
Reviews
</a>
<a class="item lh-sidebar" target="lh-scores">
Scores
</a>
</div>
</div>
<div class="lh-content" id="lh-scores">
<div class="eight wide column">
@await Html.PartialAsync("Partials/LeaderboardPartial",
ViewData.WithLang(language).WithTime(timeZone).CanDelete(Model.User?.IsModerator ?? false))
@{
string divLength = isMobile ? "sixteen" : "thirteen";
}
<div class="@divLength wide stretched column">
<div class="lh-content" id="lh-comments">
@await Html.PartialAsync("Partials/CommentsPartial", new ViewDataDictionary(ViewData.WithLang(language).WithTime(timeZone))
{
{
"PageOwner", Model.Slot?.CreatorId
},
})
</div>
<div class="lh-content" id="lh-photos">
<div class="ui purple segment" id="photos">
@if (Model.Photos.Count != 0)
{
<div class="ui center aligned grid">
@foreach (PhotoEntity photo in Model.Photos)
{
string width = isMobile ? "sixteen" : "eight";
bool canDelete = Model.User != null && (Model.User.IsModerator || Model.User.UserId == photo.CreatorId);
<div class="@width wide column">
@await photo.ToHtml(Html, ViewData, language, timeZone, canDelete)
</div>
}
</div>
@if (isMobile)
{
<br/>
}
}
else
{
<p>This level has no photos yet.</p>
}
</div>
</div>
<div class="lh-content" id="lh-reviews">
@await Html.PartialAsync("Partials/ReviewPartial", new ViewDataDictionary(ViewData)
{
{
"isMobile", isMobile
},
{
"CanDelete", Model.User?.IsModerator ?? false
},
})
</div>
<div class="lh-content" id="lh-scores">
<div class="eight wide column">
@await Html.PartialAsync("Partials/LeaderboardPartial", ViewData.WithLang(language).WithTime(timeZone).CanDelete(Model.User?.IsModerator ?? false))
</div>
</div>
</div>
</div>
</div>
}
@if (isMobile)
{

View file

@ -22,6 +22,8 @@ public class SlotPage : BaseLayout
public bool CommentsEnabled;
public readonly bool ReviewsEnabled = ServerConfiguration.Instance.UserGeneratedContentLimits.LevelReviewsEnabled;
public bool CanViewSlot;
public SlotEntity? Slot;
public SlotPage(DatabaseContext database) : base(database)
{}
@ -34,27 +36,11 @@ public class SlotPage : BaseLayout
if (slot == null) return this.NotFound();
System.Diagnostics.Debug.Assert(slot.Creator != null);
bool isAuthenticated = this.User != null;
bool isOwner = slot.Creator == this.User || this.User != null && this.User.IsModerator;
// Determine if user can view slot according to creator's privacy settings
if (this.User == null || !this.User.IsAdmin)
{
switch (slot.Creator.ProfileVisibility)
{
case PrivacyType.PSN:
{
if (this.User != null) return this.NotFound();
break;
}
case PrivacyType.Game:
{
if (this.User == null || slot.Creator != this.User) return this.NotFound();
break;
}
case PrivacyType.All: break;
default: throw new ArgumentOutOfRangeException();
}
}
this.CanViewSlot = slot.Creator.LevelVisibility.CanAccess(isAuthenticated, isOwner);
if ((slot.Hidden || slot.SubLevel && (this.User == null && this.User != slot.Creator)) && !(this.User?.IsModerator ?? false))
return this.NotFound();

View file

@ -72,7 +72,6 @@ public class SlotsPage : BaseLayout
if (this.PageNumber < 0 || this.PageNumber >= this.PageAmount) return this.Redirect($"/slots/{Math.Clamp(this.PageNumber, 0, this.PageAmount - 1)}");
this.Slots = await slots
.Where(p => p.Creator!.LevelVisibility == PrivacyType.All) // TODO: change check for when user is logged in
.OrderByDescending(p => p.FirstUploaded)
.Skip(pageNumber * ServerStatics.PageSize)
.Take(ServerStatics.PageSize)

View file

@ -29,7 +29,7 @@
<b>Reason:</b>
<span>"@Model.ProfileUser.BannedReason"</span>
}
else
else
{
<p>This user has been banned for violating the Terms of Service. Remember to follow the rules!</p>
}
@ -39,20 +39,20 @@
<div class="@(isMobile ? "" : "ui grid")">
<div class="eight wide column">
@await Html.PartialAsync("Partials/UserCardPartial", Model.ProfileUser, new ViewDataDictionary(ViewData)
{
{
"ShowLink", false
},
{
"IsMobile", Model.Request.IsMobile()
},
{
"Language", Model.GetLanguage()
},
{
"TimeZone", Model.GetTimeZone()
},
})
{
{
"ShowLink", false
},
{
"IsMobile", Model.Request.IsMobile()
},
{
"Language", Model.GetLanguage()
},
{
"TimeZone", Model.GetTimeZone()
},
})
</div>
<div class="eight wide right aligned column">
<br>
@ -87,11 +87,18 @@
</a>
}
}
@if (Model.ProfileUser == Model.User)
{
<a class="ui blue button" href="/user/@Model.ProfileUser.UserId/privacy">
<i class="eye icon"></i>
<span>Privacy Settings</span>
</a>
}
@if (Model.ProfileUser == Model.User || (Model.User?.IsModerator ?? false))
{
<a class="ui blue button" href="/user/@Model.ProfileUser.UserId/settings">
<i class="cog icon"></i>
<span>Settings</span>
<span>Profile Settings</span>
</a>
}
@if (Model.ProfileUser == Model.User)
@ -106,173 +113,200 @@
{
<br/>
}
<div class="eight wide column">
<div class="ui blue segment">
<h2>@Model.Translate(ProfileStrings.Biography)</h2>
@if (string.IsNullOrWhiteSpace(Model.ProfileUser.Biography))
{
<p>@Model.Translate(ProfileStrings.NoBiography, Model.ProfileUser.Username)</p>
}
else
{
<p style="overflow-wrap: anywhere;">@HttpUtility.HtmlDecode(Model.ProfileUser.Biography)</p>
}
</div>
</div>
@if (isMobile)
@if (Model.CanViewProfile)
{
<br/>
}
<div class="eight wide column">
<div class="ui red segment">
<h2>@Model.Translate(GeneralStrings.RecentActivity)</h2>
<p>@Model.Translate(GeneralStrings.Soon)</p>
</div>
</div>
@if (isMobile)
{
<br/>
}
</div>
<div class="ui grid">
@{
string outerDiv = isMobile ?
"horizontal-scroll" :
"three wide column";
string innerDiv = isMobile ?
"ui top attached tabular menu horizontal-scroll" :
"ui vertical fluid tabular menu";
}
<div class="@outerDiv">
<div class="@innerDiv">
<a class="item active lh-sidebar" target="lh-comments">
Comments
</a>
<a class="item lh-sidebar" target="lh-photos">
@Model.Translate(BaseLayoutStrings.HeaderPhotos)
</a>
<a class="item lh-sidebar" target="lh-levels">
@Model.Translate(BaseLayoutStrings.HeaderSlots)
</a>
<a class="item lh-sidebar" target="lh-playlists">
Playlists
</a>
@if (Model.User == Model.ProfileUser)
{
<a class="item lh-sidebar" target="lh-hearted">
Hearted Levels
</a>
<a class="item lh-sidebar" target="lh-queued">
Queued Levels
</a>
}
</div>
</div>
@{
string divLength = isMobile ? "sixteen" : "thirteen";
}
<div class="@divLength wide stretched column">
<div class="lh-content" id="lh-comments">
@if (Model.ProfileUser.IsBanned)
{
<div class="ui yellow segment" id="comments">
<p><i>Comments are disabled because the user is banned.</i></p>
</div>
}
else
{
@await Html.PartialAsync("Partials/CommentsPartial", new ViewDataDictionary(ViewData.WithLang(language).WithTime(timeZone))
{ {"PageOwner", Model.ProfileUser.UserId}, })
}
</div>
<div class="lh-content" id="lh-photos">
<div class="ui purple segment" id="photos">
@if (Model.Photos != null && Model.Photos.Count != 0)
<div class="eight wide column">
<div class="ui blue segment">
<h2>@Model.Translate(ProfileStrings.Biography)</h2>
@if (string.IsNullOrWhiteSpace(Model.ProfileUser.Biography))
{
<div class="ui center aligned grid">
@foreach (PhotoEntity photo in Model.Photos)
{
string width = isMobile ? "sixteen" : "eight";
bool canDelete = Model.User != null && (Model.User.IsModerator || Model.User.UserId == photo.CreatorId);
<div class="@width wide column">
@await photo.ToHtml(Html, ViewData, language, timeZone, canDelete)
</div>
}
</div>
@if (isMobile)
{
<br/>
}
<p>@Model.Translate(ProfileStrings.NoBiography, Model.ProfileUser.Username)</p>
}
else
{
<p>This user hasn't uploaded any photos</p>
<p style="overflow-wrap: anywhere;">@HttpUtility.HtmlDecode(Model.ProfileUser.Biography)</p>
}
</div>
</div>
<div class="lh-content" id="lh-levels">
<div class="ui green segment" id="levels">
@if (Model.Slots?.Count == 0)
{
<p>This user hasn't published any levels</p>
}
@foreach (SlotEntity slot in Model.Slots ?? new List<SlotEntity>())
{
<div class="ui segment">
@await slot.ToHtml(Html, ViewData, Model.User, $"~/user/{Model.ProfileUser.UserId}#levels", language, timeZone, isMobile, true)
</div>
}
</div>
</div>
<div class="lh-content" id="lh-playlists">
<div class="ui purple segment">
@if (isMobile)
{
<br/>
}
<div class="eight wide column">
<div class="ui red segment">
<h2>@Model.Translate(GeneralStrings.RecentActivity)</h2>
<p>@Model.Translate(GeneralStrings.Soon)</p>
</div>
</div>
@if (Model.User == Model.ProfileUser)
@if (isMobile)
{
<div class="lh-content" id="lh-hearted">
<div class="ui pink segment" id="hearted">
@if (Model.HeartedSlots?.Count == 0)
{
<p>You haven't hearted any levels</p>
}
else
{
<p>You have hearted @(Model.HeartedSlots?.Count) levels</p>
}
@foreach (SlotEntity slot in Model.HeartedSlots ?? new List<SlotEntity>())
{
<div class="ui segment">
@await slot.ToHtml(Html, ViewData, Model.User, $"~/user/{Model.ProfileUser.UserId}#hearted", language, timeZone, isMobile, true)
</div>
}
</div>
</div>
<div class="lh-content" id="lh-queued">
<div class="ui yellow segment" id="queued">
@if (Model.QueuedSlots?.Count == 0)
{
<p>You haven't queued any levels</p>
}
else
{
<p>There are @(Model.QueuedSlots?.Count) levels in your queue</p>
}
@foreach (SlotEntity slot in Model.QueuedSlots ?? new List<SlotEntity>())
{
<div class="ui segment">
@await slot.ToHtml(Html, ViewData, Model.User, $"~/user/{Model.ProfileUser.UserId}#queued", language, timeZone, isMobile, true)
</div>
}
</div>
</div>
}
</div>
<br/>
}
}
</div>
@if (!Model.CanViewProfile)
{
<div class="ui red segment">
<p>
<i>The user's privacy settings prevent you from viewing this page.</i>
</p>
</div>
}
else
{
<div class="ui grid">
@{
string outerDiv = isMobile ? "horizontal-scroll" : "three wide column";
string innerDiv = isMobile ? "ui top attached tabular menu horizontal-scroll" : "ui vertical fluid tabular menu";
}
<div class="@outerDiv">
<div class="@innerDiv">
<a class="item active lh-sidebar" target="lh-comments">
Comments
</a>
<a class="item lh-sidebar" target="lh-photos">
@Model.Translate(BaseLayoutStrings.HeaderPhotos)
</a>
<a class="item lh-sidebar" target="lh-levels">
@Model.Translate(BaseLayoutStrings.HeaderSlots)
</a>
<a class="item lh-sidebar" target="lh-playlists">
Playlists
</a>
@if (Model.User == Model.ProfileUser)
{
<a class="item lh-sidebar" target="lh-hearted">
Hearted Levels
</a>
<a class="item lh-sidebar" target="lh-queued">
Queued Levels
</a>
}
</div>
</div>
@{
string divLength = isMobile ? "sixteen" : "thirteen";
}
<div class="@divLength wide stretched column">
<div class="lh-content" id="lh-comments">
@if (Model.ProfileUser.IsBanned)
{
<div class="ui yellow segment" id="comments">
<p>
<i>Comments are disabled because the user is banned.</i>
</p>
</div>
}
else
{
@await Html.PartialAsync("Partials/CommentsPartial", new ViewDataDictionary(ViewData.WithLang(language).WithTime(timeZone))
{
{
"PageOwner", Model.ProfileUser.UserId
},
})
}
</div>
<div class="lh-content" id="lh-photos">
<div class="ui purple segment" id="photos">
@if (Model.Photos != null && Model.Photos.Count != 0)
{
<div class="ui center aligned grid">
@foreach (PhotoEntity photo in Model.Photos)
{
string width = isMobile ? "sixteen" : "eight";
bool canDelete = Model.User != null && (Model.User.IsModerator || Model.User.UserId == photo.CreatorId);
<div class="@width wide column">
@await photo.ToHtml(Html, ViewData, language, timeZone, canDelete)
</div>
}
</div>
@if (isMobile)
{
<br/>
}
}
else
{
<p>This user hasn't uploaded any photos</p>
}
</div>
</div>
<div class="lh-content" id="lh-levels">
@if (!Model.CanViewSlots)
{
<div class="ui red segment">
<p>
<i>The user's privacy settings prevent you from viewing this page.</i>
</p>
</div>
}
else
{
<div class="ui green segment" id="levels">
@if (Model.Slots?.Count == 0)
{
<p>This user hasn't published any levels</p>
}
@foreach (SlotEntity slot in Model.Slots ?? new List<SlotEntity>())
{
<div class="ui segment">
@await slot.ToHtml(Html, ViewData, Model.User, $"~/user/{Model.ProfileUser.UserId}#levels", language, timeZone, isMobile, true)
</div>
}
</div>
}
</div>
<div class="lh-content" id="lh-playlists">
<div class="ui purple segment">
<p>@Model.Translate(GeneralStrings.Soon)</p>
</div>
</div>
@if (Model.User == Model.ProfileUser)
{
<div class="lh-content" id="lh-hearted">
<div class="ui pink segment" id="hearted">
@if (Model.HeartedSlots?.Count == 0)
{
<p>You haven't hearted any levels</p>
}
else
{
<p>You have hearted @(Model.HeartedSlots?.Count) levels</p>
}
@foreach (SlotEntity slot in Model.HeartedSlots ?? new List<SlotEntity>())
{
<div class="ui segment">
@await slot.ToHtml(Html, ViewData, Model.User, $"~/user/{Model.ProfileUser.UserId}#hearted", language, timeZone, isMobile, true)
</div>
}
</div>
</div>
<div class="lh-content" id="lh-queued">
<div class="ui yellow segment" id="queued">
@if (Model.QueuedSlots?.Count == 0)
{
<p>You haven't queued any levels</p>
}
else
{
<p>There are @(Model.QueuedSlots?.Count) levels in your queue</p>
}
@foreach (SlotEntity slot in Model.QueuedSlots ?? new List<SlotEntity>())
{
<div class="ui segment">
@await slot.ToHtml(Html, ViewData, Model.User, $"~/user/{Model.ProfileUser.UserId}#queued", language, timeZone, isMobile, true)
</div>
}
</div>
</div>
}
</div>
</div>
}
@if (Model.User != null && Model.User.IsModerator)
{
<div class="ui green segment">
@ -289,25 +323,25 @@
<div class="ui fitted hidden divider"></div>
}
@if (Model.ProfileUser.CommentsEnabled)
<div>
<a class="ui red button" href="/moderation/user/@Model.ProfileUser.UserId/wipePlanets">
<i class="trash alternate icon"></i>
<span>Wipe Earth Decorations</span>
</a>
</div>
<div class="ui fitted hidden divider"></div>
@if (!Model.CommentsDisabledByModerator)
{
<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>
<span>Forcibly 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>
<span>Wipe user's earth decorations</span>
</a>
</div>
<div class="ui fitted hidden divider"></div>
@if (Model.User.IsAdmin)
{
@await Html.PartialAsync("Partials/AdminSetGrantedSlotsFormPartial", Model.ProfileUser)
@ -364,4 +398,4 @@ if (selectedElement != null) {
let sidebarEle = document.querySelector("[target=" + selectedElement.id + "]")
setVisible(sidebarEle);
}
</script>
</script>

View file

@ -6,6 +6,7 @@ using LBPUnion.ProjectLighthouse.Types.Entities.Interaction;
using LBPUnion.ProjectLighthouse.Types.Entities.Level;
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
using LBPUnion.ProjectLighthouse.Types.Levels;
using LBPUnion.ProjectLighthouse.Types.Moderation.Cases;
using LBPUnion.ProjectLighthouse.Types.Users;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
@ -17,6 +18,7 @@ public class UserPage : BaseLayout
public Dictionary<CommentEntity, RatedCommentEntity?> Comments = new();
public bool CommentsEnabled;
public bool CommentsDisabledByModerator;
public bool IsProfileUserHearted;
@ -29,35 +31,24 @@ public class UserPage : BaseLayout
public List<SlotEntity>? QueuedSlots;
public UserEntity? ProfileUser;
public bool CanViewProfile;
public bool CanViewSlots;
public UserPage(DatabaseContext database) : base(database)
{}
{ }
public async Task<IActionResult> OnGet([FromRoute] int userId)
{
this.ProfileUser = await this.Database.Users.FirstOrDefaultAsync(u => u.UserId == userId);
if (this.ProfileUser == null) return this.NotFound();
bool isAuthenticated = this.User != null;
bool isOwner = this.ProfileUser == this.User || this.User != null && this.User.IsModerator;
// Determine if user can view profile according to profileUser's privacy settings
if (this.User == null || !this.User.IsAdmin)
{
switch (this.ProfileUser.ProfileVisibility)
{
case PrivacyType.PSN:
{
if (this.User != null) return this.NotFound();
break;
}
case PrivacyType.Game:
{
if (this.ProfileUser != this.User) return this.NotFound();
break;
}
case PrivacyType.All: break;
default: throw new ArgumentOutOfRangeException();
}
}
this.CanViewProfile = this.ProfileUser.ProfileVisibility.CanAccess(isAuthenticated, isOwner);
this.CanViewSlots = this.ProfileUser.LevelVisibility.CanAccess(isAuthenticated, isOwner);
this.Photos = await this.Database.Photos.Include(p => p.Slot)
.Include(p => p.PhotoSubjects)
@ -91,21 +82,24 @@ public class UserPage : BaseLayout
.ToListAsync();
}
this.CommentsEnabled = ServerConfiguration.Instance.UserGeneratedContentLimits.LevelCommentsEnabled && this.ProfileUser.CommentsEnabled;
this.CommentsEnabled = ServerConfiguration.Instance.UserGeneratedContentLimits.LevelCommentsEnabled &&
this.ProfileUser.CommentsEnabled;
if (this.CommentsEnabled)
{
List<int> blockedUsers = this.User == null ? new List<int>() : await
(from blockedProfile in this.Database.BlockedProfiles
where blockedProfile.UserId == this.User.UserId
select blockedProfile.BlockedUserId).ToListAsync();
List<int> blockedUsers = this.User == null
? new List<int>()
: await (
from blockedProfile in this.Database.BlockedProfiles
where blockedProfile.UserId == this.User.UserId
select blockedProfile.BlockedUserId).ToListAsync();
this.Comments = await this.Database.Comments.Include(p => p.Poster)
.OrderByDescending(p => p.Timestamp)
.Where(p => p.TargetId == userId && p.Type == CommentType.Profile)
.Where(p => !blockedUsers.Contains(p.PosterUserId))
.Take(50)
.ToDictionaryAsync(c => c, _ => (RatedCommentEntity?) null);
.ToDictionaryAsync(c => c, _ => (RatedCommentEntity?)null);
}
else
{
@ -122,13 +116,17 @@ public class UserPage : BaseLayout
this.Comments[kvp.Key] = reaction;
}
this.IsProfileUserHearted = await this.Database.HeartedProfiles
.Where(h => h.HeartedUserId == this.ProfileUser.UserId)
this.IsProfileUserHearted = await this.Database.HeartedProfiles.Where(h => h.HeartedUserId == this.ProfileUser.UserId)
.Where(h => h.UserId == this.User.UserId)
.AnyAsync();
this.IsProfileUserBlocked = await this.Database.IsUserBlockedBy(this.ProfileUser.UserId, this.User.UserId);
this.CommentsDisabledByModerator = await this.Database.Cases.Where(c => c.AffectedId == this.ProfileUser.UserId)
.Where(c => c.Type == CaseType.UserDisableComments)
.Where(c => c.DismissedAt == null)
.AnyAsync();
return this.Page();
}
}

View file

@ -0,0 +1,101 @@
@page "/user/{userId:int}/privacy"
@using LBPUnion.ProjectLighthouse.Extensions
@using LBPUnion.ProjectLighthouse.Localization.StringLists
@using LBPUnion.ProjectLighthouse.Types.Entities.Profile
@using LBPUnion.ProjectLighthouse.Types.Users
@model LBPUnion.ProjectLighthouse.Servers.Website.Pages.UserPrivacyPage
@{
Layout = "Layouts/BaseLayout";
Model.Title = Model.Translate(ProfileStrings.Title, Model.ProfileUser!.Username);
Model.ShowTitleInPage = false;
bool isMobile = Request.IsMobile();
}
<div class="@(isMobile ? "" : "ui left aligned grid")">
<div class="column">
<h1>@Model.ProfileUser.Username's Privacy Settings</h1>
<form method="POST" class="ui form center aligned" action="/user/@Model.ProfileUser.UserId/privacy">
@Html.AntiForgeryToken()
<div class="ui yellow segment">
<h2><i class="ui icon comment alternate"></i> Profile Privacy</h2>
<div class="field">
<label style="text-align: left" for="profilePrivacyLevel">Privacy Level</label>
<select class="ui fluid dropdown" type="text" name="profilePrivacyLevel" id="profilePrivacyLevel">
@foreach (PrivacyType type in Enum.GetValues(typeof(PrivacyType)))
{
<option value="@type.ToSerializedString()" @(Model.ProfileUser.ProfileVisibility == type ? "selected" : "")>
@Model.Translate(type.ToReadableString(), "profile")
</option>
}
</select>
</div>
<div class="field">
<label style="text-align: left" for="profileCommentsEnabled">
Comments
@if (Model.CommentsDisabledByModerator)
{
<small class="ui red text">Locked by a moderator</small>
}
</label>
<select class="ui fluid dropdown @(Model.CommentsDisabledByModerator ? "disabled" : "")" type="text" name="profileCommentsEnabled" id="profileCommentsEnabled">
<option value="true" @(Model.ProfileUser.CommentsEnabled ? "selected" : "")>
@Model.Translate(PrivacyStrings.EnableComments)
</option>
<option value="false" @(!Model.ProfileUser.CommentsEnabled ? "selected" : "")>
@Model.Translate(PrivacyStrings.DisableComments)
</option>
</select>
</div>
<h2><i class="ui icon play"></i> Level Privacy</h2>
<div class="field">
<label style="text-align: left" for="slotPrivacyLevel">Privacy Level</label>
<select class="ui fluid dropdown" type="text" name="slotPrivacyLevel" id="slotPrivacyLevel">
@foreach (PrivacyType type in Enum.GetValues(typeof(PrivacyType)))
{
<option value="@type.ToSerializedString()" @(Model.ProfileUser.LevelVisibility == type ? "selected" : "")>
@Model.Translate(type.ToReadableString(), "levels")
</option>
}
</select>
</div>
<div class="ui divider"></div>
<button type="submit" class="ui button green" tabindex="0">Save Changes</button>
<a class="ui button red" href="/user/@Model.ProfileUser.UserId">Discard Changes</a>
</div>
</form>
<div class="ui red segment">
<h2><i class="user alternate slash icon"></i> Blocked Users</h2>
@if (Model.BlockedUsers.Count == 0)
{
<span>@Model.Translate(PrivacyStrings.NoBlockedUsers)</span>
}
else
{
<p>@Model.Translate(PrivacyStrings.BlockedUsers, Model.BlockedUsers.Count)</p>
}
@foreach (UserEntity user in Model.BlockedUsers)
{
<div class="ui segment">
@await Html.PartialAsync("Partials/UserCardPartial", user, new ViewDataDictionary(ViewData)
{
{
"ShowLink", true
},
{
"IsMobile", isMobile
},
{
"Language", Model.GetLanguage()
},
{
"TimeZone", Model.GetTimeZone()
},
})
</div>
}
</div>
</div>
</div>

View file

@ -0,0 +1,78 @@
using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Servers.Website.Pages.Layouts;
using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
using LBPUnion.ProjectLighthouse.Types.Moderation.Cases;
using LBPUnion.ProjectLighthouse.Types.Users;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
namespace LBPUnion.ProjectLighthouse.Servers.Website.Pages;
public class UserPrivacyPage : BaseLayout
{
public List<UserEntity> BlockedUsers = new();
public bool CommentsDisabledByModerator;
public UserEntity? ProfileUser;
public UserPrivacyPage(DatabaseContext database) : base(database)
{ }
public async Task<IActionResult> OnGet([FromRoute] int userId)
{
this.ProfileUser = await this.Database.Users.FirstOrDefaultAsync(u => u.UserId == userId);
if (this.ProfileUser == null) return this.NotFound();
if (this.User == null) return this.Redirect("~/login");
if (this.User != this.ProfileUser) return this.Redirect("~/user/" + userId);
this.BlockedUsers = await this.Database.BlockedProfiles.Where(b => b.UserId == this.ProfileUser.UserId)
.Select(b => b.BlockedUser)
.ToListAsync();
this.CommentsDisabledByModerator = await this.Database.Cases.Where(c => c.AffectedId == this.ProfileUser.UserId)
.Where(c => c.Type == CaseType.UserDisableComments)
.Where(c => c.DismissedAt == null)
.AnyAsync();
return this.Page();
}
public async Task<IActionResult> OnPost([FromRoute] int userId, [FromForm] string profilePrivacyLevel, [FromForm] bool profileCommentsEnabled, [FromForm] string slotPrivacyLevel)
{
this.ProfileUser = await this.Database.Users.FirstOrDefaultAsync(u => u.UserId == userId);
if (this.ProfileUser == null) return this.NotFound();
if (this.User == null) return this.Redirect("~/login");
if (this.User != this.ProfileUser) return this.Redirect("~/user/" + userId);
this.CommentsDisabledByModerator = await this.Database.Cases.Where(c => c.AffectedId == this.ProfileUser.UserId)
.Where(c => c.Type == CaseType.UserDisableComments)
.Where(c => c.DismissedAt == null)
.AnyAsync();
if (!this.CommentsDisabledByModerator)
{
this.ProfileUser.CommentsEnabled = profileCommentsEnabled;
}
this.ProfileUser.ProfileVisibility = PrivacyTypeFromString(profilePrivacyLevel);
this.ProfileUser.LevelVisibility = PrivacyTypeFromString(slotPrivacyLevel);
await this.Database.SaveChangesAsync();
return this.Redirect($"~/user/{userId}");
}
private static PrivacyType PrivacyTypeFromString(string type)
{
return type switch
{
"all" => PrivacyType.All,
"psn" => PrivacyType.PSN,
"game" => PrivacyType.Game,
_ => PrivacyType.All,
};
}
}

View file

@ -44,7 +44,7 @@ function onSubmit(e){
<div class="@(isMobile ? "" : "ui center aligned grid")">
<div class="eight wide column">
<div class="ui blue segment">
<h1><i class="cog icon"></i>@Model.ProfileUser.Username's Settings</h1>
<h1><i class="cog icon"></i>@Model.ProfileUser.Username's Profile Settings</h1>
<div class="ui divider"></div>
<form id="form" method="POST" class="ui form center aligned" action="/user/@Model.ProfileUser.UserId/settings" onsubmit="onSubmit(event)">
@Html.AntiForgeryToken()

View file

@ -37,8 +37,8 @@ public class UsersPage : BaseLayout
if (this.PageNumber < 0 || this.PageNumber >= this.PageAmount) return this.Redirect($"/users/{Math.Clamp(this.PageNumber, 0, this.PageAmount - 1)}");
this.Users = await this.Database.Users.Where(u => u.PermissionLevel != PermissionLevel.Banned && u.Username.Contains(this.SearchValue))
.Where(u => u.ProfileVisibility == PrivacyType.All) // TODO: change check for when user is logged in
this.Users = await this.Database.Users.Where(u => u.Username.Contains(this.SearchValue))
.Where(u => u.PermissionLevel != PermissionLevel.Banned)
.OrderByDescending(b => b.UserId)
.Skip(pageNumber * ServerStatics.PageSize)
.Take(ServerStatics.PageSize)

View file

@ -1,3 +1,6 @@
using LBPUnion.ProjectLighthouse.Localization;
using LBPUnion.ProjectLighthouse.Localization.StringLists;
namespace LBPUnion.ProjectLighthouse.Types.Users;
/// <summary>
@ -21,6 +24,17 @@ public enum PrivacyType
public static class PrivacyTypeExtensions
{
public static TranslatableString ToReadableString(this PrivacyType type)
{
return type switch
{
PrivacyType.All => PrivacyStrings.PrivacyAll,
PrivacyType.PSN => PrivacyStrings.PrivacyPSN,
PrivacyType.Game => PrivacyStrings.PrivacyGame,
_ => null,
};
}
public static string ToSerializedString(this PrivacyType type)
=> type.ToString().ToLower();
@ -34,4 +48,15 @@ public static class PrivacyTypeExtensions
_ => null,
};
}
public static bool CanAccess(this PrivacyType type, bool authenticated, bool owner)
{
return type switch
{
PrivacyType.All => true,
PrivacyType.PSN => authenticated,
PrivacyType.Game => authenticated && owner,
_ => false,
};
}
}