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,6 +58,16 @@
@await Model.Slot.ToHtml(Html, ViewData, Model.User, $"~/slot/{Model.Slot?.SlotId}", language, timeZone, isMobile)
<br>
@if (!Model.CanViewSlot)
{
<div class="ui red segment">
<p>
<i>The creator's privacy settings prevent you from viewing this page.</i>
</p>
</div>
}
else
{
<div class="@(isMobile ? "" : "ui grid")">
<div class="eight wide column">
<div class="ui blue segment">
@ -104,12 +114,8 @@
<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";
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">
@ -134,7 +140,11 @@
<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 }, })
{
{
"PageOwner", Model.Slot?.CreatorId
},
})
</div>
<div class="lh-content" id="lh-photos">
<div class="ui purple segment" id="photos">
@ -175,12 +185,12 @@
</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))
@await Html.PartialAsync("Partials/LeaderboardPartial", ViewData.WithLang(language).WithTime(timeZone).CanDelete(Model.User?.IsModerator ?? false))
</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

@ -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,6 +113,8 @@
{
<br/>
}
@if (Model.CanViewProfile)
{
<div class="eight wide column">
<div class="ui blue segment">
<h2>@Model.Translate(ProfileStrings.Biography)</h2>
@ -133,16 +142,23 @@
{
<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";
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">
@ -178,13 +194,19 @@
@if (Model.ProfileUser.IsBanned)
{
<div class="ui yellow segment" id="comments">
<p><i>Comments are disabled because the user is banned.</i></p>
<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}, })
{
{
"PageOwner", Model.ProfileUser.UserId
},
})
}
</div>
<div class="lh-content" id="lh-photos">
@ -213,6 +235,16 @@
</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)
{
@ -225,6 +257,7 @@
</div>
}
</div>
}
</div>
<div class="lh-content" id="lh-playlists">
<div class="ui purple segment">
@ -272,6 +305,7 @@
}
</div>
</div>
}
@if (Model.User != null && Model.User.IsModerator)
{
@ -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)

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,6 +31,10 @@ public class UserPage : BaseLayout
public List<SlotEntity>? QueuedSlots;
public UserEntity? ProfileUser;
public bool CanViewProfile;
public bool CanViewSlots;
public UserPage(DatabaseContext database) : base(database)
{ }
@ -37,27 +43,12 @@ public class UserPage : BaseLayout
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,12 +82,15 @@ 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
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();
@ -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,
};
}
}