Skip to content

Commit 659e9b1

Browse files
authored
Add relist and deprecate to unlist scope (#9938)
* Add relist and deprecate to unlist scope The relist API already uses the unlist scope. It has since we introduced API scopes. The deprecate action will be mentioned in the scope description only if the user is part of the deprecation API flight. Progress on #8873
1 parent a3c390c commit 659e9b1

12 files changed

Lines changed: 169 additions & 217 deletions

File tree

src/NuGetGallery.Services/Authentication/AuthenticationService.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,12 @@ public virtual CredentialViewModel DescribeCredential(Credential credential)
661661
}
662662
}
663663

664+
var isDeprecateApiEnabled = _featureFlagService != null && credential
665+
.Scopes
666+
.Select(s => s.Owner ?? credential.User)
667+
.Where(u => u != null)
668+
.Any(_featureFlagService.IsManageDeprecationApiEnabled);
669+
664670
var credentialViewModel = new CredentialViewModel
665671
{
666672
Key = credential.Key,
@@ -675,7 +681,7 @@ public virtual CredentialViewModel DescribeCredential(Credential credential)
675681
Scopes = credential.Scopes.Select(s => new ScopeViewModel(
676682
s.Owner?.Username ?? credential.User.Username,
677683
s.Subject,
678-
NuGetScopes.Describe(s.AllowedAction)))
684+
NuGetScopes.Describe(s.AllowedAction, isDeprecateApiEnabled)))
679685
.ToList(),
680686
ExpirationDuration = credential.ExpirationTicks != null ? new TimeSpan?(new TimeSpan(credential.ExpirationTicks.Value)) : null,
681687
RevocationSource = credential.RevocationSourceKey != null ? Enum.GetName(typeof(CredentialRevocationSource), credential.RevocationSourceKey) : null,

src/NuGetGallery.Services/Authentication/NuGetScopes.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public static class NuGetScopes
1111
public const string PackageUnlist = "package:unlist";
1212
public const string PackageVerify = "package:verify";
1313

14-
public static string Describe(string scope)
14+
public static string Describe(string scope, bool isDeprecateApiEnabled)
1515
{
1616
switch (scope.ToLowerInvariant())
1717
{
@@ -22,7 +22,7 @@ public static string Describe(string scope)
2222
case PackagePushVersion:
2323
return ServicesStrings.ScopeDescription_PushPackageVersion;
2424
case PackageUnlist:
25-
return ServicesStrings.ScopeDescription_UnlistPackage;
25+
return isDeprecateApiEnabled ? ServicesStrings.ScopeDescription_UnlistDeprecatePackage : ServicesStrings.ScopeDescription_UnlistPackage;
2626
case PackageVerify:
2727
return ServicesStrings.ScopeDescription_VerifyPackage;
2828
}

src/NuGetGallery.Services/ServicesStrings.Designer.cs

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/NuGetGallery.Services/ServicesStrings.resx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@
359359
<value>Push only new package versions</value>
360360
</data>
361361
<data name="ScopeDescription_UnlistPackage" xml:space="preserve">
362-
<value>Unlist package</value>
362+
<value>Unlist or relist package versions</value>
363363
</data>
364364
<data name="ScopeDescription_Unknown" xml:space="preserve">
365365
<value>Unknown</value>
@@ -1142,4 +1142,7 @@ The {1} Team</value>
11421142
<data name="AuthenticationProviderNotFound" xml:space="preserve">
11431143
<value>The given authentication provider is not supported.</value>
11441144
</data>
1145+
<data name="ScopeDescription_UnlistDeprecatePackage" xml:space="preserve">
1146+
<value>Unlist, relist, or deprecate package versions</value>
1147+
</data>
11451148
</root>

src/NuGetGallery/Controllers/UsersController.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,11 +480,16 @@ public virtual ActionResult ApiKeys()
480480
owners.AddRange(currentUser.Organizations
481481
.Select(o => CreateApiKeyOwnerViewModel(currentUser, o.Organization)));
482482

483+
var anyWithDeprecationApi =
484+
_featureFlagService.IsManageDeprecationApiEnabled(currentUser)
485+
|| currentUser.Organizations.Any(m => _featureFlagService.IsManageDeprecationApiEnabled(m.Organization));
486+
483487
var model = new ApiKeyListViewModel
484488
{
485489
ApiKeys = apiKeys,
486490
ExpirationInDaysForApiKeyV1 = _config.ExpirationInDaysForApiKeyV1,
487491
PackageOwners = owners.Where(o => o.CanPushNew || o.CanPushExisting || o.CanUnlist).ToList(),
492+
IsDeprecationApiEnabled = anyWithDeprecationApi,
488493
};
489494

490495
return View("ApiKeys", model);

src/NuGetGallery/Strings.Designer.cs

Lines changed: 1 addition & 55 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/NuGetGallery/Strings.resx

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -349,21 +349,6 @@
349349
<data name="UserAccountLocked" xml:space="preserve">
350350
<value>Your account was locked after too many unsuccessful sign-in attempts. Please try again in {0}.</value>
351351
</data>
352-
<data name="ScopeDescription_All" xml:space="preserve">
353-
<value>All</value>
354-
</data>
355-
<data name="ScopeDescription_PushPackage" xml:space="preserve">
356-
<value>Push new packages and package versions</value>
357-
</data>
358-
<data name="ScopeDescription_PushPackageVersion" xml:space="preserve">
359-
<value>Push only new package versions</value>
360-
</data>
361-
<data name="ScopeDescription_UnlistPackage" xml:space="preserve">
362-
<value>Unlist package</value>
363-
</data>
364-
<data name="ScopeDescription_Unknown" xml:space="preserve">
365-
<value>Unknown</value>
366-
</data>
367352
<data name="ApiKeyDescriptionRequired" xml:space="preserve">
368353
<value>Can't generate an API key without a description.</value>
369354
</data>
@@ -385,9 +370,6 @@
385370
<data name="NonScopedApiKeyDescription" xml:space="preserve">
386371
<value>Full access API key</value>
387372
</data>
388-
<data name="ScopeDescription_VerifyPackage" xml:space="preserve">
389-
<value>Verify package ownership</value>
390-
</data>
391373
<data name="WarningApiDeprecated" xml:space="preserve">
392374
<value>API '{0}' is deprecated and may be removed in a future version.</value>
393375
</data>

src/NuGetGallery/ViewModels/ApiKeyListViewModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ public class ApiKeyListViewModel
1010
public IList<ApiKeyViewModel> ApiKeys { get; set; }
1111
public int ExpirationInDaysForApiKeyV1 { get; set; }
1212
public IList<ApiKeyOwnerViewModel> PackageOwners { get; set; }
13+
public bool IsDeprecationApiEnabled { get; set; }
1314
}
1415
}

src/NuGetGallery/Views/Users/ApiKeys.cshtml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@
366366
</div>
367367
<label id="select-scopes-push-package" data-bind="attr: { for: PackagePushId }"
368368
aria-labelledby="select-scopes-push-package select-scopes">
369-
@NuGetScopes.Describe(NuGetScopes.PackagePush)
369+
@NuGetScopes.Describe(NuGetScopes.PackagePush, Model.IsDeprecationApiEnabled)
370370
</label>
371371
</div>
372372
</li>
@@ -379,7 +379,7 @@
379379
</div>
380380
<label id="select-scopes-push-package-version" data-bind="attr: { for: PackagePushVersionId }"
381381
aria-labelledby="select-scopes-push-package-version select-scopes">
382-
@NuGetScopes.Describe(NuGetScopes.PackagePushVersion)
382+
@NuGetScopes.Describe(NuGetScopes.PackagePushVersion, Model.IsDeprecationApiEnabled)
383383
</label>
384384
</div>
385385
</li>
@@ -391,7 +391,7 @@
391391
<input type="checkbox" value="@NuGetScopes.PackageUnlist"
392392
aria-labelledby="select-scopes-unlist select-scopes"
393393
data-bind="checked: UnlistScopeChecked, enable: UnlistEnabled" />
394-
@NuGetScopes.Describe(NuGetScopes.PackageUnlist)
394+
@NuGetScopes.Describe(NuGetScopes.PackageUnlist, Model.IsDeprecationApiEnabled)
395395
</label>
396396
</div>
397397
</li>

0 commit comments

Comments
 (0)