Skip to content

Commit 14b204c

Browse files
Add fix for issue 1929. … (#6754)
Add fix for issue 1929. More cleanup for the support request when an account is deleted.
1 parent f14275f commit 14b204c

5 files changed

Lines changed: 39 additions & 20 deletions

File tree

src/NuGetGallery/Areas/Admin/Services/ISupportRequestService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Task<Issue> AddNewSupportRequestAsync(
5757

5858
Task AddAdminAsync(string galleryUsername);
5959

60-
Task DeleteSupportRequestsAsync(string createdBy);
60+
Task DeleteSupportRequestsAsync(User user);
6161

6262
Task<bool> TryAddDeleteSupportRequestAsync(User user);
6363
}

src/NuGetGallery/Areas/Admin/Services/SupportRequestService.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -286,26 +286,27 @@ public string GetIssueStatusNameById(int id)
286286
return issue?.Name;
287287
}
288288

289-
public async Task DeleteSupportRequestsAsync(string createdBy)
289+
public async Task DeleteSupportRequestsAsync(User user)
290290
{
291-
if (createdBy == null)
291+
if (user == null)
292292
{
293-
throw new ArgumentNullException(nameof(createdBy));
293+
throw new ArgumentNullException(nameof(user));
294294
}
295-
var userCreatedIssues = GetIssues().Where(i => string.Equals(i.CreatedBy, createdBy, StringComparison.InvariantCultureIgnoreCase)).ToList();
295+
var userIssues = GetIssues().Where(i => i.UserKey.HasValue && i.UserKey.Value == user.Key).ToList();
296296
// Delete all the support requests with exception of the delete account request.
297297
// For the DeleteAccount support request clean the user data.
298-
foreach (var issue in userCreatedIssues.Where(i => !string.Equals(i.IssueTitle, Strings.AccountDelete_SupportRequestTitle)))
298+
foreach (var issue in userIssues.Where(i => !string.Equals(i.IssueTitle, Strings.AccountDelete_SupportRequestTitle)))
299299
{
300300
_supportRequestDbContext.Issues.Remove(issue);
301301
}
302-
foreach (var accountDeletedIssue in userCreatedIssues.Where(i => string.Equals(i.IssueTitle, Strings.AccountDelete_SupportRequestTitle)))
302+
foreach (var accountDeletedIssue in userIssues.Where(i => string.Equals(i.IssueTitle, Strings.AccountDelete_SupportRequestTitle)))
303303
{
304304
accountDeletedIssue.OwnerEmail = "deletedaccount";
305305
accountDeletedIssue.CreatedBy = null;
306+
accountDeletedIssue.Details = "This support request has been redacted as the customer's account has been deleted.";
306307
foreach (var historyEntry in accountDeletedIssue.HistoryEntries)
307308
{
308-
if (string.Equals(historyEntry.EditedBy, createdBy, StringComparison.InvariantCultureIgnoreCase))
309+
if (string.Equals(historyEntry.EditedBy, user.Username, StringComparison.InvariantCultureIgnoreCase))
309310
{
310311
historyEntry.EditedBy = null;
311312
}

src/NuGetGallery/Services/DeleteAccountService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ private async Task RemoveUserDataInUserTable(User user)
282282

283283
private async Task RemoveSupportRequests(User user)
284284
{
285-
await _supportRequestService.DeleteSupportRequestsAsync(user.Username);
285+
await _supportRequestService.DeleteSupportRequestsAsync(user);
286286
}
287287

288288
private async Task RemoveUser(User user)

tests/NuGetGallery.Facts/Services/DeleteAccountServiceFacts.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ private Mock<ISupportRequestService> SetupSupportRequestService()
682682
if (_user != null)
683683
{
684684
var issue = SupportRequests.Where(i => string.Equals(i.CreatedBy, _user.Username)).FirstOrDefault();
685-
supportService.Setup(m => m.DeleteSupportRequestsAsync(_user.Username))
685+
supportService.Setup(m => m.DeleteSupportRequestsAsync(_user))
686686
.Returns(Task.FromResult(true))
687687
.Callback(() => SupportRequests.Remove(issue));
688688
}

tests/NuGetGallery.Facts/Services/SupportRequestServiceFacts.cs

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,35 +38,53 @@ public async Task DeleteRequestsNormalPath()
3838
// Arrange
3939
string userName = "Joe";
4040
string emailAddress = "[email protected]";
41+
User user = new User()
42+
{
43+
Username = userName,
44+
EmailAddress = emailAddress,
45+
Key = 11
46+
};
4147

4248
TestSupportRequestDbContext supportRequestContext = new TestSupportRequestDbContext();
4349
Issue JoesDeleteAccountRequest = new Issue()
4450
{
45-
CreatedBy = userName,
51+
CreatedBy = user.Username,
4652
Key = 1,
4753
IssueTitle = Strings.AccountDelete_SupportRequestTitle,
48-
OwnerEmail = emailAddress,
54+
OwnerEmail = user.EmailAddress,
4955
IssueStatusId = IssueStatusKeys.New,
50-
HistoryEntries = new List<History>() { new History() { EditedBy = userName, IssueId = 1, Key = 1, IssueStatusId = IssueStatusKeys.New } }
56+
HistoryEntries = new List<History>()
57+
{
58+
new History() { EditedBy = userName, IssueId = 1, Key = 1, IssueStatusId = IssueStatusKeys.New }
59+
},
60+
UserKey = user.Key
5161
};
5262
Issue JoesOldIssue = new Issue()
5363
{
54-
CreatedBy = userName,
64+
CreatedBy = user.Username,
5565
Key = 2,
5666
IssueTitle = "Joe's OldIssue",
57-
OwnerEmail = emailAddress,
67+
OwnerEmail = user.EmailAddress,
5868
IssueStatusId = IssueStatusKeys.Resolved,
59-
HistoryEntries = new List<History>() { new History() { EditedBy = userName, IssueId = 2, Key = 2, IssueStatusId = IssueStatusKeys.New },
60-
new History() { EditedBy = userName, IssueId = 2, Key = 2, IssueStatusId = IssueStatusKeys.Resolved }}
69+
HistoryEntries = new List<History>()
70+
{
71+
new History() { EditedBy = userName, IssueId = 2, Key = 2, IssueStatusId = IssueStatusKeys.New },
72+
new History() { EditedBy = userName, IssueId = 2, Key = 2, IssueStatusId = IssueStatusKeys.Resolved }
73+
},
74+
UserKey = user.Key
6175
};
6276
Issue randomIssue = new Issue()
6377
{
64-
CreatedBy = $"{userName}_second",
78+
CreatedBy = $"{user.Username}_second",
6579
Key = 3,
6680
IssueTitle = "Second",
6781
OwnerEmail = "random",
6882
IssueStatusId = IssueStatusKeys.New,
69-
HistoryEntries = new List<History>() { new History() { EditedBy = $"{userName}_second", IssueId = 3, Key = 3, IssueStatusId = IssueStatusKeys.New } }
83+
HistoryEntries = new List<History>()
84+
{
85+
new History() { EditedBy = $"{userName}_second", IssueId = 3, Key = 3, IssueStatusId = IssueStatusKeys.New }
86+
},
87+
UserKey = user.Key + 1
7088
};
7189
supportRequestContext.Issues.Add(JoesDeleteAccountRequest);
7290
supportRequestContext.Issues.Add(JoesOldIssue);
@@ -76,7 +94,7 @@ public async Task DeleteRequestsNormalPath()
7694
SupportRequestService supportRequestService = new SupportRequestService(supportRequestContext, GetAppConfig(),auditingService.Object);
7795

7896
// Act
79-
await supportRequestService.DeleteSupportRequestsAsync(userName);
97+
await supportRequestService.DeleteSupportRequestsAsync(user);
8098

8199
//Assert
82100
Assert.Equal<int>(2, supportRequestContext.Issues.Count());

0 commit comments

Comments
 (0)