mirror of https://github.com/Ombi-app/Ombi
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
2.2 KiB
63 lines
2.2 KiB
using System;
|
|
using Ombi.Store.Entities;
|
|
using System.IO;
|
|
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.Requests;
|
|
|
|
namespace Ombi.Core.Rule.Rules.Request
|
|
{
|
|
public class CanRequestRule : BaseRequestRule, IRules<BaseRequest>
|
|
{
|
|
public CanRequestRule(IPrincipal principal, OmbiUserManager manager)
|
|
{
|
|
User = principal;
|
|
_manager = manager;
|
|
}
|
|
|
|
private IPrincipal User { get; }
|
|
private readonly OmbiUserManager _manager;
|
|
|
|
public async Task<RuleResult> Execute(BaseRequest obj)
|
|
{
|
|
var user = await _manager.Users.FirstOrDefaultAsync(x => x.UserName.Equals(User.Identity.Name, StringComparison.InvariantCultureIgnoreCase));
|
|
if (await _manager.IsInRoleAsync(user, OmbiRoles.Admin) || user.IsSystemUser)
|
|
return Success();
|
|
|
|
if (obj.RequestType == RequestType.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 (await _manager.IsInRoleAsync(user, OmbiRoles.RequestTv) || await _manager.IsInRoleAsync(user, OmbiRoles.AutoApproveTv))
|
|
{
|
|
return Success();
|
|
}
|
|
|
|
return Fail("You do not have permissions to Request a TV Show");
|
|
}
|
|
|
|
if (obj.RequestType == RequestType.Album)
|
|
{
|
|
if (await _manager.IsInRoleAsync(user, OmbiRoles.RequestMusic) || await _manager.IsInRoleAsync(user, OmbiRoles.AutoApproveMusic))
|
|
{
|
|
return Success();
|
|
}
|
|
|
|
return Fail("You do not have permissions to Request an Album");
|
|
}
|
|
|
|
throw new InvalidDataException("Permission check failed: unknown RequestType");
|
|
}
|
|
}
|
|
}
|