Skip to content

Commit

Permalink
bug(#4854): šŸ› Fixed the Recently Requested showing requests when it sā€¦
Browse files Browse the repository at this point in the history
ā€¦hould be hidden
  • Loading branch information
tidusjar committed Jan 22, 2023
1 parent 46ce254 commit 854d1c0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
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

0 comments on commit 854d1c0

Please sign in to comment.