Deprecate HasPassword property on UserDto

This commit is contained in:
Niels van Velzen 2025-10-05 10:59:10 +02:00
parent 288640a5d0
commit 0fb6d930e1
6 changed files with 7 additions and 51 deletions

View File

@ -59,7 +59,7 @@ namespace Jellyfin.Server.Implementations.Users
} }
// As long as jellyfin supports password-less users, we need this little block here to accommodate // As long as jellyfin supports password-less users, we need this little block here to accommodate
if (!HasPassword(resolvedUser) && string.IsNullOrEmpty(password)) if (string.IsNullOrEmpty(resolvedUser.Password) && string.IsNullOrEmpty(password))
{ {
return Task.FromResult(new ProviderAuthenticationResult return Task.FromResult(new ProviderAuthenticationResult
{ {
@ -93,10 +93,6 @@ namespace Jellyfin.Server.Implementations.Users
}); });
} }
/// <inheritdoc />
public bool HasPassword(User user)
=> !string.IsNullOrEmpty(user?.Password);
/// <inheritdoc /> /// <inheritdoc />
public Task ChangePassword(User user, string newPassword) public Task ChangePassword(User user, string newPassword)
{ {

View File

@ -21,12 +21,6 @@ namespace Jellyfin.Server.Implementations.Users
throw new AuthenticationException("User Account cannot login with this provider. The Normal provider for this user cannot be found"); throw new AuthenticationException("User Account cannot login with this provider. The Normal provider for this user cannot be found");
} }
/// <inheritdoc />
public bool HasPassword(User user)
{
return true;
}
/// <inheritdoc /> /// <inheritdoc />
public Task ChangePassword(User user, string newPassword) public Task ChangePassword(User user, string newPassword)
{ {

View File

@ -306,15 +306,12 @@ namespace Jellyfin.Server.Implementations.Users
/// <inheritdoc/> /// <inheritdoc/>
public UserDto GetUserDto(User user, string? remoteEndPoint = null) public UserDto GetUserDto(User user, string? remoteEndPoint = null)
{ {
var hasPassword = GetAuthenticationProvider(user).HasPassword(user);
var castReceiverApplications = _serverConfigurationManager.Configuration.CastReceiverApplications; var castReceiverApplications = _serverConfigurationManager.Configuration.CastReceiverApplications;
return new UserDto return new UserDto
{ {
Name = user.Username, Name = user.Username,
Id = user.Id, Id = user.Id,
ServerId = _appHost.SystemId, ServerId = _appHost.SystemId,
HasPassword = hasPassword,
HasConfiguredPassword = hasPassword,
EnableAutoLogin = user.EnableAutoLogin, EnableAutoLogin = user.EnableAutoLogin,
LastLoginDate = user.LastLoginDate, LastLoginDate = user.LastLoginDate,
LastActivityDate = user.LastActivityDate, LastActivityDate = user.LastActivityDate,

View File

@ -14,8 +14,6 @@ namespace MediaBrowser.Controller.Authentication
Task<ProviderAuthenticationResult> Authenticate(string username, string password); Task<ProviderAuthenticationResult> Authenticate(string username, string password);
bool HasPassword(User user);
Task ChangePassword(User user, string newPassword); Task ChangePassword(User user, string newPassword);
} }

View File

@ -1,5 +1,6 @@
#nullable disable #nullable disable
using System; using System;
using System.ComponentModel;
using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Users; using MediaBrowser.Model.Users;
@ -54,20 +55,22 @@ namespace MediaBrowser.Model.Dto
/// Gets or sets a value indicating whether this instance has password. /// Gets or sets a value indicating whether this instance has password.
/// </summary> /// </summary>
/// <value><c>true</c> if this instance has password; otherwise, <c>false</c>.</value> /// <value><c>true</c> if this instance has password; otherwise, <c>false</c>.</value>
public bool HasPassword { get; set; } [Obsolete("This information is no longer provided")]
public bool? HasPassword { get; set; } = true;
/// <summary> /// <summary>
/// Gets or sets a value indicating whether this instance has configured password. /// Gets or sets a value indicating whether this instance has configured password.
/// </summary> /// </summary>
/// <value><c>true</c> if this instance has configured password; otherwise, <c>false</c>.</value> /// <value><c>true</c> if this instance has configured password; otherwise, <c>false</c>.</value>
public bool HasConfiguredPassword { get; set; } [Obsolete("This is always true")]
public bool? HasConfiguredPassword { get; set; } = true;
/// <summary> /// <summary>
/// Gets or sets a value indicating whether this instance has configured easy password. /// Gets or sets a value indicating whether this instance has configured easy password.
/// </summary> /// </summary>
/// <value><c>true</c> if this instance has configured easy password; otherwise, <c>false</c>.</value> /// <value><c>true</c> if this instance has configured easy password; otherwise, <c>false</c>.</value>
[Obsolete("Easy Password has been replaced with Quick Connect")] [Obsolete("Easy Password has been replaced with Quick Connect")]
public bool HasConfiguredEasyPassword { get; set; } public bool? HasConfiguredEasyPassword { get; set; } = false;
/// <summary> /// <summary>
/// Gets or sets whether async login is enabled or not. /// Gets or sets whether async login is enabled or not.

View File

@ -61,7 +61,6 @@ namespace Jellyfin.Server.Integration.Tests.Controllers
var users = await response.Content.ReadFromJsonAsync<UserDto[]>(_jsonOptions); var users = await response.Content.ReadFromJsonAsync<UserDto[]>(_jsonOptions);
Assert.NotNull(users); Assert.NotNull(users);
Assert.Single(users); Assert.Single(users);
Assert.False(users![0].HasConfiguredPassword);
} }
[Fact] [Fact]
@ -92,8 +91,6 @@ namespace Jellyfin.Server.Integration.Tests.Controllers
Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal(HttpStatusCode.OK, response.StatusCode);
var user = await response.Content.ReadFromJsonAsync<UserDto>(_jsonOptions); var user = await response.Content.ReadFromJsonAsync<UserDto>(_jsonOptions);
Assert.Equal(TestUsername, user!.Name); Assert.Equal(TestUsername, user!.Name);
Assert.False(user.HasPassword);
Assert.False(user.HasConfiguredPassword);
_testUserId = user.Id; _testUserId = user.Id;
@ -149,35 +146,6 @@ namespace Jellyfin.Server.Integration.Tests.Controllers
using var response = await UpdateUserPassword(client, _testUserId, createRequest); using var response = await UpdateUserPassword(client, _testUserId, createRequest);
Assert.Equal(HttpStatusCode.NoContent, response.StatusCode); Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);
var users = await JsonSerializer.DeserializeAsync<UserDto[]>(
await client.GetStreamAsync("Users"), _jsonOptions);
var user = users!.First(x => x.Id.Equals(_testUserId));
Assert.True(user.HasPassword);
Assert.True(user.HasConfiguredPassword);
}
[Fact]
[Priority(2)]
public async Task UpdateUserPassword_Empty_RemoveSetPassword()
{
var client = _factory.CreateClient();
client.DefaultRequestHeaders.AddAuthHeader(_accessToken!);
var createRequest = new UpdateUserPassword()
{
CurrentPw = "4randomPa$$word",
};
using var response = await UpdateUserPassword(client, _testUserId, createRequest);
Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);
var users = await JsonSerializer.DeserializeAsync<UserDto[]>(
await client.GetStreamAsync("Users"), _jsonOptions);
var user = users!.First(x => x.Id.Equals(_testUserId));
Assert.False(user.HasPassword);
Assert.False(user.HasConfiguredPassword);
} }
} }
} }