feat: Add Auto Approve 4K role (#4982) (#4983)

Legacy "Auto Approve" role now only applies to non-4K requests
Fixes #4957

Co-authored-by: sephrat <34862846+sephrat@users.noreply.github.com>
pull/4987/head
Jamie 1 year ago committed by GitHub
parent cf9aadaa52
commit ac05495425
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -54,6 +54,17 @@ namespace Ombi.Core.Tests.Rule.Request
Assert.True(request.Approved);
}
[Test]
public async Task Should_ReturnSuccess_WhenAdminAndRequest4KMovie()
{
UserManager.Setup(x => x.IsInRoleAsync(It.IsAny<OmbiUser>(), OmbiRoles.Admin)).ReturnsAsync(true);
var request = new MovieRequests() { RequestType = Store.Entities.RequestType.Movie, Is4kRequest = true };
var result = await Rule.Execute(request);
Assert.True(result.Success);
Assert.True(request.Approved);
}
[Test]
public async Task Should_ReturnSuccess_WhenAdminAndRequestTV()
{
@ -76,6 +87,17 @@ namespace Ombi.Core.Tests.Rule.Request
Assert.True(request.Approved);
}
[Test]
public async Task Should_ReturnSuccess_WhenAutoApprove4KMovieAndRequest4KMovie()
{
UserManager.Setup(x => x.IsInRoleAsync(It.IsAny<OmbiUser>(), OmbiRoles.AutoApprove4KMovie)).ReturnsAsync(true);
var request = new MovieRequests() { RequestType = Store.Entities.RequestType.Movie, Is4kRequest = true };
var result = await Rule.Execute(request);
Assert.True(result.Success);
Assert.True(request.Approved);
}
[Test]
public async Task Should_ReturnFail_WhenAutoApproveMovie_And_RequestTV()
{
@ -115,7 +137,7 @@ namespace Ombi.Core.Tests.Rule.Request
public async Task Should_ReturnFail_WhenAutoApproveTV_And_RequestMovie()
{
UserManager.Setup(x => x.IsInRoleAsync(It.IsAny<OmbiUser>(), OmbiRoles.AutoApproveTv)).ReturnsAsync(true);
var request = new BaseRequest() { RequestType = Store.Entities.RequestType.Movie };
var request = new MovieRequests() { RequestType = Store.Entities.RequestType.Movie };
var result = await Rule.Execute(request);
Assert.True(result.Success);
@ -126,7 +148,7 @@ namespace Ombi.Core.Tests.Rule.Request
public async Task Should_ReturnFail_WhenNoClaimsAndRequestMovie()
{
UserManager.Setup(x => x.IsInRoleAsync(It.IsAny<OmbiUser>(), It.IsAny<string>())).ReturnsAsync(false);
var request = new BaseRequest() { RequestType = Store.Entities.RequestType.Movie };
var request = new MovieRequests() { RequestType = Store.Entities.RequestType.Movie };
var result = await Rule.Execute(request);
Assert.True(result.Success);

@ -51,11 +51,20 @@ namespace Ombi.Core.Tests.Rule.Request
}
[Test]
public async Task Should_ReturnSuccess_WhenRequestingMovie4KWithMovieRole()
public async Task Should_ReturnSuccess_WhenRequestingMovieWithAutoApproveRole()
{
UserManager.Setup(x => x.IsInRoleAsync(It.IsAny<OmbiUser>(), OmbiRoles.AutoApproveMovie)).ReturnsAsync(true);
var request = new MovieRequests() { RequestType = Store.Entities.RequestType.Movie };
var result = await Rule.Execute(request);
Assert.True(result.Success);
}
[Test]
public async Task Should_ReturnSuccess_WhenRequestingMovie4KWithMovie4KRole()
{
UserManager.Setup(x => x.IsInRoleAsync(It.IsAny<OmbiUser>(), OmbiRoles.RequestMovie)).ReturnsAsync(true);
UserManager.Setup(x => x.IsInRoleAsync(It.IsAny<OmbiUser>(), OmbiRoles.Request4KMovie)).ReturnsAsync(true);
var request = new MovieRequests() { RequestType = Store.Entities.RequestType.Movie, Has4KRequest = true };
var request = new MovieRequests() { RequestType = Store.Entities.RequestType.Movie, Is4kRequest = true };
var result = await Rule.Execute(request);
Assert.True(result.Success);
@ -74,15 +83,29 @@ namespace Ombi.Core.Tests.Rule.Request
}
[Test]
public async Task Should_ReturnSuccess_WhenRequestingMovie4KWithAutoApprove()
public async Task Should_ReturnSuccess_WhenRequestingMovie4KWithAutoApprove4K()
{
UserManager.Setup(x => x.IsInRoleAsync(It.IsAny<OmbiUser>(), OmbiRoles.RequestMovie)).ReturnsAsync(false);
UserManager.Setup(x => x.IsInRoleAsync(It.IsAny<OmbiUser>(), OmbiRoles.AutoApproveMovie)).ReturnsAsync(false);
UserManager.Setup(x => x.IsInRoleAsync(It.IsAny<OmbiUser>(), OmbiRoles.Request4KMovie)).ReturnsAsync(false);
UserManager.Setup(x => x.IsInRoleAsync(It.IsAny<OmbiUser>(), OmbiRoles.AutoApprove4KMovie)).ReturnsAsync(true);
var request = new MovieRequests() { RequestType = Store.Entities.RequestType.Movie, Is4kRequest = true };
var result = await Rule.Execute(request);
Assert.True(result.Success);
}
[Test]
public async Task Should_ReturnFailure_WhenRequestingMovie4KWithout4KRoles()
{
UserManager.Setup(x => x.IsInRoleAsync(It.IsAny<OmbiUser>(), OmbiRoles.RequestMovie)).ReturnsAsync(true);
UserManager.Setup(x => x.IsInRoleAsync(It.IsAny<OmbiUser>(), OmbiRoles.AutoApproveMovie)).ReturnsAsync(true);
UserManager.Setup(x => x.IsInRoleAsync(It.IsAny<OmbiUser>(), OmbiRoles.Request4KMovie)).ReturnsAsync(false);
var request = new MovieRequests() { RequestType = Store.Entities.RequestType.Movie, Has4KRequest = true };
UserManager.Setup(x => x.IsInRoleAsync(It.IsAny<OmbiUser>(), OmbiRoles.AutoApprove4KMovie)).ReturnsAsync(false);
var request = new MovieRequests() { RequestType = Store.Entities.RequestType.Movie, Is4kRequest = true };
var result = await Rule.Execute(request);
Assert.True(result.Success);
Assert.False(result.Success);
}
[Test]

@ -36,7 +36,7 @@ namespace Ombi.Core.Rule.Rules.Request
{
if (obj is MovieRequests movie)
{
await Check4K(movie);
await ApproveMovie(movie);
}
else
{
@ -45,10 +45,14 @@ namespace Ombi.Core.Rule.Rules.Request
return Success();
}
if (obj.RequestType == RequestType.Movie && await _manager.IsInRoleAsync(user, OmbiRoles.AutoApproveMovie))
if (obj.RequestType == RequestType.Movie)
{
var movie = (MovieRequests)obj;
await Check4K(movie);
var autoApproveRole = movie.Is4kRequest ? OmbiRoles.AutoApprove4KMovie : OmbiRoles.AutoApproveMovie;
if (await _manager.IsInRoleAsync(user, autoApproveRole))
{
await ApproveMovie(movie);
}
}
if (obj.RequestType == RequestType.TvShow && await _manager.IsInRoleAsync(user, OmbiRoles.AutoApproveTv))
obj.Approved = true;
@ -57,7 +61,7 @@ namespace Ombi.Core.Rule.Rules.Request
return Success(); // We don't really care, we just don't set the obj to approve
}
private async Task Check4K(MovieRequests movie)
private async Task ApproveMovie(MovieRequests movie)
{
var featureEnabled = await _featureService.FeatureEnabled(FeatureNames.Movie4KRequests);
if (movie.Is4kRequest && featureEnabled)

@ -36,21 +36,13 @@ namespace Ombi.Core.Rule.Rules.Request
if (obj.RequestType == RequestType.Movie)
{
var movie = (MovieRequests)obj;
var hasAutoApprove = await _manager.IsInRoleAsync(user, OmbiRoles.AutoApproveMovie);
if (await _manager.IsInRoleAsync(user, OmbiRoles.RequestMovie) || hasAutoApprove)
var requestRole = movie.Is4kRequest ? OmbiRoles.Request4KMovie : OmbiRoles.RequestMovie;
var autoApproveRole = movie.Is4kRequest ? OmbiRoles.AutoApprove4KMovie : OmbiRoles.AutoApproveMovie;
if (await _manager.IsInRoleAsync(user, requestRole) || await _manager.IsInRoleAsync(user, autoApproveRole))
{
if (movie.Is4kRequest && !hasAutoApprove)
{
var has4kPermission = await _manager.IsInRoleAsync(user, OmbiRoles.Request4KMovie);
if (has4kPermission)
{
return Success();
}
}
else
{
return Success();
}
return Success();
}
return Fail(ErrorCode.NoPermissionsRequestMovie, "You do not have permissions to Request a Movie");
}

@ -2,7 +2,7 @@
{
public static class OmbiRoles
{
// DONT FORGET TO ADD TO IDENTITYCONTROLLER.CREATEROLES AND THE UI!
// DONT FORGET TO ADD TO IDENTITYCONTROLLER.CREATEROLES!
public const string Admin = nameof(Admin);
public const string AutoApproveMovie = nameof(AutoApproveMovie);
@ -17,5 +17,6 @@
public const string ManageOwnRequests = nameof(ManageOwnRequests);
public const string EditCustomPage = nameof(EditCustomPage);
public const string Request4KMovie = nameof(Request4KMovie);
public const string AutoApprove4KMovie = nameof(AutoApprove4KMovie);
}
}

@ -0,0 +1,20 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Ombi.Helpers;
#nullable disable
namespace Ombi.Store.Migrations.OmbiMySql
{
public partial class Approve4KMovie : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.InsertRoleMySql(OmbiRoles.AutoApprove4KMovie);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}

@ -16,7 +16,7 @@ namespace Ombi.Store.Migrations.OmbiMySql
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "6.0.0")
.HasAnnotation("ProductVersion", "6.0.9")
.HasAnnotation("Relational:MaxIdentifierLength", 64);
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>

@ -0,0 +1,20 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Ombi.Helpers;
#nullable disable
namespace Ombi.Store.Migrations.OmbiSqlite
{
public partial class Approve4KMovie : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.InsertRole(OmbiRoles.AutoApprove4KMovie);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}

@ -15,7 +15,7 @@ namespace Ombi.Store.Migrations.OmbiSqlite
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "6.0.0");
modelBuilder.HasAnnotation("ProductVersion", "6.0.9");
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
{

@ -60,7 +60,7 @@ export class UserManagementUserComponent implements OnInit {
this.identityService.getUserById(this.userId).subscribe(x => {
this.user = x;
if (!is4KEnabled) {
this.user.claims = this.user.claims.filter(x => x.value !== "Request4KMovie");
this.user.claims = this.user.claims.filter(x => x.value !== "Request4KMovie" && x.value !== "AutoApprove4KMovie");
}
});
this.requestLimitTypes = [RequestLimitType.Day, RequestLimitType.Week, RequestLimitType.Month];
@ -68,7 +68,7 @@ export class UserManagementUserComponent implements OnInit {
this.identityService.getAllAvailableClaims().subscribe(x => {
this.availableClaims = x;
if (!is4KEnabled) {
this.availableClaims = this.availableClaims.filter(y => y.value !== "Request4KMovie");
this.availableClaims = this.availableClaims.filter(y => y.value !== "Request4KMovie" && y.value !== "AutoApprove4KMovie");
}
});
if(this.edit) {

@ -229,6 +229,7 @@ namespace Ombi.Controllers.V1
await CreateRole(OmbiRoles.EditCustomPage);
await CreateRole(OmbiRoles.EditCustomPage);
await CreateRole(OmbiRoles.Request4KMovie);
await CreateRole(OmbiRoles.AutoApprove4KMovie);
}
private async Task CreateRole(string role)

Loading…
Cancel
Save