mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-03 17:38:22 +00:00
* 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>
132 lines
No EOL
5.2 KiB
C#
132 lines
No EOL
5.2 KiB
C#
#nullable enable
|
|
using LBPUnion.ProjectLighthouse.Configuration;
|
|
using LBPUnion.ProjectLighthouse.Database;
|
|
using LBPUnion.ProjectLighthouse.Servers.Website.Pages.Layouts;
|
|
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;
|
|
|
|
namespace LBPUnion.ProjectLighthouse.Servers.Website.Pages;
|
|
|
|
public class UserPage : BaseLayout
|
|
{
|
|
public Dictionary<CommentEntity, RatedCommentEntity?> Comments = new();
|
|
|
|
public bool CommentsEnabled;
|
|
public bool CommentsDisabledByModerator;
|
|
|
|
public bool IsProfileUserHearted;
|
|
|
|
public bool IsProfileUserBlocked;
|
|
|
|
public List<PhotoEntity>? Photos;
|
|
public List<SlotEntity>? Slots;
|
|
|
|
public List<SlotEntity>? HeartedSlots;
|
|
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
|
|
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)
|
|
.ThenInclude(ps => ps.User)
|
|
.OrderByDescending(p => p.Timestamp)
|
|
.Where(p => p.CreatorId == userId)
|
|
.Take(6)
|
|
.ToListAsync();
|
|
|
|
this.Slots = await this.Database.Slots.Include(p => p.Creator)
|
|
.OrderByDescending(s => s.LastUpdated)
|
|
.Where(p => p.CreatorId == userId)
|
|
.Take(10)
|
|
.ToListAsync();
|
|
|
|
if (this.User == this.ProfileUser)
|
|
{
|
|
this.QueuedSlots = await this.Database.QueuedLevels.Include(h => h.Slot)
|
|
.Where(q => this.User != null && q.UserId == this.User.UserId)
|
|
.OrderByDescending(q => q.QueuedLevelId)
|
|
.Select(q => q.Slot)
|
|
.Where(s => s.Type == SlotType.User)
|
|
.Take(10)
|
|
.ToListAsync();
|
|
this.HeartedSlots = await this.Database.HeartedLevels.Include(h => h.Slot)
|
|
.Where(h => this.User != null && h.UserId == this.User.UserId)
|
|
.OrderByDescending(h => h.HeartedLevelId)
|
|
.Select(h => h.Slot)
|
|
.Where(s => s.Type == SlotType.User)
|
|
.Take(10)
|
|
.ToListAsync();
|
|
}
|
|
|
|
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();
|
|
|
|
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);
|
|
}
|
|
else
|
|
{
|
|
this.Comments = new Dictionary<CommentEntity, RatedCommentEntity?>();
|
|
}
|
|
|
|
if (this.User == null) return this.Page();
|
|
|
|
foreach (KeyValuePair<CommentEntity, RatedCommentEntity?> kvp in this.Comments)
|
|
{
|
|
RatedCommentEntity? reaction = await this.Database.RatedComments.Where(r => r.CommentId == kvp.Key.CommentId)
|
|
.Where(r => r.UserId == this.User.UserId)
|
|
.FirstOrDefaultAsync();
|
|
this.Comments[kvp.Key] = reaction;
|
|
}
|
|
|
|
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();
|
|
}
|
|
} |