mirror of https://github.com/jellyfin/jellyfin.git
Convert some code in UserManager to async
This commit is contained in:
parent
e37805e82e
commit
72263613d0
|
@ -109,7 +109,7 @@ namespace Jellyfin.Api.Controllers
|
||||||
var userDataPath = Path.Combine(_serverConfigurationManager.ApplicationPaths.UserConfigurationDirectoryPath, user.Username);
|
var userDataPath = Path.Combine(_serverConfigurationManager.ApplicationPaths.UserConfigurationDirectoryPath, user.Username);
|
||||||
if (user.ProfileImage != null)
|
if (user.ProfileImage != null)
|
||||||
{
|
{
|
||||||
_userManager.ClearProfileImage(user);
|
await _userManager.ClearProfileImageAsync(user).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
user.ProfileImage = new Data.Entities.ImageInfo(Path.Combine(userDataPath, "profile" + MimeTypes.ToExtension(mimeType)));
|
user.ProfileImage = new Data.Entities.ImageInfo(Path.Combine(userDataPath, "profile" + MimeTypes.ToExtension(mimeType)));
|
||||||
|
@ -138,7 +138,7 @@ namespace Jellyfin.Api.Controllers
|
||||||
[SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "index", Justification = "Imported from ServiceStack")]
|
[SuppressMessage("Microsoft.Performance", "CA1801:ReviewUnusedParameters", MessageId = "index", Justification = "Imported from ServiceStack")]
|
||||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||||
[ProducesResponseType(StatusCodes.Status403Forbidden)]
|
[ProducesResponseType(StatusCodes.Status403Forbidden)]
|
||||||
public ActionResult DeleteUserImage(
|
public async Task<ActionResult> DeleteUserImage(
|
||||||
[FromRoute, Required] Guid userId,
|
[FromRoute, Required] Guid userId,
|
||||||
[FromRoute, Required] ImageType imageType,
|
[FromRoute, Required] ImageType imageType,
|
||||||
[FromRoute] int? index = null)
|
[FromRoute] int? index = null)
|
||||||
|
@ -158,7 +158,7 @@ namespace Jellyfin.Api.Controllers
|
||||||
_logger.LogError(e, "Error deleting user profile image:");
|
_logger.LogError(e, "Error deleting user profile image:");
|
||||||
}
|
}
|
||||||
|
|
||||||
_userManager.ClearProfileImage(user);
|
await _userManager.ClearProfileImageAsync(user).ConfigureAwait(false);
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -381,17 +381,13 @@ namespace Jellyfin.Api.Controllers
|
||||||
|
|
||||||
var user = _userManager.GetUserById(userId);
|
var user = _userManager.GetUserById(userId);
|
||||||
|
|
||||||
if (string.Equals(user.Username, updateUser.Name, StringComparison.Ordinal))
|
if (!string.Equals(user.Username, updateUser.Name, StringComparison.Ordinal))
|
||||||
{
|
|
||||||
await _userManager.UpdateUserAsync(user).ConfigureAwait(false);
|
|
||||||
_userManager.UpdateConfiguration(user.Id, updateUser.Configuration);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
await _userManager.RenameUser(user, updateUser.Name).ConfigureAwait(false);
|
await _userManager.RenameUser(user, updateUser.Name).ConfigureAwait(false);
|
||||||
_userManager.UpdateConfiguration(updateUser.Id, updateUser.Configuration);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await _userManager.UpdateConfigurationAsync(user.Id, updateUser.Configuration).ConfigureAwait(false);
|
||||||
|
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -409,7 +405,7 @@ namespace Jellyfin.Api.Controllers
|
||||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||||
[ProducesResponseType(StatusCodes.Status403Forbidden)]
|
[ProducesResponseType(StatusCodes.Status403Forbidden)]
|
||||||
public ActionResult UpdateUserPolicy(
|
public async Task<ActionResult> UpdateUserPolicy(
|
||||||
[FromRoute, Required] Guid userId,
|
[FromRoute, Required] Guid userId,
|
||||||
[FromBody] UserPolicy newPolicy)
|
[FromBody] UserPolicy newPolicy)
|
||||||
{
|
{
|
||||||
|
@ -447,7 +443,7 @@ namespace Jellyfin.Api.Controllers
|
||||||
_sessionManager.RevokeUserTokens(user.Id, currentToken);
|
_sessionManager.RevokeUserTokens(user.Id, currentToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
_userManager.UpdatePolicy(userId, newPolicy);
|
await _userManager.UpdatePolicyAsync(userId, newPolicy).ConfigureAwait(false);
|
||||||
|
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
@ -464,7 +460,7 @@ namespace Jellyfin.Api.Controllers
|
||||||
[Authorize(Policy = Policies.DefaultAuthorization)]
|
[Authorize(Policy = Policies.DefaultAuthorization)]
|
||||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||||
[ProducesResponseType(StatusCodes.Status403Forbidden)]
|
[ProducesResponseType(StatusCodes.Status403Forbidden)]
|
||||||
public ActionResult UpdateUserConfiguration(
|
public async Task<ActionResult> UpdateUserConfiguration(
|
||||||
[FromRoute, Required] Guid userId,
|
[FromRoute, Required] Guid userId,
|
||||||
[FromBody] UserConfiguration userConfig)
|
[FromBody] UserConfiguration userConfig)
|
||||||
{
|
{
|
||||||
|
@ -473,7 +469,7 @@ namespace Jellyfin.Api.Controllers
|
||||||
return Forbid("User configuration update not allowed");
|
return Forbid("User configuration update not allowed");
|
||||||
}
|
}
|
||||||
|
|
||||||
_userManager.UpdateConfiguration(userId, userConfig);
|
await _userManager.UpdateConfigurationAsync(userId, userConfig).ConfigureAwait(false);
|
||||||
|
|
||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
|
|
@ -434,9 +434,7 @@ namespace Jellyfin.Server.Implementations.Users
|
||||||
|
|
||||||
if (authenticationProvider is IHasNewUserPolicy hasNewUserPolicy && user != null)
|
if (authenticationProvider is IHasNewUserPolicy hasNewUserPolicy && user != null)
|
||||||
{
|
{
|
||||||
UpdatePolicy(user.Id, hasNewUserPolicy.GetNewUserPolicy());
|
await UpdatePolicyAsync(user.Id, hasNewUserPolicy.GetNewUserPolicy()).ConfigureAwait(false);
|
||||||
|
|
||||||
await UpdateUserAsync(user).ConfigureAwait(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -615,9 +613,9 @@ namespace Jellyfin.Server.Implementations.Users
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public void UpdateConfiguration(Guid userId, UserConfiguration config)
|
public async Task UpdateConfigurationAsync(Guid userId, UserConfiguration config)
|
||||||
{
|
{
|
||||||
using var dbContext = _dbProvider.CreateContext();
|
await using var dbContext = _dbProvider.CreateContext();
|
||||||
var user = dbContext.Users
|
var user = dbContext.Users
|
||||||
.Include(u => u.Permissions)
|
.Include(u => u.Permissions)
|
||||||
.Include(u => u.Preferences)
|
.Include(u => u.Preferences)
|
||||||
|
@ -644,13 +642,13 @@ namespace Jellyfin.Server.Implementations.Users
|
||||||
user.SetPreference(PreferenceKind.LatestItemExcludes, config.LatestItemsExcludes);
|
user.SetPreference(PreferenceKind.LatestItemExcludes, config.LatestItemsExcludes);
|
||||||
|
|
||||||
dbContext.Update(user);
|
dbContext.Update(user);
|
||||||
dbContext.SaveChanges();
|
await dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public void UpdatePolicy(Guid userId, UserPolicy policy)
|
public async Task UpdatePolicyAsync(Guid userId, UserPolicy policy)
|
||||||
{
|
{
|
||||||
using var dbContext = _dbProvider.CreateContext();
|
await using var dbContext = _dbProvider.CreateContext();
|
||||||
var user = dbContext.Users
|
var user = dbContext.Users
|
||||||
.Include(u => u.Permissions)
|
.Include(u => u.Permissions)
|
||||||
.Include(u => u.Preferences)
|
.Include(u => u.Preferences)
|
||||||
|
@ -715,15 +713,15 @@ namespace Jellyfin.Server.Implementations.Users
|
||||||
user.SetPreference(PreferenceKind.EnableContentDeletionFromFolders, policy.EnableContentDeletionFromFolders);
|
user.SetPreference(PreferenceKind.EnableContentDeletionFromFolders, policy.EnableContentDeletionFromFolders);
|
||||||
|
|
||||||
dbContext.Update(user);
|
dbContext.Update(user);
|
||||||
dbContext.SaveChanges();
|
await dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public void ClearProfileImage(User user)
|
public async Task ClearProfileImageAsync(User user)
|
||||||
{
|
{
|
||||||
using var dbContext = _dbProvider.CreateContext();
|
await using var dbContext = _dbProvider.CreateContext();
|
||||||
dbContext.Remove(user.ProfileImage);
|
dbContext.Remove(user.ProfileImage);
|
||||||
dbContext.SaveChanges();
|
await dbContext.SaveChangesAsync().ConfigureAwait(false);
|
||||||
user.ProfileImage = null;
|
user.ProfileImage = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -158,7 +158,8 @@ namespace MediaBrowser.Controller.Library
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userId">The user's Id.</param>
|
/// <param name="userId">The user's Id.</param>
|
||||||
/// <param name="config">The request containing the new user configuration.</param>
|
/// <param name="config">The request containing the new user configuration.</param>
|
||||||
void UpdateConfiguration(Guid userId, UserConfiguration config);
|
/// <returns>A task representing the update.</returns>
|
||||||
|
Task UpdateConfigurationAsync(Guid userId, UserConfiguration config);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This method updates the user's policy.
|
/// This method updates the user's policy.
|
||||||
|
@ -167,12 +168,14 @@ namespace MediaBrowser.Controller.Library
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userId">The user's Id.</param>
|
/// <param name="userId">The user's Id.</param>
|
||||||
/// <param name="policy">The request containing the new user policy.</param>
|
/// <param name="policy">The request containing the new user policy.</param>
|
||||||
void UpdatePolicy(Guid userId, UserPolicy policy);
|
/// <returns>A task representing the update.</returns>
|
||||||
|
Task UpdatePolicyAsync(Guid userId, UserPolicy policy);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Clears the user's profile image.
|
/// Clears the user's profile image.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="user">The user.</param>
|
/// <param name="user">The user.</param>
|
||||||
void ClearProfileImage(User user);
|
/// <returns>A task representing the clearing of the profile image.</returns>
|
||||||
|
Task ClearProfileImageAsync(User user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue