Skip to content

Commit

Permalink
feat(request-limits): ✨ Added the UI portion to set the new limits
Browse files Browse the repository at this point in the history
  • Loading branch information
tidusjar committed Sep 25, 2021
1 parent a6e8eef commit 978d4ea
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 16 deletions.
3 changes: 3 additions & 0 deletions src/Ombi.Core/Models/UI/UserViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions src/Ombi.Core/Services/RequestLimitService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ public interface IRequestLimitService
Task<RequestQuotaCountModel> GetRemainingTvRequests(OmbiUser user = default);
Task<RequestQuotaCountModel> 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> _requestLog;

public RequestLimitService(IPrincipal user, OmbiUserManager um, IRuleEvaluator rules, IRepository<RequestLog> rl) : base(user, um, rules)
public RequestLimitService(IPrincipal user, OmbiUserManager userManager, IRepository<RequestLog> rl)
{
_user = user;
_userManager = userManager;
_requestLog = rl;
}

Expand Down Expand Up @@ -129,6 +133,12 @@ public async Task<RequestQuotaCountModel> GetRemainingMusicRequests(OmbiUser use
return await CalculateBasicRemaingRequests(user, limit, user.MusicRequestLimitType ?? RequestLimitType.Day, log);
}

private async Task<OmbiUser> GetUser()
{
var username = _user.Identity.Name.ToUpper();
return await _userManager.Users.FirstOrDefaultAsync(x => x.NormalizedUserName == username);
}

private static async Task<RequestQuotaCountModel> CalculateBasicRemaingRequests(OmbiUser user, int limit, RequestLimitType type, IQueryable<RequestLog> log)
{
int count = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/Ombi.DependencyInjection/IocExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,51 @@

<div class="col-md-3 col-sm-12">
<label class="control-label"><h3>Request Limits</h3></label>
<div>
<mat-form-field>
<input id="movieRequestLimit" matInput placeholder="Movie Request Limit" [(ngModel)]="user.movieRequestLimit">
</mat-form-field>
<div class="row">
<div class="col-6">
<mat-form-field>
<input id="movieRequestLimit" matInput placeholder="Movie Request Limit" [(ngModel)]="user.movieRequestLimit">
</mat-form-field>
</div>
<div class="col-6">
<mat-label>Movie Request Limit Type</mat-label>
<mat-select [(value)]="user.movieRequestLimitType">
<mat-option *ngFor="let value of requestLimitTypes" [value]="value">
{{RequestLimitType[value]}}
</mat-option>
</mat-select>
</div>
</div>
<div>
<mat-form-field>
<input id="episodeRequestLimit" matInput placeholder="Episode Request Limit" [(ngModel)]="user.episodeRequestLimit">
</mat-form-field>
<div class="row">
<div class="col-6">
<mat-form-field>
<input id="episodeRequestLimit" matInput placeholder="Episode Request Limit" [(ngModel)]="user.episodeRequestLimit">
</mat-form-field>
</div>
<div class="col-6">
<mat-label>Episode Request Limit Type</mat-label>
<mat-select [(value)]="user.episodeRequestLimitType">
<mat-option *ngFor="let value of requestLimitTypes" [value]="value">
{{RequestLimitType[value]}}
</mat-option>
</mat-select>
</div>
</div>
<div>
<div class="row">
<div class="col-6">
<mat-form-field>
<input id="musicRequestLimit" matInput placeholder="Music Request Limit" [(ngModel)]="user.musicRequestLimit">
</mat-form-field>
</div>
<div class="col-6">
<mat-label>Music Request Limit Type</mat-label>
<mat-select [(value)]="user.musicRequestLimitType">
<mat-option *ngFor="let value of requestLimitTypes" [value]="value">
{{RequestLimitType[value]}}
</mat-option>
</mat-select>
</div>
</div>
<label class="control-label"><h3>Quality & Root Path Preferences</h3></label>
<mat-form-field *ngIf="sonarrQualities">
<mat-label>Sonarr Quality Profile</mat-label>
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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;
Expand All @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions src/Ombi/Controllers/V1/IdentityController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,9 @@ private async Task<UserViewModel> 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
};
Expand Down Expand Up @@ -641,6 +644,9 @@ public async Task<OmbiIdentityResult> 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);
Expand Down

0 comments on commit 978d4ea

Please sign in to comment.