From 978d4ea33b32d5a8333c75e29d4cd702e434c5f0 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Sat, 25 Sep 2021 23:26:14 +0100 Subject: [PATCH] feat(request-limits): :sparkles: Added the UI portion to set the new limits --- src/Ombi.Core/Models/UI/UserViewModel.cs | 3 ++ src/Ombi.Core/Services/RequestLimitService.cs | 14 +++++- src/Ombi.DependencyInjection/IocExtensions.cs | 2 +- .../remaining-requests.component.ts | 6 ++- .../usermanagement-user.component.html | 48 +++++++++++++++---- .../usermanagement-user.component.ts | 6 ++- src/Ombi/Controllers/V1/IdentityController.cs | 6 +++ 7 files changed, 69 insertions(+), 16 deletions(-) diff --git a/src/Ombi.Core/Models/UI/UserViewModel.cs b/src/Ombi.Core/Models/UI/UserViewModel.cs index 7ce2f7e7c..35136123b 100644 --- a/src/Ombi.Core/Models/UI/UserViewModel.cs +++ b/src/Ombi.Core/Models/UI/UserViewModel.cs @@ -24,6 +24,9 @@ public class UserViewModel public RequestQuotaCountModel MusicRequestQuota { get; set; } public int MusicRequestLimit { get; set; } public UserQualityProfiles UserQualityProfiles { get; set; } + public RequestLimitType MovieRequestLimitType { get; set; } + public RequestLimitType MusicRequestLimitType { get; set; } + public RequestLimitType EpisodeRequestLimitType { get; set; } } public class ClaimCheckboxes diff --git a/src/Ombi.Core/Services/RequestLimitService.cs b/src/Ombi.Core/Services/RequestLimitService.cs index 2872e69dd..a3d25d0c4 100644 --- a/src/Ombi.Core/Services/RequestLimitService.cs +++ b/src/Ombi.Core/Services/RequestLimitService.cs @@ -20,12 +20,16 @@ public interface IRequestLimitService Task GetRemainingTvRequests(OmbiUser user = default); Task GetRemainingMusicRequests(OmbiUser user = default); } - public class RequestLimitService : BaseEngine, IRequestLimitService + public class RequestLimitService : IRequestLimitService { + private readonly IPrincipal _user; + private readonly OmbiUserManager _userManager; private readonly IRepository _requestLog; - public RequestLimitService(IPrincipal user, OmbiUserManager um, IRuleEvaluator rules, IRepository rl) : base(user, um, rules) + public RequestLimitService(IPrincipal user, OmbiUserManager userManager, IRepository rl) { + _user = user; + _userManager = userManager; _requestLog = rl; } @@ -129,6 +133,12 @@ public async Task GetRemainingMusicRequests(OmbiUser use return await CalculateBasicRemaingRequests(user, limit, user.MusicRequestLimitType ?? RequestLimitType.Day, log); } + private async Task GetUser() + { + var username = _user.Identity.Name.ToUpper(); + return await _userManager.Users.FirstOrDefaultAsync(x => x.NormalizedUserName == username); + } + private static async Task CalculateBasicRemaingRequests(OmbiUser user, int limit, RequestLimitType type, IQueryable log) { int count = 0; diff --git a/src/Ombi.DependencyInjection/IocExtensions.cs b/src/Ombi.DependencyInjection/IocExtensions.cs index 0adde9cff..f81cd05da 100644 --- a/src/Ombi.DependencyInjection/IocExtensions.cs +++ b/src/Ombi.DependencyInjection/IocExtensions.cs @@ -81,10 +81,10 @@ public static void RegisterApplicationDependencies(this IServiceCollection servi services.RegisterEngines(); services.RegisterEnginesV2(); services.RegisterApi(); + services.RegisterHttp(); services.RegisterServices(); services.RegisterStore(); services.RegisterJobs(); - services.RegisterHttp(); } public static void RegisterEngines(this IServiceCollection services) diff --git a/src/Ombi/ClientApp/src/app/shared/remaining-requests/remaining-requests.component.ts b/src/Ombi/ClientApp/src/app/shared/remaining-requests/remaining-requests.component.ts index 110053e75..008fa2186 100644 --- a/src/Ombi/ClientApp/src/app/shared/remaining-requests/remaining-requests.component.ts +++ b/src/Ombi/ClientApp/src/app/shared/remaining-requests/remaining-requests.component.ts @@ -1,8 +1,10 @@ import { Component, Input, OnInit } from "@angular/core"; -import { TranslateService } from "@ngx-translate/core"; -import { RequestType } from "../../interfaces"; + import { IRemainingRequests } from "../../interfaces/IRemainingRequests"; import { RequestService } from "../../services"; +import { RequestType } from "../../interfaces"; +import { TranslateService } from "@ngx-translate/core"; + @Component({ selector: "app-remaining-requests", templateUrl: "remaining-requests.component.html", diff --git a/src/Ombi/ClientApp/src/app/usermanagement/usermanagement-user.component.html b/src/Ombi/ClientApp/src/app/usermanagement/usermanagement-user.component.html index e247f0ea1..c8eda1a87 100644 --- a/src/Ombi/ClientApp/src/app/usermanagement/usermanagement-user.component.html +++ b/src/Ombi/ClientApp/src/app/usermanagement/usermanagement-user.component.html @@ -42,21 +42,51 @@
-
- - - +
+
+ + + +
+
+ Movie Request Limit Type + + + {{RequestLimitType[value]}} + + +
-
- - - +
+
+ + + +
+
+ Episode Request Limit Type + + + {{RequestLimitType[value]}} + + +
-
+
+
+
+ Music Request Limit Type + + + {{RequestLimitType[value]}} + + +
+
Sonarr Quality Profile diff --git a/src/Ombi/ClientApp/src/app/usermanagement/usermanagement-user.component.ts b/src/Ombi/ClientApp/src/app/usermanagement/usermanagement-user.component.ts index c091d3861..038de9b64 100644 --- a/src/Ombi/ClientApp/src/app/usermanagement/usermanagement-user.component.ts +++ b/src/Ombi/ClientApp/src/app/usermanagement/usermanagement-user.component.ts @@ -1,6 +1,6 @@ import { ActivatedRoute, Router } from "@angular/router"; import { Component, OnInit } from "@angular/core"; -import { ICheckbox, ICustomizationSettings, INotificationAgent, INotificationPreferences, IRadarrProfile, IRadarrRootFolder, ISonarrProfile, ISonarrRootFolder, IUser, UserType } from "../interfaces"; +import { ICheckbox, ICustomizationSettings, INotificationAgent, INotificationPreferences, IRadarrProfile, IRadarrRootFolder, ISonarrProfile, ISonarrRootFolder, IUser, RequestLimitType, UserType } from "../interfaces"; import { IdentityService, MessageService, RadarrService, SettingsService, SonarrService } from "../services"; import { Clipboard } from '@angular/cdk/clipboard'; @@ -27,6 +27,8 @@ export class UserManagementUserComponent implements OnInit { public edit: boolean; public countries: string[]; + public requestLimitTypes: RequestLimitType[]; + public RequestLimitType = RequestLimitType; private customization: ICustomizationSettings; private accessToken: string; @@ -53,7 +55,7 @@ export class UserManagementUserComponent implements OnInit { } public ngOnInit() { - + this.requestLimitTypes = [RequestLimitType.Day, RequestLimitType.Week, RequestLimitType.Month]; this.identityService.getSupportedStreamingCountries().subscribe(x => this.countries = x); this.identityService.getAllAvailableClaims().subscribe(x => this.availableClaims = x); if(this.edit) { diff --git a/src/Ombi/Controllers/V1/IdentityController.cs b/src/Ombi/Controllers/V1/IdentityController.cs index c010f0c02..a186f6694 100644 --- a/src/Ombi/Controllers/V1/IdentityController.cs +++ b/src/Ombi/Controllers/V1/IdentityController.cs @@ -399,6 +399,9 @@ private async Task GetUserWithRoles(OmbiUser user) EpisodeRequestLimit = user.EpisodeRequestLimit ?? 0, MovieRequestLimit = user.MovieRequestLimit ?? 0, MusicRequestLimit = user.MusicRequestLimit ?? 0, + MovieRequestLimitType = user.MovieRequestLimitType ?? RequestLimitType.Week, + EpisodeRequestLimitType = user.EpisodeRequestLimitType ?? RequestLimitType.Week, + MusicRequestLimitType = user.MusicRequestLimitType ?? RequestLimitType.Week, Language = user.Language, StreamingCountry = user.StreamingCountry }; @@ -641,6 +644,9 @@ public async Task UpdateUser([FromBody] UserViewModel ui) user.MovieRequestLimit = ui.MovieRequestLimit; user.EpisodeRequestLimit = ui.EpisodeRequestLimit; user.MusicRequestLimit = ui.MusicRequestLimit; + user.EpisodeRequestLimitType = ui.EpisodeRequestLimitType; + user.MusicRequestLimitType = ui.MusicRequestLimitType; + user.MovieRequestLimitType = ui.MovieRequestLimitType; if (ui.Password.HasValue()) { user.PasswordHash = UserManager.PasswordHasher.HashPassword(user, ui.Password);