diff options
| author | Bond_009 <bond.009@outlook.com> | 2020-04-23 11:29:19 +0200 |
|---|---|---|
| committer | Bond_009 <bond.009@outlook.com> | 2020-04-23 11:29:19 +0200 |
| commit | 118f30059c11cf43d9780c8e0328423e35b44b76 (patch) | |
| tree | 3dae865e35e3cd026e188706b5eec739cb33bf7b /MediaBrowser.Api/BaseApiService.cs | |
| parent | 10afa4509db6fc7e3c2e7dd6ccc8997dfe3b10f9 (diff) | |
| parent | 97e383d108a4adb7e57c13d67f1d36bd1b5ce7b5 (diff) | |
Merge branch 'master' into nullable4
Diffstat (limited to 'MediaBrowser.Api/BaseApiService.cs')
| -rw-r--r-- | MediaBrowser.Api/BaseApiService.cs | 58 |
1 files changed, 20 insertions, 38 deletions
diff --git a/MediaBrowser.Api/BaseApiService.cs b/MediaBrowser.Api/BaseApiService.cs index 112ee8f79..1a1d86362 100644 --- a/MediaBrowser.Api/BaseApiService.cs +++ b/MediaBrowser.Api/BaseApiService.cs @@ -58,12 +58,9 @@ namespace MediaBrowser.Api public static string[] SplitValue(string value, char delim) { - if (value == null) - { - return Array.Empty<string>(); - } - - return value.Split(new[] { delim }, StringSplitOptions.RemoveEmptyEntries); + return value == null + ? Array.Empty<string>() + : value.Split(new[] { delim }, StringSplitOptions.RemoveEmptyEntries); } public static Guid[] GetGuids(string value) @@ -97,19 +94,10 @@ namespace MediaBrowser.Api var authenticatedUser = auth.User; // If they're going to update the record of another user, they must be an administrator - if (!userId.Equals(auth.UserId)) - { - if (!authenticatedUser.Policy.IsAdministrator) - { - throw new SecurityException("Unauthorized access."); - } - } - else if (restrictUserPreferences) + if ((!userId.Equals(auth.UserId) && !authenticatedUser.Policy.IsAdministrator) + || (restrictUserPreferences && !authenticatedUser.Policy.EnableUserPreferenceAccess)) { - if (!authenticatedUser.Policy.EnableUserPreferenceAccess) - { - throw new SecurityException("Unauthorized access."); - } + throw new SecurityException("Unauthorized access."); } } @@ -138,8 +126,8 @@ namespace MediaBrowser.Api options.Fields = hasFields.GetItemFields(); } - if (!options.ContainsField(Model.Querying.ItemFields.RecursiveItemCount) - || !options.ContainsField(Model.Querying.ItemFields.ChildCount)) + if (!options.ContainsField(ItemFields.RecursiveItemCount) + || !options.ContainsField(ItemFields.ChildCount)) { var client = authContext.GetAuthorizationInfo(Request).Client ?? string.Empty; if (client.IndexOf("kodi", StringComparison.OrdinalIgnoreCase) != -1 || @@ -150,7 +138,7 @@ namespace MediaBrowser.Api int oldLen = options.Fields.Length; var arr = new ItemFields[oldLen + 1]; options.Fields.CopyTo(arr, 0); - arr[oldLen] = Model.Querying.ItemFields.RecursiveItemCount; + arr[oldLen] = ItemFields.RecursiveItemCount; options.Fields = arr; } @@ -166,7 +154,7 @@ namespace MediaBrowser.Api int oldLen = options.Fields.Length; var arr = new ItemFields[oldLen + 1]; options.Fields.CopyTo(arr, 0); - arr[oldLen] = Model.Querying.ItemFields.ChildCount; + arr[oldLen] = ItemFields.ChildCount; options.Fields = arr; } } @@ -282,27 +270,21 @@ namespace MediaBrowser.Api }).OfType<T>().FirstOrDefault(); - if (result == null) + result ??= libraryManager.GetItemList(new InternalItemsQuery { - result = libraryManager.GetItemList(new InternalItemsQuery - { - Name = name.Replace(BaseItem.SlugChar, '/'), - IncludeItemTypes = new[] { typeof(T).Name }, - DtoOptions = dtoOptions + Name = name.Replace(BaseItem.SlugChar, '/'), + IncludeItemTypes = new[] { typeof(T).Name }, + DtoOptions = dtoOptions - }).OfType<T>().FirstOrDefault(); - } + }).OfType<T>().FirstOrDefault(); - if (result == null) + result ??= libraryManager.GetItemList(new InternalItemsQuery { - result = libraryManager.GetItemList(new InternalItemsQuery - { - Name = name.Replace(BaseItem.SlugChar, '?'), - IncludeItemTypes = new[] { typeof(T).Name }, - DtoOptions = dtoOptions + Name = name.Replace(BaseItem.SlugChar, '?'), + IncludeItemTypes = new[] { typeof(T).Name }, + DtoOptions = dtoOptions - }).OfType<T>().FirstOrDefault(); - } + }).OfType<T>().FirstOrDefault(); return result; } |
