mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-13 00:32:57 -07:00
Merge pull request #2496 from MrTopCat/display-quota-on-user-managment
Display quota on user managment page
This commit is contained in:
commit
97c51a3be1
10 changed files with 91 additions and 16 deletions
|
@ -23,6 +23,6 @@ namespace Ombi.Core.Engine.Interfaces
|
||||||
Task<int> GetTotal();
|
Task<int> GetTotal();
|
||||||
Task UnSubscribeRequest(int requestId, RequestType type);
|
Task UnSubscribeRequest(int requestId, RequestType type);
|
||||||
Task SubscribeToRequest(int requestId, RequestType type);
|
Task SubscribeToRequest(int requestId, RequestType type);
|
||||||
Task<RequestQuotaCountModel> GetRemainingRequests();
|
Task<RequestQuotaCountModel> GetRemainingRequests(OmbiUser user = null);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -486,9 +486,19 @@ namespace Ombi.Core.Engine
|
||||||
return new RequestEngineResult {Result = true, Message = $"{movieName} has been successfully added!"};
|
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();
|
||||||
|
|
||||||
|
// If user is still null after attempting to get the logged in user, return null.
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int limit = user.MovieRequestLimit ?? 0;
|
int limit = user.MovieRequestLimit ?? 0;
|
||||||
|
|
||||||
if (limit <= 0)
|
if (limit <= 0)
|
||||||
|
|
|
@ -588,6 +588,15 @@ namespace Ombi.Core.Engine
|
||||||
NotificationHelper.NewRequest(model);
|
NotificationHelper.NewRequest(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await _requestLog.Add(new RequestLog
|
||||||
|
{
|
||||||
|
UserId = (await GetUser()).Id,
|
||||||
|
RequestDate = DateTime.UtcNow,
|
||||||
|
RequestId = model.Id,
|
||||||
|
RequestType = RequestType.TvShow,
|
||||||
|
EpisodeCount = model.SeasonRequests.Select(m => m.Episodes.Count).Sum(),
|
||||||
|
});
|
||||||
|
|
||||||
if (model.Approved)
|
if (model.Approved)
|
||||||
{
|
{
|
||||||
// Autosend
|
// Autosend
|
||||||
|
@ -603,21 +612,22 @@ namespace Ombi.Core.Engine
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
await _requestLog.Add(new RequestLog
|
|
||||||
{
|
|
||||||
UserId = (await GetUser()).Id,
|
|
||||||
RequestDate = DateTime.UtcNow,
|
|
||||||
RequestId = model.Id,
|
|
||||||
RequestType = RequestType.TvShow,
|
|
||||||
EpisodeCount = model.SeasonRequests.Select(m => m.Episodes.Count).Sum(),
|
|
||||||
});
|
|
||||||
|
|
||||||
return new RequestEngineResult { Result = true };
|
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();
|
||||||
|
|
||||||
|
// If user is still null after attempting to get the logged in user, return null.
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int limit = user.EpisodeRequestLimit ?? 0;
|
int limit = user.EpisodeRequestLimit ?? 0;
|
||||||
|
|
||||||
if (limit <= 0)
|
if (limit <= 0)
|
||||||
|
|
|
@ -16,6 +16,8 @@ namespace Ombi.Core.Models.UI
|
||||||
public UserType UserType { get; set; }
|
public UserType UserType { get; set; }
|
||||||
public int MovieRequestLimit { get; set; }
|
public int MovieRequestLimit { get; set; }
|
||||||
public int EpisodeRequestLimit { get; set; }
|
public int EpisodeRequestLimit { get; set; }
|
||||||
|
public RequestQuotaCountModel EpisodeRequestQuota { get; set; }
|
||||||
|
public RequestQuotaCountModel MovieRequestQuota { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ClaimCheckboxes
|
public class ClaimCheckboxes
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { ICheckbox } from ".";
|
import { ICheckbox } from ".";
|
||||||
|
import { IRemainingRequests } from "./IRemainingRequests";
|
||||||
|
|
||||||
export interface IUser {
|
export interface IUser {
|
||||||
id: string;
|
id: string;
|
||||||
|
@ -13,7 +14,10 @@ export interface IUser {
|
||||||
movieRequestLimit: number;
|
movieRequestLimit: number;
|
||||||
episodeRequestLimit: number;
|
episodeRequestLimit: number;
|
||||||
userAccessToken: string;
|
userAccessToken: string;
|
||||||
|
|
||||||
// FOR UI
|
// FOR UI
|
||||||
|
episodeRequestQuota: IRemainingRequests | null;
|
||||||
|
movieRequestQuota: IRemainingRequests | null;
|
||||||
checked: boolean;
|
checked: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,8 @@ export class UserManagementAddComponent implements OnInit {
|
||||||
episodeRequestLimit: 0,
|
episodeRequestLimit: 0,
|
||||||
movieRequestLimit: 0,
|
movieRequestLimit: 0,
|
||||||
userAccessToken: "",
|
userAccessToken: "",
|
||||||
|
episodeRequestQuota: null,
|
||||||
|
movieRequestQuota: null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,12 @@
|
||||||
<th>
|
<th>
|
||||||
Roles
|
Roles
|
||||||
</th>
|
</th>
|
||||||
|
<th>
|
||||||
|
Requests Remaining
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Next Request Due
|
||||||
|
</th>
|
||||||
<th (click)="setOrder('lastLoggedIn', $event)">
|
<th (click)="setOrder('lastLoggedIn', $event)">
|
||||||
<a> Last Logged In</a>
|
<a> Last Logged In</a>
|
||||||
<span *ngIf="order === 'lastLoggedIn'">
|
<span *ngIf="order === 'lastLoggedIn'">
|
||||||
|
@ -85,6 +91,22 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
|
<td class="td-labelled" data-label="Requests Remaining">
|
||||||
|
<div *ngIf="u.movieRequestQuota != null && u.movieRequestQuota.hasLimit">
|
||||||
|
{{'UserManagment.MovieRemaining' | translate: {remaining: u.movieRequestQuota.remaining, total: u.movieRequestLimit} }}
|
||||||
|
</div>
|
||||||
|
<div *ngIf="u.episodeRequestQuota != null && u.episodeRequestQuota.hasLimit">
|
||||||
|
{{'UserManagment.TvRemaining' | translate: {remaining: u.episodeRequestQuota.remaining, total: u.episodeRequestLimit} }}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td class="td-labelled" data-label="Request Due">
|
||||||
|
<div *ngIf="u.movieRequestQuota != null && u.movieRequestQuota.remaining != u.movieRequestLimit">
|
||||||
|
{{'UserManagment.MovieDue' | translate: {date: (u.movieRequestQuota.nextRequest | date: 'short')} }}
|
||||||
|
</div>
|
||||||
|
<div *ngIf="u.episodeRequestQuota != null && u.episodeRequestQuota.remaining != u.episodeRequestLimit">
|
||||||
|
{{'UserManagment.TvDue' | translate: {date: (u.episodeRequestQuota.nextRequest | date: 'short')} }}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
<td class="td-labelled" data-label="Last Logged In:">
|
<td class="td-labelled" data-label="Last Logged In:">
|
||||||
{{u.lastLoggedIn | date: 'short'}}
|
{{u.lastLoggedIn | date: 'short'}}
|
||||||
</td>
|
</td>
|
||||||
|
|
|
@ -19,6 +19,8 @@ import { AuthGuard } from "../auth/auth.guard";
|
||||||
import { OrderModule } from "ngx-order-pipe";
|
import { OrderModule } from "ngx-order-pipe";
|
||||||
import { AddPlexUserComponent } from "./addplexuser.component";
|
import { AddPlexUserComponent } from "./addplexuser.component";
|
||||||
|
|
||||||
|
import { SharedModule } from "../shared/shared.module";
|
||||||
|
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
{ path: "", component: UserManagementComponent, canActivate: [AuthGuard] },
|
{ path: "", component: UserManagementComponent, canActivate: [AuthGuard] },
|
||||||
{ path: "add", component: UserManagementAddComponent, canActivate: [AuthGuard] },
|
{ path: "add", component: UserManagementAddComponent, canActivate: [AuthGuard] },
|
||||||
|
@ -39,6 +41,7 @@ const routes: Routes = [
|
||||||
TooltipModule,
|
TooltipModule,
|
||||||
OrderModule,
|
OrderModule,
|
||||||
SidebarModule,
|
SidebarModule,
|
||||||
|
SharedModule,
|
||||||
],
|
],
|
||||||
declarations: [
|
declarations: [
|
||||||
UserManagementComponent,
|
UserManagementComponent,
|
||||||
|
|
|
@ -16,6 +16,7 @@ using Ombi.Api.Plex;
|
||||||
using Ombi.Attributes;
|
using Ombi.Attributes;
|
||||||
using Ombi.Config;
|
using Ombi.Config;
|
||||||
using Ombi.Core.Authentication;
|
using Ombi.Core.Authentication;
|
||||||
|
using Ombi.Core.Engine.Interfaces;
|
||||||
using Ombi.Core.Helpers;
|
using Ombi.Core.Helpers;
|
||||||
using Ombi.Core.Models.UI;
|
using Ombi.Core.Models.UI;
|
||||||
using Ombi.Core.Settings;
|
using Ombi.Core.Settings;
|
||||||
|
@ -60,7 +61,9 @@ namespace Ombi.Controllers
|
||||||
IRepository<IssueComments> issueComments,
|
IRepository<IssueComments> issueComments,
|
||||||
IRepository<NotificationUserId> notificationRepository,
|
IRepository<NotificationUserId> notificationRepository,
|
||||||
IRepository<RequestSubscription> subscriptionRepository,
|
IRepository<RequestSubscription> subscriptionRepository,
|
||||||
ISettingsService<UserManagementSettings> umSettings)
|
ISettingsService<UserManagementSettings> umSettings,
|
||||||
|
IMovieRequestEngine movieRequestEngine,
|
||||||
|
ITvRequestEngine tvRequestEngine)
|
||||||
{
|
{
|
||||||
UserManager = user;
|
UserManager = user;
|
||||||
Mapper = mapper;
|
Mapper = mapper;
|
||||||
|
@ -81,6 +84,8 @@ namespace Ombi.Controllers
|
||||||
_requestSubscriptionRepository = subscriptionRepository;
|
_requestSubscriptionRepository = subscriptionRepository;
|
||||||
_notificationRepository = notificationRepository;
|
_notificationRepository = notificationRepository;
|
||||||
_userManagementSettings = umSettings;
|
_userManagementSettings = umSettings;
|
||||||
|
TvRequestEngine = tvRequestEngine;
|
||||||
|
MovieRequestEngine = movieRequestEngine;
|
||||||
}
|
}
|
||||||
|
|
||||||
private OmbiUserManager UserManager { get; }
|
private OmbiUserManager UserManager { get; }
|
||||||
|
@ -94,6 +99,8 @@ namespace Ombi.Controllers
|
||||||
private IWelcomeEmail WelcomeEmail { get; }
|
private IWelcomeEmail WelcomeEmail { get; }
|
||||||
private IMovieRequestRepository MovieRepo { get; }
|
private IMovieRequestRepository MovieRepo { get; }
|
||||||
private ITvRequestRepository TvRepo { get; }
|
private ITvRequestRepository TvRepo { get; }
|
||||||
|
private IMovieRequestEngine MovieRequestEngine { get; }
|
||||||
|
private ITvRequestEngine TvRequestEngine { get; }
|
||||||
private readonly ILogger<IdentityController> _log;
|
private readonly ILogger<IdentityController> _log;
|
||||||
private readonly IPlexApi _plexApi;
|
private readonly IPlexApi _plexApi;
|
||||||
private readonly ISettingsService<PlexSettings> _plexSettings;
|
private readonly ISettingsService<PlexSettings> _plexSettings;
|
||||||
|
@ -103,7 +110,6 @@ namespace Ombi.Controllers
|
||||||
private readonly IRepository<NotificationUserId> _notificationRepository;
|
private readonly IRepository<NotificationUserId> _notificationRepository;
|
||||||
private readonly IRepository<RequestSubscription> _requestSubscriptionRepository;
|
private readonly IRepository<RequestSubscription> _requestSubscriptionRepository;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is what the Wizard will call when creating the user for the very first time.
|
/// This is what the Wizard will call when creating the user for the very first time.
|
||||||
/// This should never be called after this.
|
/// 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;
|
return vm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -184,5 +184,11 @@
|
||||||
"FilterHeaderRequestStatus":"Status",
|
"FilterHeaderRequestStatus":"Status",
|
||||||
"Approved":"Approved",
|
"Approved":"Approved",
|
||||||
"PendingApproval": "Pending Approval"
|
"PendingApproval": "Pending Approval"
|
||||||
|
},
|
||||||
|
"UserManagment": {
|
||||||
|
"TvRemaining": "TV: {{remaining}}/{{total}} remaining",
|
||||||
|
"MovieRemaining": "Movies: {{remaining}}/{{total}} remaining",
|
||||||
|
"TvDue": "TV: {{date}}",
|
||||||
|
"MovieDue": "Movie: {{date}}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue