mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-15 09:42:56 -07:00
Fixed the issue where it was not picking up roles until the JWT was refreshed
This commit is contained in:
parent
826517cbff
commit
cf9bb889ed
3 changed files with 34 additions and 22 deletions
|
@ -1,46 +1,52 @@
|
|||
using Ombi.Store.Entities;
|
||||
using System.Security.Claims;
|
||||
using System.Security.Principal;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Ombi.Core.Authentication;
|
||||
using Ombi.Core.Rule.Interfaces;
|
||||
using Ombi.Helpers;
|
||||
using Ombi.Store.Entities;
|
||||
using Ombi.Store.Entities.Requests;
|
||||
|
||||
namespace Ombi.Core.Rule.Rules
|
||||
namespace Ombi.Core.Rule.Rules.Request
|
||||
{
|
||||
public class CanRequestRule : BaseRequestRule, IRules<BaseRequest>
|
||||
{
|
||||
public CanRequestRule(IPrincipal principal)
|
||||
public CanRequestRule(IPrincipal principal, OmbiUserManager manager)
|
||||
{
|
||||
User = principal;
|
||||
_manager = manager;
|
||||
}
|
||||
|
||||
private IPrincipal User { get; }
|
||||
private readonly OmbiUserManager _manager;
|
||||
|
||||
public Task<RuleResult> Execute(BaseRequest obj)
|
||||
public async Task<RuleResult> Execute(BaseRequest obj)
|
||||
{
|
||||
if (User.IsInRole(OmbiRoles.Admin))
|
||||
return Task.FromResult(Success());
|
||||
var user = await _manager.Users.FirstOrDefaultAsync(x => x.UserName == User.Identity.Name);
|
||||
if (await _manager.IsInRoleAsync(user, OmbiRoles.Admin))
|
||||
return Success();
|
||||
|
||||
if (obj.RequestType == RequestType.Movie)
|
||||
{
|
||||
if (User.IsInRole(OmbiRoles.RequestMovie) || User.IsInRole(OmbiRoles.AutoApproveMovie))
|
||||
return Task.FromResult(Success());
|
||||
return Task.FromResult(Fail("You do not have permissions to Request a Movie"));
|
||||
if (await _manager.IsInRoleAsync(user, OmbiRoles.RequestMovie) || await _manager.IsInRoleAsync(user, OmbiRoles.AutoApproveMovie))
|
||||
return Success();
|
||||
return Fail("You do not have permissions to Request a Movie");
|
||||
}
|
||||
|
||||
if (obj.RequestType == RequestType.TvShow)
|
||||
{
|
||||
if (User.IsInRole(OmbiRoles.RequestTv) || User.IsInRole(OmbiRoles.AutoApproveTv))
|
||||
return Task.FromResult(Success());
|
||||
if (await _manager.IsInRoleAsync(user, OmbiRoles.RequestTv) || await _manager.IsInRoleAsync(user, OmbiRoles.AutoApproveTv))
|
||||
return Success();
|
||||
}
|
||||
|
||||
if (obj.RequestType == RequestType.Album)
|
||||
{
|
||||
if (User.IsInRole(OmbiRoles.RequestMusic) || User.IsInRole(OmbiRoles.AutoApproveMusic))
|
||||
return Task.FromResult(Success());
|
||||
if (await _manager.IsInRoleAsync(user, OmbiRoles.RequestMusic) || await _manager.IsInRoleAsync(user, OmbiRoles.AutoApproveMusic))
|
||||
return Success();
|
||||
}
|
||||
|
||||
return Task.FromResult(Fail("You do not have permissions to Request a TV Show"));
|
||||
return Fail("You do not have permissions to Request a TV Show");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue