Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions backend/Api/MoonfinController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

private static readonly Type? _userManagerType = Type.GetType("MediaBrowser.Controller.Library.IUserManager, MediaBrowser.Controller");
private static readonly MethodInfo? _userManagerGetUserById = _userManagerType?.GetMethod("GetUserById", [typeof(Guid)]);
private static readonly PropertyInfo? _userManagerUsersProperty = _userManagerType?.GetProperty("Users");
private static readonly MethodInfo? _userManagerGetUsers = _userManagerType?.GetMethod("GetUsers");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private static readonly MethodInfo? _userManagerGetUsers = _userManagerType?.GetMethod("GetUsers");
private static readonly MethodInfo? _userManagerGetUsersIds = _userManagerType?.GetMethod("GetUsersIds", Type.EmptyTypes);
private static readonly PropertyInfo? _userManagerUsersIdsProperty = _userManagerType?.GetProperty("UsersIds");
private static readonly MethodInfo? _userManagerGetUsers = _userManagerType?.GetMethod("GetUsers", Type.EmptyTypes);
private static readonly PropertyInfo? _userManagerUsersProperty = _userManagerType?.GetProperty("Users");

To support 10.10.7 through 12.0 we need both the 10.11+ methods and the 10.10 properties, for both the Guid list and the User list.

private static readonly MethodInfo? _internalItemsQuerySetUser = typeof(InternalItemsQuery).GetMethod("SetUser", BindingFlags.Public | BindingFlags.Instance);
private static readonly PropertyInfo? _internalItemsQueryUserProperty = typeof(InternalItemsQuery).GetProperty(nameof(InternalItemsQuery.User), BindingFlags.Public | BindingFlags.Instance);
private static readonly MethodInfo? _baseItemIsVisible = typeof(BaseItem)
Expand Down Expand Up @@ -1038,7 +1038,7 @@

private List<Guid>? GetAllServerUserIds()
{
if (_userManagerType == null || _userManagerUsersProperty == null)
if (_userManagerType == null)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (_userManagerType == null)
if (_userManagerType == null ||
(_userManagerGetUsersIds == null && _userManagerUsersIdsProperty == null &&
_userManagerGetUsers == null && _userManagerUsersProperty == null))

_userManagerType can resolve while none of the user members do

{
return null;
}
Expand All @@ -1049,7 +1049,8 @@
return null;
}

if (_userManagerUsersProperty.GetValue(userManager) is not IEnumerable<object> users)
object usersObject = _userManagerGetUsers.Invoke(userManager,["null"]);

Check warning on line 1052 in backend/Api/MoonfinController.cs

View workflow job for this annotation

GitHub Actions / Build Plugin

Converting null literal or possible null value to non-nullable type.

Check warning on line 1052 in backend/Api/MoonfinController.cs

View workflow job for this annotation

GitHub Actions / Build Plugin

Dereference of a possibly null reference.

Check warning on line 1052 in backend/Api/MoonfinController.cs

View workflow job for this annotation

GitHub Actions / Build Plugin

Converting null literal or possible null value to non-nullable type.

Check warning on line 1052 in backend/Api/MoonfinController.cs

View workflow job for this annotation

GitHub Actions / Build Plugin

Dereference of a possibly null reference.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
object usersObject = _userManagerGetUsers.Invoke(userManager,["null"]);
// Preferred path: ask the server for the Guid list directly.
object? idsObject = _userManagerGetUsersIds != null
? _userManagerGetUsersIds.Invoke(userManager, null)
: _userManagerUsersIdsProperty?.GetValue(userManager);
if (idsObject is IEnumerable<Guid> guidIds)
{
return guidIds.ToList();
}
// Fallback: enumerate User objects and reflect their Id (older shapes / safety).
object? usersObject = _userManagerGetUsers != null
? _userManagerGetUsers.Invoke(userManager, null)
: _userManagerUsersProperty?.GetValue(userManager);
if (usersObject is not IEnumerable<object> users)
{
return null;
}
var ids = new List<Guid>();
foreach (var user in users)
{
if (user?.GetType().GetProperty("Id")?.GetValue(user) is Guid id)
{
ids.Add(id);
}
}
return ids;

Three problems on this line: GetUsers() is parameterless so ["null"] throws TargetParameterCountException every call; ["null"] is the string "null", not a null ref; and _userManagerGetUsers isn't null-checked. Rework the body to prefer the direct Guid member and fall back to the User collection, using method-or-property on each so it spans from 10.10.7 to 12.0 nicely.

if (usersObject is not IEnumerable<object> users)
{
return null;
}
Expand Down
Loading