public virtual ActionResult VerifyPackage(bool? listed) { var currentUser = userSvc.FindByUsername(GetIdentity().Name); IPackage nugetPackage; using (var uploadFile = uploadFileSvc.GetUploadFile(currentUser.Key)) { if (uploadFile == null) return HttpNotFound(); nugetPackage = ReadNuGetPackage(uploadFile); } Package package; using (var tx = new TransactionScope()) { package = packageSvc.CreatePackage(nugetPackage, currentUser); packageSvc.PublishPackage(package.PackageRegistration.Id, package.Version); if (listed.HasValue && listed.Value == false) packageSvc.MarkPackageUnlisted(package); uploadFileSvc.DeleteUploadFile(currentUser.Key); autoCuratedPackageCmd.Execute(package, nugetPackage); tx.Complete(); } TempData["Message"] = string.Format( "You have successfully created '{0}' version '{1}'. The package is now under review by the moderators and will show up once approved.", package.PackageRegistration.Id, package.Version); return RedirectToRoute( RouteName.DisplayPackage, new { package.PackageRegistration.Id, package.Version }); }
public virtual async Task <ActionResult> VerifyPackage(bool?listed) { var currentUser = _userService.FindByUsername(GetIdentity().Name); Package package; using (Stream uploadFile = await _uploadFileService.GetUploadFileAsync(currentUser.Key)) { if (uploadFile == null) { return(HttpNotFound()); } INupkg nugetPackage = CreatePackage(uploadFile); // update relevant database tables package = _packageService.CreatePackage(nugetPackage, currentUser, commitChanges: false); Debug.Assert(package.PackageRegistration != null); _packageService.PublishPackage(package, commitChanges: false); if (listed == false) { _packageService.MarkPackageUnlisted(package, commitChanges: false); } _autoCuratedPackageCmd.Execute(package, nugetPackage, commitChanges: false); // save package to blob storage uploadFile.Position = 0; await _packageFileService.SavePackageFileAsync(package, uploadFile); // commit all changes to database as an atomic transaction _entitiesContext.SaveChanges(); // tell Lucene to update index for the new package _indexingService.UpdateIndex(); // If we're pushing a new stable version of NuGet.CommandLine, update the extracted executable. if (package.PackageRegistration.Id.Equals(Constants.NuGetCommandLinePackageId, StringComparison.OrdinalIgnoreCase) && package.IsLatestStable) { await _nugetExeDownloaderService.UpdateExecutableAsync(nugetPackage); } } // delete the uploaded binary in the Uploads container await _uploadFileService.DeleteUploadFileAsync(currentUser.Key); TempData["Message"] = String.Format( CultureInfo.CurrentCulture, Strings.SuccessfullyUploadedPackage, package.PackageRegistration.Id, package.Version); return(RedirectToRoute(RouteName.DisplayPackage, new { package.PackageRegistration.Id, package.Version })); }
public virtual ActionResult VerifyPackage(bool?listed) { var currentUser = userSvc.FindByUsername(GetIdentity().Name); IPackage nugetPackage; using (var uploadFile = uploadFileSvc.GetUploadFile(currentUser.Key)) { if (uploadFile == null) { return(HttpNotFound()); } nugetPackage = ReadNuGetPackage(uploadFile); } Package package; using (var tx = new TransactionScope()) { package = packageSvc.CreatePackage(nugetPackage, currentUser); packageSvc.PublishPackage(package.PackageRegistration.Id, package.Version); if (listed.HasValue && listed.Value == false) { packageSvc.MarkPackageUnlisted(package); } uploadFileSvc.DeleteUploadFile(currentUser.Key); autoCuratedPackageCmd.Execute(package, nugetPackage); tx.Complete(); } if (package.PackageRegistration.Id.Equals(Constants.NuGetCommandLinePackageId, StringComparison.OrdinalIgnoreCase) && package.IsLatestStable) { // If we're pushing a new stable version of NuGet.CommandLine, update the extracted executable. nugetExeDownloaderSvc.UpdateExecutable(nugetPackage); } TempData["Message"] = string.Format( "You have successfully created '{0}' version '{1}'. The package is now under review by the moderators and will show up once approved.", package.PackageRegistration.Id, package.Version); return(RedirectToRoute( RouteName.DisplayPackage, new { package.PackageRegistration.Id, package.Version })); }
[ValidateInput(false)] // Security note: Disabling ASP.Net input validation which does things like disallow angle brackets in submissions. See http://go.microsoft.com/fwlink/?LinkID=212874 public virtual async Task <ActionResult> VerifyPackage(VerifyPackageRequest formData) { var currentUser = GetCurrentUser(); Package package; using (Stream uploadFile = await _uploadFileService.GetUploadFileAsync(currentUser.Key)) { if (uploadFile == null) { TempData["Message"] = "Your attempt to verify the package submission failed, because we could not find the uploaded package file. Please try again."; return(new RedirectResult(Url.UploadPackage())); } INupkg nugetPackage = await SafeCreatePackage(currentUser, uploadFile); if (nugetPackage == null) { // Send the user back return(new RedirectResult(Url.UploadPackage())); } Debug.Assert(nugetPackage != null); // Rule out problem scenario with multiple tabs - verification request (possibly with edits) was submitted by user // viewing a different package to what was actually most recently uploaded if (!(String.IsNullOrEmpty(formData.Id) || String.IsNullOrEmpty(formData.Version))) { if (!(String.Equals(nugetPackage.Metadata.Id, formData.Id, StringComparison.OrdinalIgnoreCase) && String.Equals(nugetPackage.Metadata.Version.ToNormalizedString(), formData.Version, StringComparison.OrdinalIgnoreCase))) { TempData["Message"] = "Your attempt to verify the package submission failed, because the package file appears to have changed. Please try again."; return(new RedirectResult(Url.VerifyPackage())); } } bool pendEdit = false; if (formData.Edit != null) { pendEdit = pendEdit || formData.Edit.RequiresLicenseAcceptance != nugetPackage.Metadata.RequireLicenseAcceptance; pendEdit = pendEdit || IsDifferent(formData.Edit.IconUrl, nugetPackage.Metadata.IconUrl.ToEncodedUrlStringOrNull()); pendEdit = pendEdit || IsDifferent(formData.Edit.ProjectUrl, nugetPackage.Metadata.ProjectUrl.ToEncodedUrlStringOrNull()); pendEdit = pendEdit || IsDifferent(formData.Edit.Authors, nugetPackage.Metadata.Authors.Flatten()); pendEdit = pendEdit || IsDifferent(formData.Edit.Copyright, nugetPackage.Metadata.Copyright); pendEdit = pendEdit || IsDifferent(formData.Edit.Description, nugetPackage.Metadata.Description); pendEdit = pendEdit || IsDifferent(formData.Edit.ReleaseNotes, nugetPackage.Metadata.ReleaseNotes); pendEdit = pendEdit || IsDifferent(formData.Edit.Summary, nugetPackage.Metadata.Summary); pendEdit = pendEdit || IsDifferent(formData.Edit.Tags, nugetPackage.Metadata.Tags); pendEdit = pendEdit || IsDifferent(formData.Edit.VersionTitle, nugetPackage.Metadata.Title); } // update relevant database tables package = _packageService.CreatePackage(nugetPackage, currentUser, commitChanges: false); Debug.Assert(package.PackageRegistration != null); _packageService.PublishPackage(package, commitChanges: false); if (pendEdit) { // Add the edit request to a queue where it will be processed in the background. _editPackageService.StartEditPackageRequest(package, formData.Edit, currentUser); } if (!formData.Listed) { _packageService.MarkPackageUnlisted(package, commitChanges: false); } _autoCuratedPackageCmd.Execute(package, nugetPackage, commitChanges: false); // save package to blob storage uploadFile.Position = 0; await _packageFileService.SavePackageFileAsync(package, uploadFile); // commit all changes to database as an atomic transaction _entitiesContext.SaveChanges(); // tell Lucene to update index for the new package _indexingService.UpdateIndex(); } // delete the uploaded binary in the Uploads container await _uploadFileService.DeleteUploadFileAsync(currentUser.Key); TempData["Message"] = String.Format( CultureInfo.CurrentCulture, Strings.SuccessfullyUploadedPackage, package.PackageRegistration.Id, package.Version); return(RedirectToRoute(RouteName.DisplayPackage, new { package.PackageRegistration.Id, package.Version })); }