Nullify User

This commit is contained in:
Jordan Dominion
2023-12-18 23:19:51 -05:00
parent 052b0b9e26
commit 02e5e86f21
6 changed files with 17 additions and 16 deletions
@@ -263,13 +263,13 @@ namespace Tgstation.Server.Host.Controllers
return Unauthorized();
query = query.Where(
x => x.OAuthConnections.Any(
x => x.OAuthConnections!.Any(
y => y.Provider == oAuthProvider
&& y.ExternalUserId == externalUserId));
}
else
{
var canonicalUserName = Models.User.CanonicalizeName(ApiHeaders.Username);
var canonicalUserName = Models.User.CanonicalizeName(ApiHeaders.Username!);
if (canonicalUserName == Models.User.CanonicalizeName(Models.User.TgsSystemUserName))
return Unauthorized();
@@ -153,7 +153,7 @@ namespace Tgstation.Server.Host.Jobs
logger.LogTrace("RefreshHubGroups");
var permissionSetUsers = await databaseContext
.Users
.Where(x => x.PermissionSet.Id == permissionSetId)
.Where(x => x.PermissionSet!.Id == permissionSetId)
.ToListAsync(cancellationToken);
var allInstanceIds = await databaseContext
.Instances
+8 -10
View File
@@ -6,8 +6,6 @@ using System.Linq;
using Tgstation.Server.Api.Models;
using Tgstation.Server.Api.Models.Response;
#nullable disable
namespace Tgstation.Server.Host.Models
{
/// <inheritdoc cref="Api.Models.Internal.UserModelBase" />
@@ -21,17 +19,17 @@ namespace Tgstation.Server.Host.Models
/// <summary>
/// The hash of the user's password.
/// </summary>
public string PasswordHash { get; set; }
public string? PasswordHash { get; set; }
/// <summary>
/// See <see cref="UserResponse"/>.
/// </summary>
public User CreatedBy { get; set; }
public User? CreatedBy { get; set; }
/// <summary>
/// The <see cref="UserGroup"/> the <see cref="User"/> belongs to, if any.
/// </summary>
public UserGroup Group { get; set; }
public UserGroup? Group { get; set; }
/// <summary>
/// The ID of the <see cref="User"/>'s <see cref="UserGroup"/>.
@@ -41,14 +39,14 @@ namespace Tgstation.Server.Host.Models
/// <summary>
/// The <see cref="PermissionSet"/> the <see cref="User"/> has, if any.
/// </summary>
public PermissionSet PermissionSet { get; set; }
public PermissionSet? PermissionSet { get; set; }
/// <summary>
/// The uppercase invariant of <see cref="UserName.Name"/>.
/// </summary>
[Required]
[StringLength(Limits.MaximumIndexableStringLength, MinimumLength = 1)]
public string CanonicalName { get; set; }
public string? CanonicalName { get; set; }
/// <summary>
/// When <see cref="PasswordHash"/> was last changed.
@@ -58,17 +56,17 @@ namespace Tgstation.Server.Host.Models
/// <summary>
/// <see cref="User"/>s created by this <see cref="User"/>.
/// </summary>
public ICollection<User> CreatedUsers { get; set; }
public ICollection<User>? CreatedUsers { get; set; }
/// <summary>
/// The <see cref="TestMerge"/>s made by the <see cref="User"/>.
/// </summary>
public ICollection<TestMerge> TestMerges { get; set; }
public ICollection<TestMerge>? TestMerges { get; set; }
/// <summary>
/// The <see cref="TestMerge"/>s made by the <see cref="User"/>.
/// </summary>
public ICollection<OAuthConnection> OAuthConnections { get; set; }
public ICollection<OAuthConnection>? OAuthConnections { get; set; }
/// <summary>
/// Change a <see cref="UserName.Name"/> into a <see cref="CanonicalName"/>.
@@ -56,7 +56,7 @@ namespace Tgstation.Server.Host.Security
if (systemIdentity == null && User.SystemIdentifier != null)
throw new ArgumentNullException(nameof(systemIdentity));
permissionSet = user.PermissionSet
?? user.Group.PermissionSet
?? user.Group!.PermissionSet
?? throw new ArgumentException("No PermissionSet provider", nameof(user));
InstancePermissionSet = instanceUser;
SystemIdentity = systemIdentity;
@@ -88,7 +88,7 @@ namespace Tgstation.Server.Host.Security
.Include(x => x.CreatedBy)
.Include(x => x.PermissionSet)
.Include(x => x.Group)
.ThenInclude(x => x.PermissionSet)
.ThenInclude(x => x!.PermissionSet)
.Include(x => x.OAuthConnections)
.FirstOrDefaultAsync(cancellationToken);
if (user == default)
@@ -111,7 +111,7 @@ namespace Tgstation.Server.Host.Security
systemIdentity = null;
}
var userPermissionSet = user.PermissionSet ?? user.Group.PermissionSet;
var userPermissionSet = user.PermissionSet ?? user.Group!.PermissionSet;
try
{
InstancePermissionSet? instancePermissionSet = null;
@@ -55,6 +55,9 @@ namespace Tgstation.Server.Host.Security
ArgumentNullException.ThrowIfNull(user);
ArgumentNullException.ThrowIfNull(password);
if (user.PasswordHash == null)
throw new ArgumentException("user must have PasswordHash!", nameof(user));
var result = passwordHasher.VerifyHashedPassword(user, user.PasswordHash, password);
switch (result)
{