Skip to content

Commit

Permalink
Merge pull request #8 from tidusjar/develop
Browse files Browse the repository at this point in the history
Bring develop branch up to date with source
  • Loading branch information
anojht authored Apr 26, 2018
2 parents ccb496f + ac597af commit e8acf79
Show file tree
Hide file tree
Showing 30 changed files with 206 additions and 3,674 deletions.
3,659 changes: 49 additions & 3,610 deletions CHANGELOG.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build.cake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

#tool "nuget:?package=GitVersion.CommandLine"
#addin "Cake.Gulp"
#addin "Cake.Npm"
#addin "nuget:?package=Cake.Npm&version=0.13.0"
#addin "SharpZipLib"
#addin nuget:?package=Cake.Compression&version=0.1.4
#addin "Cake.Incubator"
Expand Down
19 changes: 14 additions & 5 deletions src/Ombi.Core/Authentication/PlexOAuthManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,24 @@ public async Task<PlexAccount> GetAccount(string accessToken)
return await _api.GetAccount(accessToken);
}

public async Task<Uri> GetOAuthUrl(int pinId, string code)
public async Task<Uri> GetOAuthUrl(int pinId, string code, string websiteAddress = null)
{
var settings = await _customizationSettingsService.GetSettingsAsync();
if (settings.ApplicationUrl.IsNullOrEmpty())
Uri url;
if (websiteAddress.IsNullOrEmpty())
{
return null;
var settings = await _customizationSettingsService.GetSettingsAsync();
if (settings.ApplicationUrl.IsNullOrEmpty())
{
return null;
}

url = _api.GetOAuthUrl(pinId, code, settings.ApplicationUrl, false);
}
else
{
url = _api.GetOAuthUrl(pinId, code, websiteAddress, false);
}

var url = _api.GetOAuthUrl(pinId, code, settings.ApplicationUrl, false);
return url;
}

Expand Down
1 change: 1 addition & 0 deletions src/Ombi.Core/Engine/Interfaces/IMovieRequestEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ public interface IMovieRequestEngine : IRequestEngine<MovieRequests>
Task<RequestEngineResult> ApproveMovieById(int requestId);
Task<RequestEngineResult> DenyMovieById(int modelId);
Task<IEnumerable<MovieRequests>> Filter(FilterViewModel vm);

}
}
1 change: 1 addition & 0 deletions src/Ombi.Core/Engine/Interfaces/IRequestEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ public interface IRequestEngine<T>

Task<RequestEngineResult> MarkUnavailable(int modelId);
Task<RequestEngineResult> MarkAvailable(int modelId);
Task<int> GetTotal();
}
}
13 changes: 13 additions & 0 deletions src/Ombi.Core/Engine/MovieRequestEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,19 @@ public async Task<IEnumerable<MovieRequests>> GetRequests(int count, int positio
return allRequests;
}

public async Task<int> GetTotal()
{
var shouldHide = await HideFromOtherUsers();
if (shouldHide.Hide)
{
return await MovieRepository.GetWithUser(shouldHide.UserId).CountAsync();
}
else
{
return await MovieRepository.GetWithUser().CountAsync();
}
}

/// <summary>
/// Gets the requests.
/// </summary>
Expand Down
17 changes: 15 additions & 2 deletions src/Ombi.Core/Engine/TvRequestEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public async Task<RequestEngineResult> RequestTvShow(TvRequestViewModel tv)
var newRequest = tvBuilder.CreateNewRequest(tv);
return await AddRequest(newRequest.NewRequest);
}

public async Task<IEnumerable<TvRequests>> GetRequests(int count, int position)
{
var shouldHide = await HideFromOtherUsers();
Expand Down Expand Up @@ -280,7 +280,7 @@ public async Task<TvRequests> UpdateTvRequest(TvRequests request)
results.Background = PosterPathHelper.FixBackgroundPath(request.Background);
results.QualityOverride = request.QualityOverride;
results.RootFolder = request.RootFolder;

await TvRepository.Update(results);
return results;
}
Expand Down Expand Up @@ -432,6 +432,19 @@ public async Task<RequestEngineResult> MarkAvailable(int modelId)
};
}

public async Task<int> GetTotal()
{
var shouldHide = await HideFromOtherUsers();
if (shouldHide.Hide)
{
return await TvRepository.Get(shouldHide.UserId).CountAsync();
}
else
{
return await TvRepository.Get().CountAsync();
}
}

private async Task<RequestEngineResult> AddExistingRequest(ChildRequests newRequest, TvRequests existingRequest)
{
// Add the child
Expand Down
2 changes: 1 addition & 1 deletion src/Ombi.Core/IPlexOAuthManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public interface IPlexOAuthManager
{
Task<string> GetAccessTokenFromPin(int pinId);
Task<OAuthPin> RequestPin();
Task<Uri> GetOAuthUrl(int pinId, string code);
Task<Uri> GetOAuthUrl(int pinId, string code, string websiteAddress = null);
Uri GetWizardOAuthUrl(int pinId, string code, string websiteAddress);
Task<PlexAccount> GetAccount(string accessToken);
}
Expand Down
10 changes: 10 additions & 0 deletions src/Ombi.Helpers/StringHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,15 @@ public static SecureString ToSecureString(this string password)
securePassword.MakeReadOnly();
return securePassword;
}

public static int IntParseLinq(string stringIn)
{
if (int.TryParse(stringIn, out var result))
{
return result;
}

return -1;
}
}
}
1 change: 1 addition & 0 deletions src/Ombi.Helpers/UriHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public static Uri ReturnUriWithSubDir(this string val, int port, bool ssl, strin

return uriBuilder.Uri;
}

}

public class ApplicationSettingsException : Exception
Expand Down
18 changes: 9 additions & 9 deletions src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public async Task Start(NewsletterSettings settings, bool test)
addedLog.Where(x => x.Type == RecentlyAddedType.Emby && x.ContentType == ContentType.Episode);

// Filter out the ones that we haven't sent yet
var plexContentMoviesToSend = plexContent.Where(x => x.Type == PlexMediaTypeEntity.Movie && !addedPlexMovieLogIds.Contains(int.Parse(x.TheMovieDbId)));
var embyContentMoviesToSend = embyContent.Where(x => x.Type == EmbyMediaType.Movie && !addedEmbyMoviesLogIds.Contains(int.Parse(x.TheMovieDbId)));
var plexContentMoviesToSend = plexContent.Where(x => x.Type == PlexMediaTypeEntity.Movie && !addedPlexMovieLogIds.Contains(StringHelper.IntParseLinq(x.TheMovieDbId)));
var embyContentMoviesToSend = embyContent.Where(x => x.Type == EmbyMediaType.Movie && !addedEmbyMoviesLogIds.Contains(StringHelper.IntParseLinq(x.TheMovieDbId)));
_log.LogInformation("Plex Movies to send: {0}", plexContentMoviesToSend.Count());
_log.LogInformation("Emby Movies to send: {0}", embyContentMoviesToSend.Count());

Expand Down Expand Up @@ -173,7 +173,7 @@ public async Task Start(NewsletterSettings settings, bool test)
AddedAt = DateTime.Now,
Type = RecentlyAddedType.Plex,
ContentType = ContentType.Parent,
ContentId = int.Parse(p.TheMovieDbId),
ContentId = StringHelper.IntParseLinq(p.TheMovieDbId),
});

}
Expand All @@ -185,7 +185,7 @@ public async Task Start(NewsletterSettings settings, bool test)
AddedAt = DateTime.Now,
Type = RecentlyAddedType.Plex,
ContentType = ContentType.Episode,
ContentId = int.Parse(p.Series.TvDbId),
ContentId = StringHelper.IntParseLinq(p.Series.TvDbId),
EpisodeNumber = p.EpisodeNumber,
SeasonNumber = p.SeasonNumber
});
Expand All @@ -199,7 +199,7 @@ public async Task Start(NewsletterSettings settings, bool test)
AddedAt = DateTime.Now,
Type = RecentlyAddedType.Emby,
ContentType = ContentType.Parent,
ContentId = int.Parse(e.TheMovieDbId),
ContentId = StringHelper.IntParseLinq(e.TheMovieDbId),
});
}
}
Expand All @@ -211,7 +211,7 @@ public async Task Start(NewsletterSettings settings, bool test)
AddedAt = DateTime.Now,
Type = RecentlyAddedType.Emby,
ContentType = ContentType.Episode,
ContentId = int.Parse(p.Series.TvDbId),
ContentId = StringHelper.IntParseLinq(p.Series.TvDbId),
EpisodeNumber = p.EpisodeNumber,
SeasonNumber = p.SeasonNumber
});
Expand Down Expand Up @@ -259,7 +259,7 @@ private HashSet<PlexEpisode> FilterPlexEpisodes(IEnumerable<PlexEpisode> source,
var itemsToReturn = new HashSet<PlexEpisode>();
foreach (var ep in source)
{
var tvDbId = int.Parse(ep.Series.TvDbId);
var tvDbId = StringHelper.IntParseLinq(ep.Series.TvDbId);
if (recentlyAdded.Any(x => x.ContentId == tvDbId && x.EpisodeNumber == ep.EpisodeNumber && x.SeasonNumber == ep.SeasonNumber))
{
continue;
Expand All @@ -276,7 +276,7 @@ private HashSet<EmbyEpisode> FilterEmbyEpisodes(IEnumerable<EmbyEpisode> source,
var itemsToReturn = new HashSet<EmbyEpisode>();
foreach (var ep in source)
{
var tvDbId = int.Parse(ep.Series.TvDbId);
var tvDbId = StringHelper.IntParseLinq(ep.Series.TvDbId);
if (recentlyAdded.Any(x => x.ContentId == tvDbId && x.EpisodeNumber == ep.EpisodeNumber && x.SeasonNumber == ep.SeasonNumber))
{
continue;
Expand Down Expand Up @@ -374,7 +374,7 @@ private async Task ProcessEmbyMovies(IQueryable<EmbyContent> embyContent, String
theMovieDbId = result.id.ToString();
}

var info = await _movieApi.GetMovieInformationWithExtraInfo(int.Parse(theMovieDbId));
var info = await _movieApi.GetMovieInformationWithExtraInfo(StringHelper.IntParseLinq(theMovieDbId));
if (info == null)
{
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ public class AuthenticationSettings : Settings
public bool RequireLowercase { get; set; }
public bool RequireNonAlphanumeric { get; set; }
public bool RequireUppercase { get; set; }
public bool EnableOAuth { get; set; } // Plex OAuth
}
}
1 change: 1 addition & 0 deletions src/Ombi/ClientApp/app/interfaces/ISettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export interface IAuthenticationSettings extends ISettings {
requiredLowercase: boolean;
requireNonAlphanumeric: boolean;
requireUppercase: boolean;
enableOAuth: boolean;
}

export interface IUserManagementSettings extends ISettings {
Expand Down
9 changes: 5 additions & 4 deletions src/Ombi/ClientApp/app/login/login.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</div>
<p id="profile-name" class="profile-name-card"></p>

<div *ngIf="!plexEnabled || !customizationSettings.applicationUrl || loginWithOmbi">
<div *ngIf="!authenticationSettings.enableOAuth || loginWithOmbi">
<form *ngIf="authenticationSettings" class="form-signin" novalidate [formGroup]="form" (ngSubmit)="onSubmit(form)">


Expand All @@ -41,15 +41,16 @@
<!-- /form -->
</div>
<!-- Main OAuth Flow -->
<div class="form-signin" *ngIf="plexEnabled && customizationSettings.applicationUrl && !loginWithOmbi">
<div *ngIf="authenticationSettings.enableOAuth && !loginWithOmbi">
<div class="form-signin">
<button class="btn btn-success" type="button" (click)="loginWithOmbi = true">
Sign In With {{appName}}</button>
</div>
<div class="form-signin" *ngIf="plexEnabled && customizationSettings.applicationUrl && !loginWithOmbi">
<div class="form-signin">
<button class="btn btn-primary" type="button" (click)="oauth()">
Sign In With Plex</button>
</div>

</div>

</div>
<!-- /card-container -->
Expand Down
9 changes: 7 additions & 2 deletions src/Ombi/ClientApp/app/login/login.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ export class LoginComponent implements OnDestroy, OnInit {
public ngOnInit() {
this.settingsService.getAuthentication().subscribe(x => this.authenticationSettings = x);
this.settingsService.getCustomization().subscribe(x => this.customizationSettings = x);
this.settingsService.getStatusPlex().subscribe(x => this.plexEnabled = x);
this.images.getRandomBackground().subscribe(x => {
this.background = this.sanitizer.bypassSecurityTrustStyle("linear-gradient(-10deg, transparent 20%, rgba(0,0,0,0.7) 20.0%, rgba(0,0,0,0.7) 80.0%, transparent 80%),url(" + x.url + ")");
});
Expand Down Expand Up @@ -125,7 +124,13 @@ export class LoginComponent implements OnDestroy, OnInit {

public oauth() {
this.authService.login({usePlexOAuth: true, password:"",rememberMe:true,username:""}).subscribe(x => {
window.location.href = x.url;
if (window.frameElement) {
// in frame
window.open(x.url, "_blank");
} else {
// not in frame
window.location.href = x.url;
}
});
}

Expand Down
7 changes: 6 additions & 1 deletion src/Ombi/ClientApp/app/login/loginoauth.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { ActivatedRoute, Router } from "@angular/router";

import { AuthService } from "../auth/auth.service";
import { NotificationService } from "../services";

@Component({
templateUrl: "./loginoauth.component.html",
Expand All @@ -11,7 +12,7 @@ export class LoginOAuthComponent implements OnInit {
public error: string;

constructor(private authService: AuthService, private router: Router,
private route: ActivatedRoute) {
private route: ActivatedRoute, private notify: NotificationService) {
this.route.params
.subscribe((params: any) => {
this.pin = params.pin;
Expand All @@ -37,6 +38,10 @@ export class LoginOAuthComponent implements OnInit {
this.error = x.errorMessage;
}

}, err => {
this.notify.error(err.statusText);

this.router.navigate(["login"]);
});
}
}
4 changes: 3 additions & 1 deletion src/Ombi/ClientApp/app/requests/movierequests.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<br />


<div infinite-scroll [infiniteScrollDistance]="1" [infiniteScrollThrottle]="100" (scrolled)="loadMore()">
<div>


<div *ngFor="let request of movieRequests | orderBy: order : reverse : 'case-insensitive'">
Expand Down Expand Up @@ -212,6 +212,8 @@ <h4 class="request-title">{{request.title}} ({{request.releaseDate | date: 'yyyy


</div>

<p-paginator [rows]="10" [totalRecords]="totalMovies" (onPageChange)="paginate($event)"></p-paginator>
</div>


Expand Down
16 changes: 10 additions & 6 deletions src/Ombi/ClientApp/app/requests/movierequests.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Subject } from "rxjs/Subject";
import { AuthService } from "../auth/auth.service";
import { NotificationService, RadarrService, RequestService } from "../services";

import { FilterType, IFilter, IIssueCategory, IMovieRequests, IRadarrProfile, IRadarrRootFolder } from "../interfaces";
import { FilterType, IFilter, IIssueCategory, IMovieRequests, IPagenator, IRadarrProfile, IRadarrRootFolder } from "../interfaces";

@Component({
selector: "movie-requests",
Expand Down Expand Up @@ -39,6 +39,7 @@ export class MovieRequestsComponent implements OnInit {
public order: string = "requestedDate";
public reverse = false;

public totalMovies: number = 100;
private currentlyLoaded: number;
private amountToLoad: number;

Expand All @@ -65,17 +66,19 @@ export class MovieRequestsComponent implements OnInit {
}

public ngOnInit() {
this.amountToLoad = 100;
this.currentlyLoaded = 100;
this.amountToLoad = 10;
this.currentlyLoaded = 10;
this.loadInit();
this.isAdmin = this.auth.hasRole("admin") || this.auth.hasRole("poweruser");
this.filter = {
availabilityFilter: FilterType.None,
statusFilter: FilterType.None};
}

public loadMore() {
this.loadRequests(this.amountToLoad, this.currentlyLoaded);
public paginate(event: IPagenator) {
const skipAmount = event.first;

this.loadRequests(this.amountToLoad, skipAmount);
}

public search(text: any) {
Expand Down Expand Up @@ -226,7 +229,7 @@ export class MovieRequestsComponent implements OnInit {
if(!this.movieRequests) {
this.movieRequests = [];
}
this.movieRequests.push.apply(this.movieRequests, x);
this.movieRequests = x;
this.currentlyLoaded = currentlyLoaded + amountToLoad;
});
}
Expand Down Expand Up @@ -267,6 +270,7 @@ export class MovieRequestsComponent implements OnInit {
}

private loadInit() {
this.requestService.getTotalMovies().subscribe(x => this.totalMovies = x);
this.requestService.getMovieRequests(this.amountToLoad, 0)
.subscribe(x => {
this.movieRequests = x;
Expand Down
Loading

0 comments on commit e8acf79

Please sign in to comment.