Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed a few different things #4855

Merged
merged 3 commits into from
Jan 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/Ombi.Core.Tests/Services/RecentlyRequestedServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,20 +182,25 @@ public async Task GetRecentlyRequested_HideUsernames()
var releaseDate = new DateTime(2019, 01, 01);
var requestDate = DateTime.Now;

var movies = _fixture.CreateMany<MovieRequests>(10);
var movies = _fixture.CreateMany<MovieRequests>(10).ToList();
var albums = _fixture.CreateMany<AlbumRequest>(10);
var chilRequests = _fixture.CreateMany<ChildRequests>(10);
movies.Add(_fixture.Build<MovieRequests>().With(x => x.RequestedUserId, "a").With(x => x.Title, "unit").Create());

_mocker.Setup<IMovieRequestRepository, IQueryable<MovieRequests>>(x => x.GetAll()).Returns(movies.AsQueryable().BuildMock());
_mocker.Setup<IMusicRequestRepository, IQueryable<AlbumRequest>>(x => x.GetAll()).Returns(albums.AsQueryable().BuildMock());
_mocker.Setup<ITvRequestRepository, IQueryable<ChildRequests>>(x => x.GetChild()).Returns(chilRequests.AsQueryable().BuildMock());
_mocker.Setup<ICurrentUser, Task<OmbiUser>>(x => x.GetUser()).ReturnsAsync(new OmbiUser { UserName = "test", Alias = "alias", UserType = UserType.LocalUser });
_mocker.Setup<ICurrentUser, Task<OmbiUser>>(x => x.GetUser()).ReturnsAsync(new OmbiUser { UserName = "test", Id = "a", Alias = "alias", UserType = UserType.LocalUser });
_mocker.Setup<ICurrentUser, string>(x => x.Username).Returns("test");
_mocker.Setup<OmbiUserManager, Task<bool>>(x => x.IsInRoleAsync(It.IsAny<OmbiUser>(), It.IsAny<string>())).ReturnsAsync(false);

var result = await _subject.GetRecentlyRequested(CancellationToken.None);

CollectionAssert.IsEmpty(result.Where(x => !string.IsNullOrEmpty(x.Username) && !string.IsNullOrEmpty(x.UserId)));
Assert.Multiple(() =>
{
Assert.That(result.Count, Is.EqualTo(1));
Assert.That(result.First().Title, Is.EqualTo("unit"));
});
}
}
}
24 changes: 18 additions & 6 deletions src/Ombi.Core/Services/RecentlyRequestedService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ public async Task<IEnumerable<RecentlyRequestedModel>> GetRecentlyRequested(Canc
var lang = await DefaultLanguageCode();
foreach (var item in await recentMovieRequests.ToListAsync(cancellationToken))
{
if (hideUsers.Hide && item.RequestedUserId != hideUsers.UserId)
{
continue;
}
var images = await _cache.GetOrAddAsync($"{CacheKeys.TmdbImages}movie{item.TheMovieDbId}", () => _movieDbApi.GetMovieImages(item.TheMovieDbId.ToString(), cancellationToken), DateTimeOffset.Now.AddDays(1));
model.Add(new RecentlyRequestedModel
{
Expand All @@ -84,8 +88,8 @@ public async Task<IEnumerable<RecentlyRequestedModel>> GetRecentlyRequested(Canc
Title = item.Title,
Type = RequestType.Movie,
Approved = item.Approved,
UserId = hideUsers.Hide ? string.Empty : item.RequestedUserId,
Username = hideUsers.Hide ? string.Empty : item.RequestedUser.UserAlias,
UserId = item.RequestedUserId,
Username = item.RequestedUser.UserAlias,
MediaId = item.TheMovieDbId.ToString(),
PosterPath = images?.posters?.Where(x => lang.Equals(x?.iso_639_1, StringComparison.InvariantCultureIgnoreCase))?.OrderByDescending(x => x.vote_count)?.Select(x => x.file_path)?.FirstOrDefault(),
Background = images?.backdrops?.Where(x => lang.Equals(x?.iso_639_1, StringComparison.InvariantCultureIgnoreCase))?.OrderByDescending(x => x.vote_count)?.Select(x => x.file_path)?.FirstOrDefault(),
Expand All @@ -94,6 +98,10 @@ public async Task<IEnumerable<RecentlyRequestedModel>> GetRecentlyRequested(Canc

foreach (var item in await recentMusicRequests.ToListAsync(cancellationToken))
{
if (hideUsers.Hide && item.RequestedUserId != hideUsers.UserId)
{
continue;
}
model.Add(new RecentlyRequestedModel
{
RequestId = item.Id,
Expand All @@ -104,14 +112,18 @@ public async Task<IEnumerable<RecentlyRequestedModel>> GetRecentlyRequested(Canc
RequestDate = item.RequestedDate,
Title = item.Title,
Type = RequestType.Album,
UserId = hideUsers.Hide ? string.Empty : item.RequestedUserId,
Username = hideUsers.Hide ? string.Empty : item.RequestedUser.UserAlias,
UserId = item.RequestedUserId,
Username = item.RequestedUser.UserAlias,
MediaId = item.ForeignAlbumId,
});
}

foreach (var item in await recentTvRequests.ToListAsync(cancellationToken))
{
if (hideUsers.Hide && item.RequestedUserId != hideUsers.UserId)
{
continue;
}
var providerId = item.ParentRequest.ExternalProviderId.ToString();
var images = await _cache.GetOrAddAsync($"{CacheKeys.TmdbImages}tv{providerId}", () => _movieDbApi.GetTvImages(providerId.ToString(), cancellationToken), DateTimeOffset.Now.AddDays(1));

Expand All @@ -127,8 +139,8 @@ public async Task<IEnumerable<RecentlyRequestedModel>> GetRecentlyRequested(Canc
TvPartiallyAvailable = partialAvailability,
Title = item.ParentRequest.Title,
Type = RequestType.TvShow,
UserId = hideUsers.Hide ? string.Empty : item.RequestedUserId,
Username = hideUsers.Hide ? string.Empty : item.RequestedUser.UserAlias,
UserId = item.RequestedUserId,
Username = item.RequestedUser.UserAlias,
MediaId = providerId.ToString(),
PosterPath = images?.posters?.Where(x => lang.Equals(x?.iso_639_1, StringComparison.InvariantCultureIgnoreCase))?.OrderByDescending(x => x.vote_count)?.Select(x => x.file_path)?.FirstOrDefault(),
Background = images?.backdrops?.Where(x => lang.Equals(x?.iso_639_1, StringComparison.InvariantCultureIgnoreCase))?.OrderByDescending(x => x.vote_count)?.Select(x => x.file_path)?.FirstOrDefault(),
Expand Down
3 changes: 2 additions & 1 deletion src/Ombi/ClientApp/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { APP_BASE_HREF, CommonModule, PlatformLocation } from "@angular/common";
import { CustomPageService, ImageService, RequestService, SettingsService, SonarrService } from "./services";
import { CustomPageService, ImageService, LidarrService, RequestService, SettingsService, SonarrService } from "./services";
import { FormsModule, ReactiveFormsModule } from "@angular/forms";
import { HTTP_INTERCEPTORS, HttpClient, HttpClientModule } from "@angular/common/http";
import { IdentityService, IssuesService, JobService, MessageService, PlexTvService, SearchService, StatusService } from "./services";
Expand Down Expand Up @@ -209,6 +209,7 @@ export function JwtTokenGetter() {
StorageService,
RequestService,
SonarrService,
LidarrService,
SignalRNotificationService,
FEATURES_INITIALIZER,
SONARR_INITIALIZER,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Component, OnInit, Input, ViewChild, Output, EventEmitter } from "@angular/core";
import { Component, OnInit, Input, ViewChild, Output, EventEmitter, Inject } from "@angular/core";
import { DiscoverOption, IDiscoverCardResult } from "../../interfaces";
import { ISearchMovieResult, ISearchTvResult, RequestType } from "../../../interfaces";
import { SearchV2Service } from "../../../services";
import { StorageService } from "../../../shared/storage/storage-service";
import { MatButtonToggleChange } from '@angular/material/button-toggle';
import { Carousel } from 'primeng/carousel';
import { FeaturesFacade } from "../../../state/features/features.facade";
import { APP_BASE_HREF } from "@angular/common";

export enum DiscoverType {
Upcoming,
Expand Down Expand Up @@ -44,10 +45,18 @@ export class CarouselListComponent implements OnInit {
};
private amountToLoad = 17;
private currentlyLoaded = 0;
private baseUrl: string = "";


constructor(private searchService: SearchV2Service,
private storageService: StorageService,
private featureFacade: FeaturesFacade) {
private featureFacade: FeaturesFacade,
@Inject(APP_BASE_HREF) private href: string) {

if (this.href.length > 1) {
this.baseUrl = this.href;
}

Carousel.prototype.onTouchMove = () => { },
this.responsiveOptions = [
{
Expand Down Expand Up @@ -294,7 +303,7 @@ export class CarouselListComponent implements OnInit {
this.movies.forEach(m => {
tempResults.push({
available: m.available,
posterPath: m.posterPath ? `https://image.tmdb.org/t/p/w500/${m.posterPath}` : "../../../images/default_movie_poster.png",
posterPath: m.posterPath ? `https://image.tmdb.org/t/p/w500/${m.posterPath}` : this.baseUrl + "/images/default_movie_poster.png",
requested: m.requested,
title: m.title,
type: RequestType.movie,
Expand All @@ -316,7 +325,7 @@ export class CarouselListComponent implements OnInit {
this.tvShows.forEach(m => {
tempResults.push({
available: m.fullyAvailable,
posterPath: m.backdropPath ? `https://image.tmdb.org/t/p/w500/${m.backdropPath}` : "../../../images/default_tv_poster.png",
posterPath: m.backdropPath ? `https://image.tmdb.org/t/p/w500/${m.backdropPath}` : this.baseUrl + "/images/default_tv_poster.png",
requested: m.requested,
title: m.title,
type: RequestType.tvShow,
Expand Down
2 changes: 1 addition & 1 deletion src/Ombi/ClientApp/src/app/my-nav/my-nav.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<mat-slide-toggle id="filterTv" class="mat-menu-item slide-menu" [checked]="searchFilter.tvShows"
(click)="$event.stopPropagation()" (change)="changeFilter($event,SearchFilterType.TvShow)">
{{ 'NavigationBar.Filter.TvShows' | translate}}</mat-slide-toggle>
<mat-slide-toggle id="filterMusic" class="mat-menu-item slide-menu" [checked]="searchFilter.music"
<mat-slide-toggle *ngIf="musicEnabled$ | async" id="filterMusic" class="mat-menu-item slide-menu" [checked]="searchFilter.music"
(click)="$event.stopPropagation()" (change)="changeFilter($event,SearchFilterType.Music)">
{{ 'NavigationBar.Filter.Music' | translate}}</mat-slide-toggle>
<!-- <mat-slide-toggle class="mat-menu-item slide-menu" [checked]="searchFilter.people"
Expand Down
7 changes: 5 additions & 2 deletions src/Ombi/ClientApp/src/app/my-nav/my-nav.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout';
import { Component, EventEmitter, Input, OnInit, Output, SimpleChanges } from '@angular/core';
import { ICustomizationSettings, IUser, RequestType, UserType } from '../interfaces';
import { SettingsService, SettingsStateService } from '../services';
import { LidarrService, SettingsService, SettingsStateService } from '../services';

import { AdvancedSearchDialogComponent } from '../shared/advanced-search-dialog/advanced-search-dialog.component';
import { CustomizationFacade } from '../state/customization';
Expand All @@ -15,7 +15,7 @@ import { Observable } from 'rxjs';
import { Router } from '@angular/router';
import { SearchFilter } from './SearchFilter';
import { StorageService } from '../shared/storage/storage-service';
import { map } from 'rxjs/operators';
import { map, take } from 'rxjs/operators';

export enum SearchFilterType {
Movie = 1,
Expand Down Expand Up @@ -56,9 +56,12 @@ export class MyNavComponent implements OnInit {

private customizationSettings: ICustomizationSettings;

public readonly musicEnabled$ = this.lidarrService.enabled().pipe(take(1));

constructor(private breakpointObserver: BreakpointObserver,
private settingsService: SettingsService,
private customizationFacade: CustomizationFacade,
private lidarrService: LidarrService,
private store: StorageService,
private filterService: FilterService,
private dialogService: MatDialog,
Expand Down
3 changes: 2 additions & 1 deletion src/Ombi/ClientApp/src/app/requests-list/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { MoviesGridComponent } from "./movies-grid/movies-grid.component";

import { RequestServiceV2 } from "../../services/requestV2.service";
import { RequestService } from "../../services";
import { LidarrService, RequestService } from "../../services";
import { TvGridComponent } from "./tv-grid/tv-grid.component";
import { GridSpinnerComponent } from "./grid-spinner/grid-spinner.component";
import { RequestOptionsComponent } from "./options/request-options.component";
Expand All @@ -20,4 +20,5 @@ export const components: any[] = [
export const providers: any[] = [
RequestService,
RequestServiceV2,
LidarrService,
];
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<tv-grid (onOpenOptions)="onOpenOptions($event)"></tv-grid>
</ng-template>
</mat-tab>
<mat-tab label="{{ 'NavigationBar.Filter.Music' | translate }}">
<mat-tab *ngIf="musicEnabled$ | async" label="{{ 'NavigationBar.Filter.Music' | translate }}">
<ng-template matTabContent>
<albums-grid (onOpenOptions)="onOpenOptions($event)"></albums-grid>
</ng-template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ import { Component, ViewChild } from "@angular/core";
import { MatBottomSheet } from "@angular/material/bottom-sheet";
import { RequestOptionsComponent } from "./options/request-options.component";
import { UpdateType } from "../models/UpdateType";
import { LidarrService } from "app/services";
import { take } from "rxjs";

@Component({
templateUrl: "./requests-list.component.html",
styleUrls: ["./requests-list.component.scss"]
})
export class RequestsListComponent {

constructor(private bottomSheet: MatBottomSheet) { }
constructor(private bottomSheet: MatBottomSheet, private lidarrService: LidarrService) { }

public readonly musicEnabled$ = this.lidarrService.enabled().pipe(take(1));

public onOpenOptions(event: { request: any, filter: any, onChange: any, manageOwnRequests: boolean, isAdmin: boolean, has4kRequest: boolean, hasRegularRequest: boolean }) {
const ref = this.bottomSheet.open(RequestOptionsComponent, { data: { id: event.request.id, type: event.request.requestType, canApprove: event.request.canApprove, manageOwnRequests: event.manageOwnRequests, isAdmin: event.isAdmin, has4kRequest: event.has4kRequest, hasRegularRequest: event.hasRegularRequest } });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ export class LidarrService extends ServiceHelpers {
super(http, "/api/v1/Lidarr", href);
}

public enabled(): Observable<boolean> {
return this.http.get<boolean>(`${this.url}/enabled/`, {headers: this.headers});
}

public getRootFolders(settings: ILidarrSettings): Observable<ILidarrRootFolder[]> {
return this.http.post<ILidarrRootFolder[]>(`${this.url}/RootFolders/`, JSON.stringify(settings), {headers: this.headers});
}

public getQualityProfiles(settings: ILidarrSettings): Observable<ILidarrProfile[]> {
return this.http.post<ILidarrProfile[]>(`${this.url}/Profiles/`, JSON.stringify(settings), {headers: this.headers});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class AdvancedSearchDialogDataService {
getOptions(): any {
return this._options;
}

getLoaded(): number {
return this._options.loaded;
}
Expand Down
13 changes: 12 additions & 1 deletion src/Ombi/Controllers/V1/External/LidarrController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Ombi.Controllers.V1.External
{
[PowerUser]
[ApiV1]
[Produces("application/json")]
public class LidarrController : Controller
Expand All @@ -28,11 +27,19 @@ public LidarrController(ILidarrApi lidarr, ISettingsService<LidarrSettings> sett
private readonly ISettingsService<LidarrSettings> _lidarrSettings;
private ICacheService Cache { get; }

[HttpGet("enabled")]
public async Task<bool> Enabled()
{
var settings = await _lidarrSettings.GetSettingsAsync();
return settings.Enabled;
}

/// <summary>
/// Gets the Lidarr profiles.
/// </summary>
/// <param name="settings">The settings.</param>
/// <returns></returns>
[PowerUser]
[HttpPost("Profiles")]
public async Task<IEnumerable<LidarrProfile>> GetProfiles([FromBody] LidarrSettings settings)
{
Expand All @@ -44,6 +51,7 @@ public async Task<IEnumerable<LidarrProfile>> GetProfiles([FromBody] LidarrSetti
/// </summary>
/// <param name="settings">The settings.</param>
/// <returns></returns>
[PowerUser]
[HttpPost("RootFolders")]
public async Task<IEnumerable<LidarrRootFolder>> GetRootFolders([FromBody] LidarrSettings settings)
{
Expand All @@ -55,6 +63,7 @@ public async Task<IEnumerable<LidarrRootFolder>> GetRootFolders([FromBody] Lidar
/// </summary>
/// <param name="settings">The settings.</param>
/// <returns></returns>
[PowerUser]
[HttpPost("Metadata")]
public async Task<IEnumerable<MetadataProfile>> GetMetadataProfiles([FromBody] LidarrSettings settings)
{
Expand All @@ -66,6 +75,7 @@ public async Task<IEnumerable<MetadataProfile>> GetMetadataProfiles([FromBody] L
/// <remarks>The data is cached for an hour</remarks>
/// </summary>
/// <returns></returns>
[PowerUser]
[HttpGet("Profiles")]
public async Task<IEnumerable<LidarrProfile>> GetProfiles()
{
Expand All @@ -85,6 +95,7 @@ public async Task<IEnumerable<LidarrProfile>> GetProfiles()
/// <remarks>The data is cached for an hour</remarks>
/// </summary>
/// <returns></returns>
[PowerUser]
[HttpGet("RootFolders")]
public async Task<IEnumerable<LidarrRootFolder>> GetRootFolders()
{
Expand Down