mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-13 16:52:56 -07:00
Fixed the API key not working when attempting to get requests #2058
This commit is contained in:
parent
1024dd5843
commit
ec4fe9993c
1 changed files with 16 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
|||
using Ombi.Core.Rule;
|
||||
using System;
|
||||
using Ombi.Core.Rule;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Principal;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -10,6 +11,7 @@ using Microsoft.AspNetCore.Identity;
|
|||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Ombi.Core.Authentication;
|
||||
using Ombi.Helpers;
|
||||
|
||||
namespace Ombi.Core.Engine.Interfaces
|
||||
{
|
||||
|
@ -30,6 +32,13 @@ namespace Ombi.Core.Engine.Interfaces
|
|||
private OmbiUser _user;
|
||||
protected async Task<OmbiUser> GetUser()
|
||||
{
|
||||
if (IsApiUser)
|
||||
{
|
||||
return new OmbiUser
|
||||
{
|
||||
UserName = Username,
|
||||
};
|
||||
}
|
||||
return _user ?? (_user = await UserManager.Users.FirstOrDefaultAsync(x => x.UserName == Username));
|
||||
}
|
||||
|
||||
|
@ -40,6 +49,10 @@ namespace Ombi.Core.Engine.Interfaces
|
|||
|
||||
protected async Task<bool> IsInRole(string roleName)
|
||||
{
|
||||
if (IsApiUser && roleName != OmbiRoles.Disabled)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return await UserManager.IsInRoleAsync(await GetUser(), roleName);
|
||||
}
|
||||
|
||||
|
@ -59,5 +72,7 @@ namespace Ombi.Core.Engine.Interfaces
|
|||
var ruleResults = await Rules.StartSpecificRules(model, rule);
|
||||
return ruleResults;
|
||||
}
|
||||
|
||||
private bool IsApiUser => Username.Equals("Api", StringComparison.CurrentCultureIgnoreCase);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue