Apply review suggestions and fix bug

pull/3423/head
Patrick Barron 5 years ago
parent fa80f84f26
commit 98142613e8

@ -420,10 +420,7 @@ namespace Jellyfin.Data.Entities
/// <returns>A string array containing the user's preferences.</returns>
public string[] GetPreference(PreferenceKind preference)
{
var val = Preferences
.Where(p => p.Kind == preference)
.Select(p => p.Value)
.First();
var val = Preferences.First(p => p.Kind == preference).Value;
return Equals(val, string.Empty) ? Array.Empty<string>() : val.Split(Delimiter);
}

@ -84,24 +84,10 @@ namespace Jellyfin.Server.Implementations.Users
public event EventHandler<GenericEventArgs<User>> OnUserLockedOut;
/// <inheritdoc/>
public IEnumerable<User> Users
{
get
{
var dbContext = _dbProvider.CreateContext();
return dbContext.Users;
}
}
public IEnumerable<User> Users => _dbProvider.CreateContext().Users;
/// <inheritdoc/>
public IEnumerable<Guid> UsersIds
{
get
{
var dbContext = _dbProvider.CreateContext();
return dbContext.Users.Select(u => u.Id);
}
}
public IEnumerable<Guid> UsersIds => _dbProvider.CreateContext().Users.Select(u => u.Id);
/// <inheritdoc/>
public User GetUserById(Guid id)
@ -111,9 +97,7 @@ namespace Jellyfin.Server.Implementations.Users
throw new ArgumentException("Guid can't be empty", nameof(id));
}
var dbContext = _dbProvider.CreateContext();
return dbContext.Users.Find(id);
return _dbProvider.CreateContext().Users.Find(id);
}
/// <inheritdoc/>
@ -124,11 +108,9 @@ namespace Jellyfin.Server.Implementations.Users
throw new ArgumentException("Invalid username", nameof(name));
}
var dbContext = _dbProvider.CreateContext();
// This can't use an overload with StringComparer because that would cause the query to
// have to be evaluated client-side.
return dbContext.Users.FirstOrDefault(u => string.Equals(u.Username, name));
return _dbProvider.CreateContext().Users.FirstOrDefault(u => string.Equals(u.Username, name));
}
/// <inheritdoc/>

@ -182,12 +182,13 @@ namespace MediaBrowser.Controller.Entities
{
if (this is ICollectionFolder && !(this is BasePluginFolder))
{
if (user.GetPreference(PreferenceKind.BlockedMediaFolders) != null)
var blockedMediaFolders = user.GetPreference(PreferenceKind.BlockedMediaFolders);
if (blockedMediaFolders.Length > 0)
{
if (user.GetPreference(PreferenceKind.BlockedMediaFolders).Contains(Id.ToString("N", CultureInfo.InvariantCulture), StringComparer.OrdinalIgnoreCase) ||
if (blockedMediaFolders.Contains(Id.ToString("N", CultureInfo.InvariantCulture), StringComparer.OrdinalIgnoreCase) ||
// Backwards compatibility
user.GetPreference(PreferenceKind.BlockedMediaFolders).Contains(Name, StringComparer.OrdinalIgnoreCase))
blockedMediaFolders.Contains(Name, StringComparer.OrdinalIgnoreCase))
{
return false;
}

Loading…
Cancel
Save