Add quota fields to user view model

pull/2496/head
Kenton Royal 6 years ago
parent cfd9deb17e
commit 9c574fb7e9

@ -23,6 +23,6 @@ namespace Ombi.Core.Engine.Interfaces
Task<int> GetTotal();
Task UnSubscribeRequest(int requestId, RequestType type);
Task SubscribeToRequest(int requestId, RequestType type);
Task<RequestQuotaCountModel> GetRemainingRequests();
Task<RequestQuotaCountModel> GetRemainingRequests(OmbiUser user = null);
}
}

@ -486,9 +486,13 @@ namespace Ombi.Core.Engine
return new RequestEngineResult {Result = true, Message = $"{movieName} has been successfully added!"};
}
public async Task<RequestQuotaCountModel> GetRemainingRequests()
public async Task<RequestQuotaCountModel> GetRemainingRequests(OmbiUser user)
{
OmbiUser user = await GetUser();
if (user == null)
{
user = await GetUser();
}
int limit = user.MovieRequestLimit ?? 0;
if (limit <= 0)

@ -615,9 +615,13 @@ namespace Ombi.Core.Engine
return new RequestEngineResult { Result = true };
}
public async Task<RequestQuotaCountModel> GetRemainingRequests()
public async Task<RequestQuotaCountModel> GetRemainingRequests(OmbiUser user)
{
OmbiUser user = await GetUser();
if (user == null)
{
user = await GetUser();
}
int limit = user.EpisodeRequestLimit ?? 0;
if (limit <= 0)

@ -16,6 +16,8 @@ namespace Ombi.Core.Models.UI
public UserType UserType { get; set; }
public int MovieRequestLimit { get; set; }
public int EpisodeRequestLimit { get; set; }
public RequestQuotaCountModel EpisodeRequestQuota { get; set; }
public RequestQuotaCountModel MovieRequestQuota { get; set; }
}
public class ClaimCheckboxes

@ -1,4 +1,5 @@
import { ICheckbox } from ".";
import { IRemainingRequests } from "./IRemainingRequests";
export interface IUser {
id: string;
@ -13,7 +14,10 @@ export interface IUser {
movieRequestLimit: number;
episodeRequestLimit: number;
userAccessToken: string;
// FOR UI
episodeRequestQuota: IRemainingRequests | null;
movieRequestQuota: IRemainingRequests | null;
checked: boolean;
}

@ -32,6 +32,8 @@ export class UserManagementAddComponent implements OnInit {
episodeRequestLimit: 0,
movieRequestLimit: 0,
userAccessToken: "",
episodeRequestQuota: null,
movieRequestQuota: null,
};
}

@ -16,6 +16,7 @@ using Ombi.Api.Plex;
using Ombi.Attributes;
using Ombi.Config;
using Ombi.Core.Authentication;
using Ombi.Core.Engine.Interfaces;
using Ombi.Core.Helpers;
using Ombi.Core.Models.UI;
using Ombi.Core.Settings;
@ -60,7 +61,9 @@ namespace Ombi.Controllers
IRepository<IssueComments> issueComments,
IRepository<NotificationUserId> notificationRepository,
IRepository<RequestSubscription> subscriptionRepository,
ISettingsService<UserManagementSettings> umSettings)
ISettingsService<UserManagementSettings> umSettings,
IMovieRequestEngine movieRequestEngine,
ITvRequestEngine tvRequestEngine)
{
UserManager = user;
Mapper = mapper;
@ -81,6 +84,8 @@ namespace Ombi.Controllers
_requestSubscriptionRepository = subscriptionRepository;
_notificationRepository = notificationRepository;
_userManagementSettings = umSettings;
TvRequestEngine = tvRequestEngine;
MovieRequestEngine = movieRequestEngine;
}
private OmbiUserManager UserManager { get; }
@ -94,6 +99,8 @@ namespace Ombi.Controllers
private IWelcomeEmail WelcomeEmail { get; }
private IMovieRequestRepository MovieRepo { get; }
private ITvRequestRepository TvRepo { get; }
private IMovieRequestEngine MovieRequestEngine { get; }
private ITvRequestEngine TvRequestEngine { get; }
private readonly ILogger<IdentityController> _log;
private readonly IPlexApi _plexApi;
private readonly ISettingsService<PlexSettings> _plexSettings;
@ -103,7 +110,6 @@ namespace Ombi.Controllers
private readonly IRepository<NotificationUserId> _notificationRepository;
private readonly IRepository<RequestSubscription> _requestSubscriptionRepository;
/// <summary>
/// This is what the Wizard will call when creating the user for the very first time.
/// This should never be called after this.
@ -316,6 +322,16 @@ namespace Ombi.Controllers
});
}
if (vm.EpisodeRequestLimit > 0)
{
vm.EpisodeRequestQuota = await TvRequestEngine.GetRemainingRequests(user);
}
if (vm.MovieRequestLimit > 0)
{
vm.MovieRequestQuota = await MovieRequestEngine.GetRemainingRequests(user);
}
return vm;
}

Loading…
Cancel
Save