Use typed UserManager GetPreference
This commit is contained in:
parent
04ba59ab40
commit
b670937c3d
|
@ -129,23 +129,23 @@ namespace Emby.Server.Implementations.Library
|
||||||
|
|
||||||
if (!query.IncludeHidden)
|
if (!query.IncludeHidden)
|
||||||
{
|
{
|
||||||
list = list.Where(i => !user.GetPreference(PreferenceKind.MyMediaExcludes).Contains(i.Id.ToString("N", CultureInfo.InvariantCulture))).ToList();
|
list = list.Where(i => !user.GetPreference<Guid>(PreferenceKind.MyMediaExcludes).Contains(i.Id)).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
var sorted = _libraryManager.Sort(list, user, new[] { ItemSortBy.SortName }, SortOrder.Ascending).ToList();
|
var sorted = _libraryManager.Sort(list, user, new[] { ItemSortBy.SortName }, SortOrder.Ascending).ToList();
|
||||||
|
|
||||||
var orders = user.GetPreference(PreferenceKind.OrderedViews).ToList();
|
var orders = user.GetPreference<Guid>(PreferenceKind.OrderedViews);
|
||||||
|
|
||||||
return list
|
return list
|
||||||
.OrderBy(i =>
|
.OrderBy(i =>
|
||||||
{
|
{
|
||||||
var index = orders.IndexOf(i.Id.ToString("D", CultureInfo.InvariantCulture));
|
var index = Array.IndexOf(orders, i.Id);
|
||||||
|
|
||||||
if (index == -1
|
if (index == -1
|
||||||
&& i is UserView view
|
&& i is UserView view
|
||||||
&& view.DisplayParentId != Guid.Empty)
|
&& view.DisplayParentId != Guid.Empty)
|
||||||
{
|
{
|
||||||
index = orders.IndexOf(view.DisplayParentId.ToString("D", CultureInfo.InvariantCulture));
|
index = Array.IndexOf(orders, view.DisplayParentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
return index == -1 ? int.MaxValue : index;
|
return index == -1 ? int.MaxValue : index;
|
||||||
|
@ -280,8 +280,8 @@ namespace Emby.Server.Implementations.Library
|
||||||
{
|
{
|
||||||
parents = _libraryManager.GetUserRootFolder().GetChildren(user, true)
|
parents = _libraryManager.GetUserRootFolder().GetChildren(user, true)
|
||||||
.Where(i => i is Folder)
|
.Where(i => i is Folder)
|
||||||
.Where(i => !user.GetPreference(PreferenceKind.LatestItemExcludes)
|
.Where(i => !user.GetPreference<Guid>(PreferenceKind.LatestItemExcludes)
|
||||||
.Contains(i.Id.ToString("N", CultureInfo.InvariantCulture)))
|
.Contains(i.Id))
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,8 +75,7 @@ namespace Emby.Server.Implementations.TV
|
||||||
{
|
{
|
||||||
parents = _libraryManager.GetUserRootFolder().GetChildren(user, true)
|
parents = _libraryManager.GetUserRootFolder().GetChildren(user, true)
|
||||||
.Where(i => i is Folder)
|
.Where(i => i is Folder)
|
||||||
.Where(i => !user.GetPreference(PreferenceKind.LatestItemExcludes)
|
.Where(i => !user.GetPreference<Guid>(PreferenceKind.LatestItemExcludes).Contains(i.Id))
|
||||||
.Contains(i.Id.ToString("N", CultureInfo.InvariantCulture)))
|
|
||||||
.ToArray();
|
.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -254,18 +254,18 @@ namespace Jellyfin.Api.Controllers
|
||||||
includeItemTypes = new[] { "Playlist" };
|
includeItemTypes = new[] { "Playlist" };
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isInEnabledFolder = user!.GetPreference(PreferenceKind.EnabledFolders).Any(i => new Guid(i) == item.Id)
|
var enabledChannels = user!.GetPreference<Guid>(PreferenceKind.EnabledChannels);
|
||||||
|
|
||||||
|
bool isInEnabledFolder = Array.IndexOf(user.GetPreference<Guid>(PreferenceKind.EnabledFolders), item.Id) != -1
|
||||||
// Assume all folders inside an EnabledChannel are enabled
|
// Assume all folders inside an EnabledChannel are enabled
|
||||||
|| user.GetPreference(PreferenceKind.EnabledChannels).Any(i => new Guid(i) == item.Id)
|
|| Array.IndexOf(enabledChannels, item.Id) != -1
|
||||||
// Assume all items inside an EnabledChannel are enabled
|
// Assume all items inside an EnabledChannel are enabled
|
||||||
|| user.GetPreference(PreferenceKind.EnabledChannels).Any(i => new Guid(i) == item.ChannelId);
|
|| Array.IndexOf(enabledChannels, item.ChannelId) != -1;
|
||||||
|
|
||||||
var collectionFolders = _libraryManager.GetCollectionFolders(item);
|
var collectionFolders = _libraryManager.GetCollectionFolders(item);
|
||||||
foreach (var collectionFolder in collectionFolders)
|
foreach (var collectionFolder in collectionFolders)
|
||||||
{
|
{
|
||||||
if (user.GetPreference(PreferenceKind.EnabledFolders).Contains(
|
if (user.GetPreference<Guid>(PreferenceKind.EnabledFolders).Contains(collectionFolder.Id))
|
||||||
collectionFolder.Id.ToString("N", CultureInfo.InvariantCulture),
|
|
||||||
StringComparer.OrdinalIgnoreCase))
|
|
||||||
{
|
{
|
||||||
isInEnabledFolder = true;
|
isInEnabledFolder = true;
|
||||||
}
|
}
|
||||||
|
@ -786,12 +786,12 @@ namespace Jellyfin.Api.Controllers
|
||||||
|
|
||||||
var ancestorIds = Array.Empty<Guid>();
|
var ancestorIds = Array.Empty<Guid>();
|
||||||
|
|
||||||
var excludeFolderIds = user.GetPreference(PreferenceKind.LatestItemExcludes);
|
var excludeFolderIds = user.GetPreference<Guid>(PreferenceKind.LatestItemExcludes);
|
||||||
if (parentIdGuid.Equals(Guid.Empty) && excludeFolderIds.Length > 0)
|
if (parentIdGuid.Equals(Guid.Empty) && excludeFolderIds.Length > 0)
|
||||||
{
|
{
|
||||||
ancestorIds = _libraryManager.GetUserRootFolder().GetChildren(user, true)
|
ancestorIds = _libraryManager.GetUserRootFolder().GetChildren(user, true)
|
||||||
.Where(i => i is Folder)
|
.Where(i => i is Folder)
|
||||||
.Where(i => !excludeFolderIds.Contains(i.Id.ToString("N", CultureInfo.InvariantCulture)))
|
.Where(i => !excludeFolderIds.Contains(i.Id))
|
||||||
.Select(i => i.Id)
|
.Select(i => i.Id)
|
||||||
.ToArray();
|
.ToArray();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
@ -413,6 +414,25 @@ namespace Jellyfin.Data.Entities
|
||||||
return Equals(val, string.Empty) ? Array.Empty<string>() : val.Split(Delimiter);
|
return Equals(val, string.Empty) ? Array.Empty<string>() : val.Split(Delimiter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the user's preferences for the given preference kind.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="preference">The preference kind.</param>
|
||||||
|
/// <typeparam name="T">Type of preference.</typeparam>
|
||||||
|
/// <returns>A {T} array containing the user's preference.</returns>
|
||||||
|
public T[] GetPreference<T>(PreferenceKind preference)
|
||||||
|
{
|
||||||
|
var val = Preferences.First(p => p.Kind == preference).Value;
|
||||||
|
if (string.IsNullOrEmpty(val))
|
||||||
|
{
|
||||||
|
return Array.Empty<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
var converter = TypeDescriptor.GetConverter(typeof(T));
|
||||||
|
var stringValues = val.Split(Delimiter);
|
||||||
|
return Array.ConvertAll(stringValues, value => (T)converter.ConvertFromString(value));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the specified preference to the given value.
|
/// Sets the specified preference to the given value.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -421,7 +441,19 @@ namespace Jellyfin.Data.Entities
|
||||||
public void SetPreference(PreferenceKind preference, string[] values)
|
public void SetPreference(PreferenceKind preference, string[] values)
|
||||||
{
|
{
|
||||||
Preferences.First(p => p.Kind == preference).Value
|
Preferences.First(p => p.Kind == preference).Value
|
||||||
= string.Join(Delimiter.ToString(CultureInfo.InvariantCulture), values);
|
= string.Join(Delimiter, values);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Sets the specified preference to the given value.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="preference">The preference kind.</param>
|
||||||
|
/// <param name="values">The values.</param>
|
||||||
|
/// <typeparam name="T">The type of value.</typeparam>
|
||||||
|
public void SetPreference<T>(PreferenceKind preference, T[] values)
|
||||||
|
{
|
||||||
|
Preferences.First(p => p.Kind == preference).Value
|
||||||
|
= string.Join(Delimiter, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -441,7 +473,7 @@ namespace Jellyfin.Data.Entities
|
||||||
/// <returns><c>True</c> if the folder is in the user's grouped folders.</returns>
|
/// <returns><c>True</c> if the folder is in the user's grouped folders.</returns>
|
||||||
public bool IsFolderGrouped(Guid id)
|
public bool IsFolderGrouped(Guid id)
|
||||||
{
|
{
|
||||||
return GetPreference(PreferenceKind.GroupedFolders).Any(i => new Guid(i) == id);
|
return Array.IndexOf(GetPreference<Guid>(PreferenceKind.GroupedFolders), id) != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool IsParentalScheduleAllowed(AccessSchedule schedule, DateTime date)
|
private static bool IsParentalScheduleAllowed(AccessSchedule schedule, DateTime date)
|
||||||
|
|
|
@ -376,14 +376,14 @@ namespace Jellyfin.Server.Implementations.Users
|
||||||
EnablePublicSharing = user.HasPermission(PermissionKind.EnablePublicSharing),
|
EnablePublicSharing = user.HasPermission(PermissionKind.EnablePublicSharing),
|
||||||
AccessSchedules = user.AccessSchedules.ToArray(),
|
AccessSchedules = user.AccessSchedules.ToArray(),
|
||||||
BlockedTags = user.GetPreference(PreferenceKind.BlockedTags),
|
BlockedTags = user.GetPreference(PreferenceKind.BlockedTags),
|
||||||
EnabledChannels = user.GetPreference(PreferenceKind.EnabledChannels)?.Select(Guid.Parse).ToArray(),
|
EnabledChannels = user.GetPreference<Guid>(PreferenceKind.EnabledChannels),
|
||||||
EnabledDevices = user.GetPreference(PreferenceKind.EnabledDevices),
|
EnabledDevices = user.GetPreference(PreferenceKind.EnabledDevices),
|
||||||
EnabledFolders = user.GetPreference(PreferenceKind.EnabledFolders)?.Select(Guid.Parse).ToArray(),
|
EnabledFolders = user.GetPreference<Guid>(PreferenceKind.EnabledFolders),
|
||||||
EnableContentDeletionFromFolders = user.GetPreference(PreferenceKind.EnableContentDeletionFromFolders),
|
EnableContentDeletionFromFolders = user.GetPreference(PreferenceKind.EnableContentDeletionFromFolders),
|
||||||
SyncPlayAccess = user.SyncPlayAccess,
|
SyncPlayAccess = user.SyncPlayAccess,
|
||||||
BlockedChannels = user.GetPreference(PreferenceKind.BlockedChannels)?.Select(Guid.Parse).ToArray(),
|
BlockedChannels = user.GetPreference<Guid>(PreferenceKind.BlockedChannels),
|
||||||
BlockedMediaFolders = user.GetPreference(PreferenceKind.BlockedMediaFolders)?.Select(Guid.Parse).ToArray(),
|
BlockedMediaFolders = user.GetPreference<Guid>(PreferenceKind.BlockedMediaFolders),
|
||||||
BlockUnratedItems = user.GetPreference(PreferenceKind.BlockUnratedItems).Select(Enum.Parse<UnratedItem>).ToArray()
|
BlockUnratedItems = user.GetPreference<UnratedItem>(PreferenceKind.BlockUnratedItems)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -704,13 +704,11 @@ namespace Jellyfin.Server.Implementations.Users
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: fix this at some point
|
// TODO: fix this at some point
|
||||||
user.SetPreference(
|
user.SetPreference(PreferenceKind.BlockUnratedItems, policy.BlockUnratedItems ?? Array.Empty<UnratedItem>());
|
||||||
PreferenceKind.BlockUnratedItems,
|
|
||||||
policy.BlockUnratedItems?.Select(i => i.ToString()).ToArray() ?? Array.Empty<string>());
|
|
||||||
user.SetPreference(PreferenceKind.BlockedTags, policy.BlockedTags);
|
user.SetPreference(PreferenceKind.BlockedTags, policy.BlockedTags);
|
||||||
user.SetPreference(PreferenceKind.EnabledChannels, policy.EnabledChannels?.Select(i => i.ToString("N", CultureInfo.InvariantCulture)).ToArray());
|
user.SetPreference(PreferenceKind.EnabledChannels, policy.EnabledChannels);
|
||||||
user.SetPreference(PreferenceKind.EnabledDevices, policy.EnabledDevices);
|
user.SetPreference(PreferenceKind.EnabledDevices, policy.EnabledDevices);
|
||||||
user.SetPreference(PreferenceKind.EnabledFolders, policy.EnabledFolders?.Select(i => i.ToString("N", CultureInfo.InvariantCulture)).ToArray());
|
user.SetPreference(PreferenceKind.EnabledFolders, policy.EnabledFolders);
|
||||||
user.SetPreference(PreferenceKind.EnableContentDeletionFromFolders, policy.EnableContentDeletionFromFolders);
|
user.SetPreference(PreferenceKind.EnableContentDeletionFromFolders, policy.EnableContentDeletionFromFolders);
|
||||||
|
|
||||||
dbContext.Update(user);
|
dbContext.Update(user);
|
||||||
|
|
|
@ -168,9 +168,9 @@ namespace Jellyfin.Server.Migrations.Routines
|
||||||
}
|
}
|
||||||
|
|
||||||
user.SetPreference(PreferenceKind.BlockedTags, policy.BlockedTags);
|
user.SetPreference(PreferenceKind.BlockedTags, policy.BlockedTags);
|
||||||
user.SetPreference(PreferenceKind.EnabledChannels, policy.EnabledChannels?.Select(i => i.ToString("N", CultureInfo.InvariantCulture)).ToArray());
|
user.SetPreference(PreferenceKind.EnabledChannels, policy.EnabledChannels);
|
||||||
user.SetPreference(PreferenceKind.EnabledDevices, policy.EnabledDevices);
|
user.SetPreference(PreferenceKind.EnabledDevices, policy.EnabledDevices);
|
||||||
user.SetPreference(PreferenceKind.EnabledFolders, policy.EnabledFolders?.Select(i => i.ToString("N", CultureInfo.InvariantCulture)).ToArray());
|
user.SetPreference(PreferenceKind.EnabledFolders, policy.EnabledFolders);
|
||||||
user.SetPreference(PreferenceKind.EnableContentDeletionFromFolders, policy.EnableContentDeletionFromFolders);
|
user.SetPreference(PreferenceKind.EnableContentDeletionFromFolders, policy.EnableContentDeletionFromFolders);
|
||||||
user.SetPreference(PreferenceKind.OrderedViews, config.OrderedViews);
|
user.SetPreference(PreferenceKind.OrderedViews, config.OrderedViews);
|
||||||
user.SetPreference(PreferenceKind.GroupedFolders, config.GroupedFolders);
|
user.SetPreference(PreferenceKind.GroupedFolders, config.GroupedFolders);
|
||||||
|
|
|
@ -17,9 +17,10 @@ namespace MediaBrowser.Controller.Channels
|
||||||
{
|
{
|
||||||
public override bool IsVisible(User user)
|
public override bool IsVisible(User user)
|
||||||
{
|
{
|
||||||
if (user.GetPreference(PreferenceKind.BlockedChannels) != null)
|
var blockedChannelsPreference = user.GetPreference<Guid>(PreferenceKind.BlockedChannels);
|
||||||
|
if (blockedChannelsPreference.Length != 0)
|
||||||
{
|
{
|
||||||
if (user.GetPreference(PreferenceKind.BlockedChannels).Contains(Id.ToString("N", CultureInfo.InvariantCulture), StringComparer.OrdinalIgnoreCase))
|
if (blockedChannelsPreference.Contains(Id))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -27,8 +28,7 @@ namespace MediaBrowser.Controller.Channels
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!user.HasPermission(PermissionKind.EnableAllChannels)
|
if (!user.HasPermission(PermissionKind.EnableAllChannels)
|
||||||
&& !user.GetPreference(PreferenceKind.EnabledChannels)
|
&& !user.GetPreference<Guid>(PreferenceKind.EnabledChannels).Contains(Id))
|
||||||
.Contains(Id.ToString("N", CultureInfo.InvariantCulture), StringComparer.OrdinalIgnoreCase))
|
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,7 +120,7 @@ namespace MediaBrowser.Controller.Entities.Audio
|
||||||
|
|
||||||
protected override bool GetBlockUnratedValue(User user)
|
protected override bool GetBlockUnratedValue(User user)
|
||||||
{
|
{
|
||||||
return user.GetPreference(PreferenceKind.BlockUnratedItems).Contains(UnratedItem.Music.ToString());
|
return user.GetPreference<UnratedItem>(PreferenceKind.BlockUnratedItems).Contains(UnratedItem.Music);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override UnratedItem GetBlockUnratedType()
|
public override UnratedItem GetBlockUnratedType()
|
||||||
|
|
|
@ -145,7 +145,7 @@ namespace MediaBrowser.Controller.Entities.Audio
|
||||||
|
|
||||||
protected override bool GetBlockUnratedValue(User user)
|
protected override bool GetBlockUnratedValue(User user)
|
||||||
{
|
{
|
||||||
return user.GetPreference(PreferenceKind.BlockUnratedItems).Contains(UnratedItem.Music.ToString());
|
return user.GetPreference<UnratedItem>(PreferenceKind.BlockUnratedItems).Contains(UnratedItem.Music);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override UnratedItem GetBlockUnratedType()
|
public override UnratedItem GetBlockUnratedType()
|
||||||
|
|
|
@ -480,11 +480,11 @@ namespace MediaBrowser.Controller.Entities
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
var allowed = user.GetPreference(PreferenceKind.EnableContentDeletionFromFolders);
|
var allowed = user.GetPreference<Guid>(PreferenceKind.EnableContentDeletionFromFolders);
|
||||||
|
|
||||||
if (SourceType == SourceType.Channel)
|
if (SourceType == SourceType.Channel)
|
||||||
{
|
{
|
||||||
return allowed.Contains(ChannelId.ToString(""), StringComparer.OrdinalIgnoreCase);
|
return allowed.Contains(ChannelId);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -492,7 +492,7 @@ namespace MediaBrowser.Controller.Entities
|
||||||
|
|
||||||
foreach (var folder in collectionFolders)
|
foreach (var folder in collectionFolders)
|
||||||
{
|
{
|
||||||
if (allowed.Contains(folder.Id.ToString("N", CultureInfo.InvariantCulture), StringComparer.OrdinalIgnoreCase))
|
if (allowed.Contains(folder.Id))
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1909,7 +1909,7 @@ namespace MediaBrowser.Controller.Entities
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return user.GetPreference(PreferenceKind.BlockUnratedItems).Contains(GetBlockUnratedType().ToString());
|
return user.GetPreference<UnratedItem>(PreferenceKind.BlockUnratedItems).Contains(GetBlockUnratedType());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -49,7 +49,7 @@ namespace MediaBrowser.Controller.Entities.Movies
|
||||||
|
|
||||||
protected override bool GetBlockUnratedValue(User user)
|
protected override bool GetBlockUnratedValue(User user)
|
||||||
{
|
{
|
||||||
return user.GetPreference(PreferenceKind.BlockUnratedItems).Contains(UnratedItem.Movie.ToString());
|
return user.GetPreference<UnratedItem>(PreferenceKind.BlockUnratedItems).Contains(UnratedItem.Movie);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override double GetDefaultPrimaryImageAspectRatio()
|
public override double GetDefaultPrimaryImageAspectRatio()
|
||||||
|
|
|
@ -452,7 +452,7 @@ namespace MediaBrowser.Controller.Entities.TV
|
||||||
|
|
||||||
protected override bool GetBlockUnratedValue(User user)
|
protected override bool GetBlockUnratedValue(User user)
|
||||||
{
|
{
|
||||||
return user.GetPreference(PreferenceKind.BlockUnratedItems).Contains(UnratedItem.Series.ToString());
|
return user.GetPreference<UnratedItem>(PreferenceKind.BlockUnratedItems).Contains(UnratedItem.Series);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override UnratedItem GetBlockUnratedType()
|
public override UnratedItem GetBlockUnratedType()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user