From 854d1c06607ce6ec3fd81dd24b18c9b6eb9842c8 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Sun, 22 Jan 2023 20:25:15 +0000 Subject: [PATCH] =?UTF-8?q?bug(#4854):=20=F0=9F=90=9B=20Fixed=20the=20Rece?= =?UTF-8?q?ntly=20Requested=20showing=20requests=20when=20it=20should=20be?= =?UTF-8?q?=20hidden?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/RecentlyRequestedServiceTests.cs | 11 ++++++--- .../Services/RecentlyRequestedService.cs | 24 ++++++++++++++----- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/Ombi.Core.Tests/Services/RecentlyRequestedServiceTests.cs b/src/Ombi.Core.Tests/Services/RecentlyRequestedServiceTests.cs index 018ee99e9..7e1046ca5 100644 --- a/src/Ombi.Core.Tests/Services/RecentlyRequestedServiceTests.cs +++ b/src/Ombi.Core.Tests/Services/RecentlyRequestedServiceTests.cs @@ -182,20 +182,25 @@ namespace Ombi.Core.Tests.Services var releaseDate = new DateTime(2019, 01, 01); var requestDate = DateTime.Now; - var movies = _fixture.CreateMany(10); + var movies = _fixture.CreateMany(10).ToList(); var albums = _fixture.CreateMany(10); var chilRequests = _fixture.CreateMany(10); + movies.Add(_fixture.Build().With(x => x.RequestedUserId, "a").With(x => x.Title, "unit").Create()); _mocker.Setup>(x => x.GetAll()).Returns(movies.AsQueryable().BuildMock()); _mocker.Setup>(x => x.GetAll()).Returns(albums.AsQueryable().BuildMock()); _mocker.Setup>(x => x.GetChild()).Returns(chilRequests.AsQueryable().BuildMock()); - _mocker.Setup>(x => x.GetUser()).ReturnsAsync(new OmbiUser { UserName = "test", Alias = "alias", UserType = UserType.LocalUser }); + _mocker.Setup>(x => x.GetUser()).ReturnsAsync(new OmbiUser { UserName = "test", Id = "a", Alias = "alias", UserType = UserType.LocalUser }); _mocker.Setup(x => x.Username).Returns("test"); _mocker.Setup>(x => x.IsInRoleAsync(It.IsAny(), It.IsAny())).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")); + }); } } } diff --git a/src/Ombi.Core/Services/RecentlyRequestedService.cs b/src/Ombi.Core/Services/RecentlyRequestedService.cs index 1c67472d4..6628dd8b8 100644 --- a/src/Ombi.Core/Services/RecentlyRequestedService.cs +++ b/src/Ombi.Core/Services/RecentlyRequestedService.cs @@ -73,6 +73,10 @@ namespace Ombi.Core.Services 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 { @@ -84,8 +88,8 @@ namespace Ombi.Core.Services 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(), @@ -94,6 +98,10 @@ namespace Ombi.Core.Services foreach (var item in await recentMusicRequests.ToListAsync(cancellationToken)) { + if (hideUsers.Hide && item.RequestedUserId != hideUsers.UserId) + { + continue; + } model.Add(new RecentlyRequestedModel { RequestId = item.Id, @@ -104,14 +112,18 @@ namespace Ombi.Core.Services 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)); @@ -127,8 +139,8 @@ namespace Ombi.Core.Services 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(),