From acf604305bd846cf944d55796ee3ad46a792818d Mon Sep 17 00:00:00 2001 From: TidusJar Date: Wed, 4 Jul 2018 14:40:02 +0100 Subject: [PATCH] Fixed the issue where you could not delete a user #2365 --- src/Ombi/Controllers/IdentityController.cs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Ombi/Controllers/IdentityController.cs b/src/Ombi/Controllers/IdentityController.cs index e9fb17af6..38c2d1e94 100644 --- a/src/Ombi/Controllers/IdentityController.cs +++ b/src/Ombi/Controllers/IdentityController.cs @@ -57,7 +57,9 @@ namespace Ombi.Controllers ISettingsService settings, IRepository requestLog, IRepository issues, - IRepository issueComments) + IRepository issueComments, + IRepository notificationRepository, + IRepository subscriptionRepository) { UserManager = user; Mapper = mapper; @@ -75,6 +77,8 @@ namespace Ombi.Controllers _requestLogRepository = requestLog; _issueCommentsRepository = issueComments; OmbiSettings = ombiSettings; + _requestSubscriptionRepository = subscriptionRepository; + _notificationRepository = notificationRepository; } private OmbiUserManager UserManager { get; } @@ -93,6 +97,8 @@ namespace Ombi.Controllers private readonly IRepository _issuesRepository; private readonly IRepository _issueCommentsRepository; private readonly IRepository _requestLogRepository; + private readonly IRepository _notificationRepository; + private readonly IRepository _requestSubscriptionRepository; /// @@ -568,6 +574,19 @@ namespace Ombi.Controllers { await _issueCommentsRepository.DeleteRange(issueComments); } + + // Delete the Subscriptions and mobile notification ids + var subs = _requestSubscriptionRepository.GetAll().Where(x => x.UserId == userId); + var mobileIds = _notificationRepository.GetAll().Where(x => x.UserId == userId); + if (subs.Any()) + { + await _requestSubscriptionRepository.DeleteRange(subs); + } + + if (mobileIds.Any()) + { + await _notificationRepository.DeleteRange(mobileIds); + } var result = await UserManager.DeleteAsync(userToDelete); if (result.Succeeded)