Skip to content

Commit

Permalink
Small fixes (#4978)
Browse files Browse the repository at this point in the history
* fix(tv-requests): 🐛 Fixed a small bug where an exception can get thrown when attempting to view TV Requests

* fix(user-importer): 🐛 Fixed an issue where the cleanup wouldn't delete users #4812
  • Loading branch information
tidusjar authored Jul 3, 2023
1 parent 3c3edf6 commit 5bc87b3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
9 changes: 8 additions & 1 deletion src/Ombi.Core/Engine/TvRequestEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,14 @@ private void CheckForPlayed(HideResult shouldHide, List<ChildRequests> childRequ

var playedCount = playedEpisodes.Count();
var toWatchCount = requestedEpisodes.Count();
request.RequestedUserPlayedProgress = 100 * playedCount / toWatchCount;
if (playedCount == 0 || toWatchCount == 0)
{
request.RequestedUserPlayedProgress = 0;
}
else
{
request.RequestedUserPlayedProgress = 100 * playedCount / toWatchCount;
}

}
}
Expand Down
1 change: 1 addition & 0 deletions src/Ombi.Core/Engine/UserDeletionEngine.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.VisualBasic;
using Ombi.Core.Authentication;
using Ombi.Store.Entities;
using Ombi.Store.Entities.Requests;
Expand Down
5 changes: 3 additions & 2 deletions src/Ombi.Schedule.Tests/PlexUserImporterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Ombi.Api.Plex.Models;
using Ombi.Api.Plex.Models.Friends;
using Ombi.Core.Authentication;
using Ombi.Core.Engine;
using Ombi.Core.Settings;
using Ombi.Core.Settings.Models.External;
using Ombi.Helpers;
Expand Down Expand Up @@ -365,7 +366,7 @@ public async Task Import_Cleanup_Missing_Plex_Users()

await _subject.Execute(null);

_mocker.Verify<OmbiUserManager>(x => x.DeleteAsync(It.Is<OmbiUser>(x => x.ProviderUserId == "PLEX_ID" && x.Email == "dupe" && x.UserName == "plex")), Times.Once);
_mocker.Verify<IUserDeletionEngine>(x => x.DeleteUser(It.Is<OmbiUser>(x => x.ProviderUserId == "PLEX_ID" && x.Email == "dupe" && x.UserName == "plex")), Times.Once);
}

[Test]
Expand Down Expand Up @@ -401,7 +402,7 @@ public async Task Import_Cleanup_Missing_Plex_Admin()

await _subject.Execute(null);

_mocker.Verify<OmbiUserManager>(x => x.DeleteAsync(It.Is<OmbiUser>(x => x.ProviderUserId == "PLEX_ID" && x.Email == "dupe" && x.UserName == "plex")), Times.Once);
_mocker.Verify<IUserDeletionEngine>(x => x.DeleteUser(It.Is<OmbiUser>(x => x.ProviderUserId == "PLEX_ID" && x.Email == "dupe" && x.UserName == "plex")), Times.Once);
}
}
}
9 changes: 6 additions & 3 deletions src/Ombi.Schedule/Jobs/Plex/PlexUserImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.Extensions.Logging;
using Ombi.Api.Plex;
using Ombi.Core.Authentication;
using Ombi.Core.Engine;
using Ombi.Core.Settings;
using Ombi.Core.Settings.Models.External;
using Ombi.Helpers;
Expand All @@ -20,14 +21,16 @@ namespace Ombi.Schedule.Jobs.Plex
public class PlexUserImporter : IPlexUserImporter
{
public PlexUserImporter(IPlexApi api, OmbiUserManager um, ILogger<PlexUserImporter> log,
ISettingsService<PlexSettings> plexSettings, ISettingsService<UserManagementSettings> ums, INotificationHubService notificationHubService)
ISettingsService<PlexSettings> plexSettings, ISettingsService<UserManagementSettings> ums, INotificationHubService notificationHubService,
IUserDeletionEngine userDeletionEngine)
{
_api = api;
_userManager = um;
_log = log;
_plexSettings = plexSettings;
_userManagementSettings = ums;
_notification = notificationHubService;
_userDeletionEngine = userDeletionEngine;
_plexSettings.ClearCache();
_userManagementSettings.ClearCache();
}
Expand All @@ -38,7 +41,7 @@ public PlexUserImporter(IPlexApi api, OmbiUserManager um, ILogger<PlexUserImport
private readonly ISettingsService<PlexSettings> _plexSettings;
private readonly ISettingsService<UserManagementSettings> _userManagementSettings;
private readonly INotificationHubService _notification;

private readonly IUserDeletionEngine _userDeletionEngine;

public async Task Execute(IJobExecutionContext job)
{
Expand Down Expand Up @@ -90,7 +93,7 @@ public async Task Execute(IJobExecutionContext job)
foreach (var ombiUser in missingUsers)
{
_log.LogInformation("Deleting user {0} not found in Plex Server.", ombiUser.UserName);
await _userManager.DeleteAsync(ombiUser);
await _userDeletionEngine.DeleteUser(ombiUser);
}
}

Expand Down

0 comments on commit 5bc87b3

Please sign in to comment.