-
Notifications
You must be signed in to change notification settings - Fork 644
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5245 from NuGet/dev
[ReleasePrep][2018.01.18] RI of dev into master
- Loading branch information
Showing
117 changed files
with
4,505 additions
and
1,473 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace NuGetGallery | ||
{ | ||
public class MembershipRequest | ||
{ | ||
public int OrganizationKey { get; set; } | ||
|
||
public virtual Organization Organization { get; set; } | ||
|
||
public int NewMemberKey { get; set; } | ||
|
||
public virtual User NewMember { get; set; } | ||
|
||
public bool IsAdmin { get; set; } | ||
|
||
[Required] | ||
public string ConfirmationToken { get; set; } | ||
|
||
public DateTime RequestDate { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/NuGetGallery.Core/Entities/OrganizationMigrationRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace NuGetGallery | ||
{ | ||
public class OrganizationMigrationRequest | ||
{ | ||
public int NewOrganizationKey { get; set; } | ||
|
||
public virtual User NewOrganization { get; set; } | ||
|
||
public int AdminUserKey { get; set; } | ||
|
||
public virtual User AdminUser { get; set; } | ||
|
||
[Required] | ||
public string ConfirmationToken { get; set; } | ||
|
||
public DateTime RequestDate { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/NuGetGallery/Areas/Admin/Controllers/LockPackageController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using System.Web.Mvc; | ||
using NuGetGallery.Areas.Admin.ViewModels; | ||
|
||
namespace NuGetGallery.Areas.Admin.Controllers | ||
{ | ||
public class LockPackageController : AdminControllerBase | ||
{ | ||
private IEntityRepository<PackageRegistration> _packageRegistrationRepository; | ||
|
||
public LockPackageController(IEntityRepository<PackageRegistration> packageRegistrationRepository) | ||
{ | ||
_packageRegistrationRepository = packageRegistrationRepository ?? throw new ArgumentNullException(nameof(packageRegistrationRepository)); | ||
} | ||
|
||
[HttpGet] | ||
public virtual ActionResult Index() | ||
{ | ||
var model = new LockPackageViewModel(); | ||
|
||
return View(model); | ||
} | ||
|
||
[HttpGet] | ||
public virtual ActionResult Search(string query) | ||
{ | ||
var lines = Helpers.ParseQueryToLines(query); | ||
var packageRegistrations = GetPackageRegistrationsForIds(lines); | ||
|
||
return View(nameof(Index), new LockPackageViewModel() | ||
{ | ||
Query = query, | ||
PackageLockStates = packageRegistrations.Select(x => new PackageLockState() { Id = x.Id, IsLocked = x.IsLocked }).ToList() | ||
}); | ||
} | ||
|
||
[HttpPost] | ||
[ValidateAntiForgeryToken] | ||
public async Task<ActionResult> Update(LockPackageViewModel lockPackageViewModel) | ||
{ | ||
int counter = 0; | ||
|
||
if (lockPackageViewModel != null && lockPackageViewModel.PackageLockStates != null) | ||
{ | ||
var packageIdsFromRequest = lockPackageViewModel.PackageLockStates.Select(x => x.Id).ToList(); | ||
var packageRegistrationsFromDb = GetPackageRegistrationsForIds(packageIdsFromRequest); | ||
|
||
var packageStatesFromRequestDictionary = lockPackageViewModel.PackageLockStates.ToDictionary(x => x.Id); | ||
|
||
foreach (var packageRegistration in packageRegistrationsFromDb) | ||
{ | ||
if (packageStatesFromRequestDictionary.TryGetValue(packageRegistration.Id, out var packageStateRequest)) | ||
{ | ||
if (packageRegistration.IsLocked != packageStateRequest.IsLocked) | ||
{ | ||
packageRegistration.IsLocked = packageStateRequest.IsLocked; | ||
counter++; | ||
} | ||
} | ||
} | ||
|
||
if (counter > 0) | ||
{ | ||
await _packageRegistrationRepository.CommitChangesAsync(); | ||
} | ||
} | ||
|
||
TempData["Message"] = string.Format(CultureInfo.InvariantCulture, $"Lock state was updated for {counter} packages."); | ||
|
||
return View(nameof(Index), lockPackageViewModel); | ||
} | ||
|
||
private IList<PackageRegistration> GetPackageRegistrationsForIds(IReadOnlyList<string> ids) | ||
{ | ||
return _packageRegistrationRepository.GetAll().Where(x => ids.Contains(x.Id)).ToList(); | ||
} | ||
} | ||
} |
Oops, something went wrong.