Remove api key check and simplify conditions

This commit is contained in:
Bill Thornton 2024-05-31 16:31:15 -04:00
parent 7221e7ca68
commit ed1b880359
2 changed files with 4 additions and 14 deletions

View File

@ -31,20 +31,20 @@ namespace Jellyfin.Api.Auth.FirstTimeSetupPolicy
context.Succeed(requirement);
}
// Succeed if user is admin or api key
else if (context.User.GetIsApiKey() || context.User.IsInRole(UserRoles.Administrator))
// Succeed if user is admin
else if (context.User.IsInRole(UserRoles.Administrator))
{
context.Succeed(requirement);
}
// Fail if admin is required and user is not admin
else if (requirement.RequireAdmin && !context.User.IsInRole(UserRoles.Administrator))
else if (requirement.RequireAdmin)
{
context.Fail();
}
// Succeed if admin is not required and user is not guest
else if (!requirement.RequireAdmin && context.User.IsInRole(UserRoles.User))
else if (context.User.IsInRole(UserRoles.User))
{
context.Succeed(requirement);
}

View File

@ -106,16 +106,6 @@ namespace Jellyfin.Api.Tests.Auth.FirstTimeSetupPolicy
Assert.Equal(shouldSucceed, allowed.Succeeded);
}
[Fact]
public async Task ShouldAllowAdminApiKeyIfStartupWizardComplete()
{
TestHelpers.SetupConfigurationManager(_configurationManagerMock, true);
var claims = new ClaimsPrincipal(new ClaimsIdentity([new Claim(InternalClaimTypes.IsApiKey, bool.TrueString)]));
var allowed = await _authorizationService.AuthorizeAsync(claims, "FirstTime");
Assert.True(allowed.Succeeded);
}
[Fact]
public async Task ShouldDisallowUserIfOutsideSchedule()
{