Skip to content

Commit 548d05d

Browse files
author
Scott Bommarito
authored
Deprecation information should flow into V3 (#7173)
1 parent 32bf908 commit 548d05d

29 files changed

Lines changed: 940 additions & 520 deletions

src/NuGetGallery.Core/Entities/EntitiesContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public EntitiesContext(DbConnection connection, bool readOnly)
5858

5959
public bool ReadOnly { get; private set; }
6060
public DbSet<Package> Packages { get; set; }
61+
public DbSet<PackageDeprecation> Deprecations { get; set; }
6162
public DbSet<PackageRegistration> PackageRegistrations { get; set; }
6263
public DbSet<Credential> Credentials { get; set; }
6364
public DbSet<Scope> Scopes { get; set; }

src/NuGetGallery.Core/Entities/IEntitiesContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public interface IEntitiesContext : IDisposable
1212
{
1313
DbSet<Certificate> Certificates { get; set; }
1414
DbSet<Package> Packages { get; set; }
15+
DbSet<PackageDeprecation> Deprecations { get; set; }
1516
DbSet<PackageRegistration> PackageRegistrations { get; set; }
1617
DbSet<Credential> Credentials { get; set; }
1718
DbSet<Scope> Scopes { get; set; }

src/NuGetGallery.Services/AccountManagement/DeleteAccountService.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class DeleteAccountService : IDeleteAccountService
2222
private readonly IEntityRepository<PackageDelete> _packageDeleteRepository;
2323
private readonly IEntitiesContext _entitiesContext;
2424
private readonly IPackageService _packageService;
25+
private readonly IPackageUpdateService _packageUpdateService;
2526
private readonly IPackageOwnershipManagementService _packageOwnershipManagementService;
2627
private readonly IReservedNamespaceService _reservedNamespaceService;
2728
private readonly ISecurityPolicyService _securityPolicyService;
@@ -42,6 +43,7 @@ public DeleteAccountService(
4243
IEntityRepository<Scope> scopeRepository,
4344
IEntitiesContext entitiesContext,
4445
IPackageService packageService,
46+
IPackageUpdateService packageUpdateService,
4547
IPackageOwnershipManagementService packageOwnershipManagementService,
4648
IReservedNamespaceService reservedNamespaceService,
4749
ISecurityPolicyService securityPolicyService,
@@ -58,6 +60,7 @@ public DeleteAccountService(
5860
_scopeRepository = scopeRepository ?? throw new ArgumentNullException(nameof(scopeRepository));
5961
_entitiesContext = entitiesContext ?? throw new ArgumentNullException(nameof(entitiesContext));
6062
_packageService = packageService ?? throw new ArgumentNullException(nameof(packageService));
63+
_packageUpdateService = packageUpdateService ?? throw new ArgumentNullException(nameof(packageUpdateService));
6164
_packageOwnershipManagementService = packageOwnershipManagementService ?? throw new ArgumentNullException(nameof(packageOwnershipManagementService));
6265
_reservedNamespaceService = reservedNamespaceService ?? throw new ArgumentNullException(nameof(reservedNamespaceService));
6366
_securityPolicyService = securityPolicyService ?? throw new ArgumentNullException(nameof(securityPolicyService));
@@ -210,7 +213,7 @@ private async Task RemovePackageOwnership(User user, User requestingUser, Accoun
210213
}
211214
else if (orphanPackagePolicy == AccountDeletionOrphanPackagePolicy.UnlistOrphans)
212215
{
213-
await _packageService.MarkPackageUnlistedAsync(package, commitChanges: false);
216+
await _packageUpdateService.MarkPackageUnlistedAsync(package, commitChanges: false, updateIndex: false);
214217
}
215218
}
216219

src/NuGetGallery.Services/NuGetGallery.Services.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@
8282
<Compile Include="Models\StorageType.cs" />
8383
<Compile Include="PackageManagement\ActionOnNewPackageContext.cs" />
8484
<Compile Include="PackageManagement\IPackageOwnerRequestService.cs" />
85+
<Compile Include="PackageManagement\IIndexingService.cs" />
8586
<Compile Include="PackageManagement\IPackageOwnershipManagementService.cs" />
8687
<Compile Include="PackageManagement\IPackageService.cs" />
88+
<Compile Include="PackageManagement\IPackageUpdateService.cs" />
8789
<Compile Include="PackageManagement\IReservedNamespaceService.cs" />
8890
<Compile Include="PackageManagement\PackageDeleteDecision.cs" />
8991
<Compile Include="PackageManagement\PackageHelper.cs" />
@@ -99,6 +101,7 @@
99101
<Compile Include="Permissions\PermissionsCheckResult.cs" />
100102
<Compile Include="Permissions\PermissionsHelpers.cs" />
101103
<Compile Include="Permissions\PermissionsRequirement.cs" />
104+
<Compile Include="PackageManagement\PackageUpdateService.cs" />
102105
<Compile Include="Properties\AssemblyInfo.cs" />
103106
<Compile Include="Providers\DateTimeProvider.cs" />
104107
<Compile Include="Providers\IDateTimeProvider.cs" />

src/NuGetGallery/Services/IIndexingService.cs renamed to src/NuGetGallery.Services/PackageManagement/IIndexingService.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5-
using System.Collections.Generic;
65
using System.Threading.Tasks;
76
using NuGet.Services.Entities;
8-
using NuGetGallery.Configuration;
9-
using WebBackgrounder;
107

118
namespace NuGetGallery
129
{
@@ -20,8 +17,6 @@ public interface IIndexingService
2017
Task<int> GetDocumentCount();
2118
Task<long> GetIndexSizeInBytes();
2219

23-
void RegisterBackgroundJobs(IList<IJob> jobs, IAppConfiguration configuration);
24-
2520
string IndexPath { get; }
2621

2722
bool IsLocal { get; }

src/NuGetGallery.Services/PackageManagement/IPackageService.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,6 @@ Package FilterLatestPackage(
9898
Task PublishPackageAsync(string id, string version, bool commitChanges = true);
9999
Task PublishPackageAsync(Package package, bool commitChanges = true);
100100

101-
Task MarkPackageUnlistedAsync(Package package, bool commitChanges = true);
102-
Task MarkPackageListedAsync(Package package, bool commitChanges = true);
103-
104101
/// <summary>
105102
/// Performs database changes to add a new package owner while removing the corresponding package owner request.
106103
/// </summary>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using NuGet.Services.Entities;
5+
using System.Collections.Generic;
6+
using System.Threading.Tasks;
7+
8+
namespace NuGetGallery
9+
{
10+
public interface IPackageUpdateService
11+
{
12+
/// <summary>
13+
/// Marks <paramref name="package"/> as unlisted.
14+
/// </summary>
15+
/// <param name="package">The package to unlist.</param>
16+
/// <param name="commitChanges">Whether or not changes should be committed.</param>
17+
/// <param name="updateIndex">If true, <see cref="IIndexingService.UpdatePackage(Package)"/> will be called.</param>
18+
Task MarkPackageUnlistedAsync(Package package, bool commitChanges = true, bool updateIndex = true);
19+
20+
/// <summary>
21+
/// Marks <paramref name="package"/> as listed.
22+
/// </summary>
23+
/// <param name="package">The package to list.</param>
24+
/// <param name="commitChanges">Whether or not changes should be committed.</param>
25+
/// <param name="updateIndex">If true, <see cref="IIndexingService.UpdatePackage(Package)"/> will be called.</param>
26+
Task MarkPackageListedAsync(Package package, bool commitChanges = true, bool updateIndex = true);
27+
28+
/// <summary>
29+
/// Marks the packages in <paramref name="packages"/> as updated.
30+
/// </summary>
31+
/// <param name="packages">
32+
/// The packages to mark as updated. All packages must have the same <see cref="PackageRegistration"/>.
33+
/// </param>
34+
/// <param name="updateIndex">If true, <see cref="IIndexingService.UpdatePackage(Package)"/> will be called.</param>
35+
Task UpdatePackagesAsync(IReadOnlyList<Package> packages, bool updateIndex = true);
36+
}
37+
}

src/NuGetGallery.Services/PackageManagement/PackageService.cs

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -423,81 +423,6 @@ private bool WillPackageBeOrphanedIfOwnerRemovedHelper(IEnumerable<User> owners,
423423
return true;
424424
}
425425

426-
public async Task MarkPackageListedAsync(Package package, bool commitChanges = true)
427-
{
428-
if (package == null)
429-
{
430-
throw new ArgumentNullException(nameof(package));
431-
}
432-
433-
if (package.Listed)
434-
{
435-
return;
436-
}
437-
438-
if (package.PackageStatusKey == PackageStatus.Deleted)
439-
{
440-
throw new InvalidOperationException("A deleted package should never be listed!");
441-
}
442-
443-
if (package.PackageStatusKey == PackageStatus.FailedValidation)
444-
{
445-
throw new InvalidOperationException("A package that failed validation should never be listed!");
446-
}
447-
448-
if (!package.Listed && (package.IsLatestStable || package.IsLatest))
449-
{
450-
throw new InvalidOperationException("An unlisted package should never be latest or latest stable!");
451-
}
452-
453-
package.Listed = true;
454-
package.LastUpdated = DateTime.UtcNow;
455-
// NOTE: LastEdited will be overwritten by a trigger defined in the migration named "AddTriggerForPackagesLastEdited".
456-
package.LastEdited = DateTime.UtcNow;
457-
458-
await UpdateIsLatestAsync(package.PackageRegistration, commitChanges: false);
459-
460-
await _auditingService.SaveAuditRecordAsync(new PackageAuditRecord(package, AuditedPackageAction.List));
461-
462-
_telemetryService.TrackPackageListed(package);
463-
464-
if (commitChanges)
465-
{
466-
await _packageRepository.CommitChangesAsync();
467-
}
468-
}
469-
470-
public async Task MarkPackageUnlistedAsync(Package package, bool commitChanges = true)
471-
{
472-
if (package == null)
473-
{
474-
throw new ArgumentNullException(nameof(package));
475-
}
476-
if (!package.Listed)
477-
{
478-
return;
479-
}
480-
481-
package.Listed = false;
482-
package.LastUpdated = DateTime.UtcNow;
483-
// NOTE: LastEdited will be overwritten by a trigger defined in the migration named "AddTriggerForPackagesLastEdited".
484-
package.LastEdited = DateTime.UtcNow;
485-
486-
if (package.IsLatest || package.IsLatestStable)
487-
{
488-
await UpdateIsLatestAsync(package.PackageRegistration, commitChanges: false);
489-
}
490-
491-
await _auditingService.SaveAuditRecordAsync(new PackageAuditRecord(package, AuditedPackageAction.Unlist));
492-
493-
_telemetryService.TrackPackageUnlisted(package);
494-
495-
if (commitChanges)
496-
{
497-
await _packageRepository.CommitChangesAsync();
498-
}
499-
}
500-
501426
private PackageRegistration CreateOrGetPackageRegistration(User owner, PackageMetadata packageMetadata, bool isVerified)
502427
{
503428
var packageRegistration = FindPackageRegistrationById(packageMetadata.Id);

0 commit comments

Comments
 (0)