Skip to content

Commit

Permalink
Merge pull request #2069 from tidusjar/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
tidusjar authored Mar 13, 2018
2 parents b777ead + 3f04c9a commit 7e6824c
Show file tree
Hide file tree
Showing 16 changed files with 408 additions and 260 deletions.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
# Changelog

## (unreleased)

### **Fixes**

- Small memory improvements in the Plex Sync. [Jamie]

- Fixed the sort issue on the user Management page. Also added sorting to the Movie Requests page. [tidusjar]

- Downgraded the angular2-jwt library since it has a bug in it. #2064. [tidusjar]

- Fixed an issue when Plex decideds to reuse the Plex Key for a different media item... #2038. [tidusjar]

- Fixed an issue where we might show the Imdb link when we do not have a imdbid #1797. [tidusjar]

- Fixed the issue where we can no longer select Pending Approval in the filters #2057. [tidusjar]

- Fixed the API key not working when attempting to get requests #2058. [tidusjar]

- Fixed #2056. [tidusjar]

- Experimental, set the Webpack base root to the ombi base path if we have it. This should hopefully fix the reverse proxy issues. [Jamie]


## v3.0.3000 (2018-03-09)

### **New Features**
Expand Down
17 changes: 16 additions & 1 deletion src/Ombi.Core/Engine/Interfaces/BaseEngine.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Ombi.Core.Rule;
using System;
using Ombi.Core.Rule;
using System.Collections.Generic;
using System.Security.Principal;
using System.Threading.Tasks;
Expand All @@ -10,6 +11,7 @@
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Ombi.Core.Authentication;
using Ombi.Helpers;

namespace Ombi.Core.Engine.Interfaces
{
Expand All @@ -30,6 +32,13 @@ protected BaseEngine(IPrincipal user, OmbiUserManager um, IRuleEvaluator rules)
private OmbiUser _user;
protected async Task<OmbiUser> GetUser()
{
if (IsApiUser)
{
return new OmbiUser
{
UserName = Username,
};
}
return _user ?? (_user = await UserManager.Users.FirstOrDefaultAsync(x => x.UserName == Username));
}

Expand All @@ -40,6 +49,10 @@ protected async Task<string> UserAlias()

protected async Task<bool> IsInRole(string roleName)
{
if (IsApiUser && roleName != OmbiRoles.Disabled)
{
return true;
}
return await UserManager.IsInRoleAsync(await GetUser(), roleName);
}

Expand All @@ -59,5 +72,7 @@ public async Task<RuleResult> RunSpecificRule(object model, SpecificRules rule)
var ruleResults = await Rules.StartSpecificRules(model, rule);
return ruleResults;
}

private bool IsApiUser => Username.Equals("Api", StringComparison.CurrentCultureIgnoreCase);
}
}
404 changes: 223 additions & 181 deletions src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs

Large diffs are not rendered by default.

93 changes: 47 additions & 46 deletions src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ private async Task Cache(PlexServers settings)
{
if (!Validate(settings))
{

_log.LogWarning("Validation failed");
return;
}
Expand Down Expand Up @@ -101,21 +100,25 @@ private async Task GetEpisodes(PlexServers settings, Directory section)
{
var currentPosition = 0;
var resultCount = settings.EpisodeBatchSize == 0 ? 150 : settings.EpisodeBatchSize;
var currentEpisodes = _repo.GetAllEpisodes();
var episodes = await _api.GetAllEpisodes(settings.PlexAuthToken, settings.FullUri, section.key, currentPosition, resultCount);
_log.LogInformation(LoggingEvents.PlexEpisodeCacher, $"Total Epsiodes found for {episodes.MediaContainer.librarySectionTitle} = {episodes.MediaContainer.totalSize}");

// Delete all the episodes because we cannot uniquly match an episode to series every time,
// see comment below.
await _repo.ExecuteSql("DELETE FROM PlexEpisode");

await ProcessEpsiodes(episodes);
// 12.03.2017 - I think we should be able to match them now
//await _repo.ExecuteSql("DELETE FROM PlexEpisode");

await ProcessEpsiodes(episodes, currentEpisodes);
currentPosition += resultCount;

while (currentPosition < episodes.MediaContainer.totalSize)
{
var ep = await _api.GetAllEpisodes(settings.PlexAuthToken, settings.FullUri, section.key, currentPosition,
resultCount);
await ProcessEpsiodes(ep);

await ProcessEpsiodes(ep, currentEpisodes);
_log.LogInformation(LoggingEvents.PlexEpisodeCacher, $"Processed {resultCount} more episodes. Total Remaining {episodes.MediaContainer.totalSize - currentPosition}");
currentPosition += resultCount;
}
Expand All @@ -125,58 +128,56 @@ private async Task GetEpisodes(PlexServers settings, Directory section)
await _repo.SaveChangesAsync();
}

private async Task ProcessEpsiodes(PlexContainer episodes)
private async Task ProcessEpsiodes(PlexContainer episodes, IQueryable<PlexEpisode> currentEpisodes)
{
var ep = new HashSet<PlexEpisode>();
try
{


foreach (var episode in episodes?.MediaContainer?.Metadata ?? new Metadata[]{})
{
// I don't think we need to get the metadata, we only need to get the metadata if we need the provider id (TheTvDbid). Why do we need it for episodes?
// We have the parent and grandparent rating keys to link up to the season and series
//var metadata = _api.GetEpisodeMetaData(server.PlexAuthToken, server.FullUri, episode.ratingKey);

// This does seem to work, it looks like we can somehow get different rating, grandparent and parent keys with episodes. Not sure how.
//var epExists = currentEpisodes.Any(x => episode.ratingKey == x.Key &&
// episode.grandparentRatingKey == x.GrandparentKey);
//if (epExists)
//{
// continue;
//}

// Let's check if we have the parent
var seriesExists = await _repo.GetByKey(episode.grandparentRatingKey);
if (seriesExists == null)
foreach (var episode in episodes?.MediaContainer?.Metadata ?? new Metadata[] { })
{
// Ok let's try and match it to a title. TODO (This is experimental)
var seriesMatch = await _repo.GetAll().FirstOrDefaultAsync(x =>
x.Title.Equals(episode.grandparentTitle, StringComparison.CurrentCultureIgnoreCase));
if (seriesMatch == null)
// I don't think we need to get the metadata, we only need to get the metadata if we need the provider id (TheTvDbid). Why do we need it for episodes?
// We have the parent and grandparent rating keys to link up to the season and series
//var metadata = _api.GetEpisodeMetaData(server.PlexAuthToken, server.FullUri, episode.ratingKey);

// This does seem to work, it looks like we can somehow get different rating, grandparent and parent keys with episodes. Not sure how.
var epExists = currentEpisodes.Any(x => episode.ratingKey == x.Key &&
episode.grandparentRatingKey == x.GrandparentKey);
if (epExists)
{
_log.LogWarning(
"The episode title {0} we cannot find the parent series. The episode grandparentKey = {1}, grandparentTitle = {2}",
episode.title, episode.grandparentRatingKey, episode.grandparentTitle);
continue;
}

// Set the rating key to the correct one
episode.grandparentRatingKey = seriesMatch.Key;
}
// Let's check if we have the parent
var seriesExists = await _repo.GetByKey(episode.grandparentRatingKey);
if (seriesExists == null)
{
// Ok let's try and match it to a title. TODO (This is experimental)
seriesExists = await _repo.GetAll().FirstOrDefaultAsync(x =>
x.Title.Equals(episode.grandparentTitle, StringComparison.CurrentCultureIgnoreCase));
if (seriesExists == null)
{
_log.LogWarning(
"The episode title {0} we cannot find the parent series. The episode grandparentKey = {1}, grandparentTitle = {2}",
episode.title, episode.grandparentRatingKey, episode.grandparentTitle);
continue;
}

ep.Add(new PlexEpisode
{
EpisodeNumber = episode.index,
SeasonNumber = episode.parentIndex,
GrandparentKey = episode.grandparentRatingKey,
ParentKey = episode.parentRatingKey,
Key = episode.ratingKey,
Title = episode.title
});
}
// Set the rating key to the correct one
episode.grandparentRatingKey = seriesExists.Key;
}

ep.Add(new PlexEpisode
{
EpisodeNumber = episode.index,
SeasonNumber = episode.parentIndex,
GrandparentKey = episode.grandparentRatingKey,
ParentKey = episode.parentRatingKey,
Key = episode.ratingKey,
Title = episode.title
});
}

await _repo.AddRange(ep);
await _repo.AddRange(ep);
}
catch (Exception e)
{
Expand All @@ -189,7 +190,7 @@ private bool Validate(PlexServers settings)
{
if (string.IsNullOrEmpty(settings.PlexAuthToken))
{
return false ;
return false;
}

return true;
Expand Down
12 changes: 10 additions & 2 deletions src/Ombi/ClientApp/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component, OnInit } from "@angular/core";
import { PlatformLocation } from "@angular/common";
import { Component, OnInit } from "@angular/core";
import { NavigationStart, Router } from "@angular/router";
import { TranslateService } from "@ngx-translate/core";
import { AuthService } from "./auth/auth.service";
Expand Down Expand Up @@ -32,7 +33,14 @@ export class AppComponent implements OnInit {
private readonly settingsService: SettingsService,
private readonly jobService: JobService,
public readonly translate: TranslateService,
private readonly identityService: IdentityService) {
private readonly identityService: IdentityService,
private readonly platformLocation: PlatformLocation) {

const base = this.platformLocation.getBaseHrefFromDOM();
if (base.length > 1) {
__webpack_public_path__ = base + "/dist/";
}

this.translate.addLangs(["en", "de", "fr","da","es","it","nl","sv","no"]);
// this language will be used as a fallback when a translation isn't found in the current language
this.translate.setDefaultLang("en");
Expand Down
8 changes: 4 additions & 4 deletions src/Ombi/ClientApp/app/issues/issuestable.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
<span [hidden]="reverse"><i class="fa fa-arrow-down" aria-hidden="true"></i></span><span [hidden]="!reverse"><i class="fa fa-arrow-up" aria-hidden="true"></i></span>
</span>
</th>
<th (click)="setOrder('issue.status')">
<th (click)="setOrder('status')">
<a [translate]="'Issues.Status'"></a>
<span *ngIf="order === 'issue.status'">
<span *ngIf="order === 'status'">
<span [hidden]="reverse"><i class="fa fa-arrow-down" aria-hidden="true"></i></span><span [hidden]="!reverse"><i class="fa fa-arrow-up" aria-hidden="true"></i></span>
</span>
</th>
<th (click)="setOrder('issue.reportedUser')">
<th (click)="setOrder('reportedUser')">
<a [translate]="'Issues.ReportedBy'"></a>
<span *ngIf="order === 'issue.reportedUser'">
<span *ngIf="order === 'reportedUser'">
<span [hidden]="reverse"><i class="fa fa-arrow-down" aria-hidden="true"></i></span><span [hidden]="!reverse"><i class="fa fa-arrow-up" aria-hidden="true"></i></span>
</span>
</th>
Expand Down
52 changes: 46 additions & 6 deletions src/Ombi/ClientApp/app/requests/movierequests.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,49 @@
<input type="text" id="search" class="form-control form-control-custom searchwidth" placeholder="Search" (keyup)="search($event)">
<span class="input-group-btn">
<button id="filterBtn" class="btn btn-sm btn-info-outline" (click)="filterDisplay = !filterDisplay" >
<i class="fa fa-filter"></i> {{ 'Requests.Filter' | translate }}</button>
<!-- <button id="filterBtn" class="btn btn-sm btn-warning-outline" (click)="sortDisplay = !sortDisplay" >
<i class="fa fa-sort"></i> {{ 'Requests.Sort' | translate }}</button> -->
<i class="fa fa-filter"></i> {{ 'Requests.Filter' | translate }}
</button>


<button class="btn btn-sm btn-primary-outline dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
<i class="fa fa-sort"></i> {{ 'Requests.Sort' | translate }}
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu2">
<li>
<a (click)="setOrder('requestedDate')">{{ 'Requests.SortRequestDate' | translate }}
<span *ngIf="order === 'requestedDate'">
<span [hidden]="reverse"><small><i class="fa fa-arrow-down" aria-hidden="true"></i></small></span>
<span [hidden]="!reverse"><small><i class="fa fa-arrow-up" aria-hidden="true"></i></small></span>
</span>
</a>
<a (click)="setOrder('title')">{{ 'Requests.SortTitle' | translate}}
<span *ngIf="order === 'title'">
<span [hidden]="reverse"><small><i class="fa fa-arrow-down" aria-hidden="true"></i></small></span>
<span [hidden]="!reverse"><small><i class="fa fa-arrow-up" aria-hidden="true"></i></small></span>
</span>
</a>
<a (click)="setOrder('releaseDate')">{{ 'Requests.TheatricalReleaseSort' | translate }}
<span *ngIf="order === 'releaseDate'">
<span [hidden]="reverse"><small><i class="fa fa-arrow-down" aria-hidden="true"></i></small></span>
<span [hidden]="!reverse"><small><i class="fa fa-arrow-up" aria-hidden="true"></i></small></span>
</span>
</a>
<a (click)="setOrder('requestedUser.userAlias')">{{ 'Requests.SortRequestedBy' | translate }}
<span *ngIf="order === 'requestedUser.userAlias'">
<span [hidden]="reverse"><small><i class="fa fa-arrow-down" aria-hidden="true"></i></small></span>
<span [hidden]="!reverse"><small><i class="fa fa-arrow-up" aria-hidden="true"></i></small></span>
</span>
</a>

<a (click)="setOrder('status')">{{ 'Requests.SortStatus' | translate }}
<span *ngIf="order === 'status'">
<span [hidden]="reverse"><small><i class="fa fa-arrow-down" aria-hidden="true"></i></small></span>
<span [hidden]="!reverse"><small><i class="fa fa-arrow-up" aria-hidden="true"></i></small></span>
</span>
</a>
</li>
</ul>
</span>

</div>
Expand All @@ -19,7 +59,7 @@
<div infinite-scroll [infiniteScrollDistance]="1" [infiniteScrollThrottle]="100" (scrolled)="loadMore()">


<div *ngFor="let request of movieRequests">
<div *ngFor="let request of movieRequests | orderBy: order : reverse : 'case-insensitive'">


<div class="row">
Expand Down Expand Up @@ -203,8 +243,8 @@ <h4>{{ 'Filter.FilterHeaderRequestStatus' | translate }}</h4>
</div>
<div class="form-group">
<div class="radio">
<input type="radio" id="approved" name="Status" (click)="filterStatus(filterType.PendingApproval)">
<label for="approved">{{ 'Filter.PendingApproval' | translate }}</label>
<input type="radio" id="pendingApproval" name="Status" (click)="filterStatus(filterType.PendingApproval, $event)">
<label for="pendingApproval">{{ 'Filter.PendingApproval' | translate }}</label>
</div>
</div>

Expand Down
11 changes: 10 additions & 1 deletion src/Ombi/ClientApp/app/requests/movierequests.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export class MovieRequestsComponent implements OnInit {
public filter: IFilter;
public filterType = FilterType;

public sortDisplay: boolean;
public order: string = "requestedDate";
public reverse = false;

private currentlyLoaded: number;
private amountToLoad: number;
Expand Down Expand Up @@ -174,6 +175,14 @@ export class MovieRequestsComponent implements OnInit {
});
}

public setOrder(value: string) {
if (this.order === value) {
this.reverse = !this.reverse;
}

this.order = value;
}

private loadRequests(amountToLoad: number, currentlyLoaded: number) {
this.requestService.getMovieRequests(amountToLoad, currentlyLoaded + 1)
.subscribe(x => {
Expand Down
2 changes: 2 additions & 0 deletions src/Ombi/ClientApp/app/requests/requests.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { RouterModule, Routes } from "@angular/router";

import { NgbModule } from "@ng-bootstrap/ng-bootstrap";
import { OrderModule } from "ngx-order-pipe";

import { InfiniteScrollModule } from "ngx-infinite-scroll";

Expand Down Expand Up @@ -34,6 +35,7 @@ const routes: Routes = [
TreeTableModule,
SharedModule,
SidebarModule,
OrderModule,
],
declarations: [
RequestComponent,
Expand Down
2 changes: 1 addition & 1 deletion src/Ombi/ClientApp/app/search/tvsearch.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<div class="col-sm-8 small-padding">
<div>

<a href="http://www.imdb.com/title/{{node.data.imdbId}}/" target="_blank">
<a *ngIf="node.data.imdbId" href="http://www.imdb.com/title/{{node.data.imdbId}}/" target="_blank">
<h4>{{node.data.title}} ({{node.data.firstAired | date: 'yyyy'}})</h4>

</a>
Expand Down
Loading

0 comments on commit 7e6824c

Please sign in to comment.