private ActionResult CreatePackageInternal(string apiKey) { Guid parsedApiKey; if (!Guid.TryParse(apiKey, out parsedApiKey)) { return(new HttpStatusCodeWithBodyResult( HttpStatusCode.BadRequest, String.Format(CultureInfo.CurrentCulture, Strings.InvalidApiKey, apiKey))); } var user = _userSvc.FindByApiKey(parsedApiKey); if (user == null) { return(new HttpStatusCodeWithBodyResult( HttpStatusCode.Forbidden, String.Format(CultureInfo.CurrentCulture, Strings.ApiKeyNotAuthorized, "push"))); } var packageToPush = ReadPackageFromRequest(); // Ensure that the user can push packages for this partialId. var packageRegistration = _packageSvc.FindPackageRegistrationById(packageToPush.Id); if (packageRegistration != null) { if (!packageRegistration.IsOwner(user)) { return(new HttpStatusCodeWithBodyResult( HttpStatusCode.Forbidden, String.Format(CultureInfo.CurrentCulture, Strings.ApiKeyNotAuthorized, "push"))); } // Check if a particular Id-Version combination already exists. We eventually need to remove this check. bool packageExists = packageRegistration.Packages.Any(p => p.Version.Equals(packageToPush.Version.ToString(), StringComparison.OrdinalIgnoreCase)); if (packageExists) { return(new HttpStatusCodeWithBodyResult( HttpStatusCode.Conflict, String.Format(CultureInfo.CurrentCulture, Strings.PackageExistsAndCannotBeModified, packageToPush.Id, packageToPush.Version))); } } var package = _packageSvc.CreatePackage(packageToPush, user); if (packageToPush.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(packageToPush); } return(new HttpStatusCodeResult(201)); }
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 })); }