Permalink
Browse files

Minor bug fixes:

* Work Item #447: Use Published Date instead of last updated date in the
  package display
* Store null values in the Download stats pag*
* Work Item #465: Allow at most 5 tags per package
  • Loading branch information...
1 parent 342febc commit 89afb3508c3f03a06fb18614b603bc453c4d36ed @pranavkm pranavkm committed with pranavkm Jul 26, 2012
@@ -6,6 +6,7 @@
using Moq;
using NuGet;
using Xunit;
+using Xunit.Extensions;
namespace NuGetGallery
{
@@ -98,6 +99,31 @@ public void WillReadThePropertiesFromTheNuGetPackageWhenCreatingANewPackage()
Assert.Equal("theFirstDependency:[1.0, 2.0):net4000|theSecondDependency:[1.0]:net4000|theThirdDependency::net4000|theFourthDependency:[1.0]:net35", package.FlattenedDependencies);
}
+ [Theory]
+ [InlineData("a b c d e f g hi jk lmn opq rst u vw xy z", "a b c d e f g hi jk lmn")]
+ [InlineData("a b c d ", "a b c d")]
+ public void WillReadAtMost10TagsFromNuGetPackage(string input, string expected)
+ {
+ // Arrange
+ var packageRegistrationRepo = new Mock<IEntityRepository<PackageRegistration>>();
+ var service = CreateService(
+ packageRegistrationRepo: packageRegistrationRepo,
+ setup: mockPackageSvc =>
+ {
+ mockPackageSvc.Setup(x => x.FindPackageRegistrationById(It.IsAny<string>())).Returns((PackageRegistration)null);
+ });
+ var nugetPackage = CreateNuGetPackage(p => p.Setup(s => s.Tags).Returns(input));
+ var currentUser = new User();
+
+ // Act
+ var package = service.CreatePackage(
+ nugetPackage.Object,
+ currentUser);
+
+ // Assert
+ Assert.Equal(expected, package.Tags);
+ }
+
[Fact]
public void WillReadPrereleaseFlagFromNuGetPackage()
{
@@ -1009,7 +1035,7 @@ public void WillIgnoreTheIpAddressForNow()
service.AddDownloadStatistics(package, "::1", "Unit Test");
- packageStatsRepo.Verify(x => x.InsertOnCommit(It.Is<PackageStatistics>(p => p.IPAddress == "unknown")));
+ packageStatsRepo.Verify(x => x.InsertOnCommit(It.Is<PackageStatistics>(p => p.IPAddress == null)));
packageStatsRepo.Verify(x => x.CommitChanges());
}
@@ -11,6 +11,7 @@ namespace NuGetGallery
{
public class PackageService : IPackageService
{
+ private const int MaxTagsToAllow = 10;
private readonly ICryptographyService cryptoSvc;
private readonly IEntityRepository<PackageRegistration> packageRegistrationRepo;
private readonly IEntityRepository<Package> packageRepo;
@@ -213,7 +214,7 @@ public void AddDownloadStatistics(Package package, string userHostAddress, strin
// IMPORTANT: Until we understand privacy implications of storing IP Addresses thoroughly,
// It's better to just not store them. Hence "unknown". - Phil Haack 10/6/2011
- IPAddress = "unknown",
+ IPAddress = null,
UserAgent = userAgent,
Package = package
});
@@ -244,7 +245,7 @@ PackageRegistration CreateOrGetPackageRegistration(User currentUser, IPackage nu
return packageRegistration;
}
- Package CreatePackageFromNuGetPackage(PackageRegistration packageRegistration, IPackage nugetPackage)
+ internal Package CreatePackageFromNuGetPackage(PackageRegistration packageRegistration, IPackage nugetPackage)
{
var package = packageRegistration.Packages
.Where(pv => pv.Version == nugetPackage.Version.ToString())
@@ -282,7 +283,11 @@ Package CreatePackageFromNuGetPackage(PackageRegistration packageRegistration, I
if (nugetPackage.Summary != null)
package.Summary = nugetPackage.Summary;
if (nugetPackage.Tags != null)
- package.Tags = nugetPackage.Tags;
+ {
+ // To prevent tag abuse, we'll allow a limited number of tags.
+ var tags = nugetPackage.Tags.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
+ package.Tags = String.Join(" ", tags.Take(MaxTagsToAllow));
+ }
if (nugetPackage.Title != null)
package.Title = nugetPackage.Title;
@@ -16,7 +16,7 @@ public PackageViewModel(Package package)
LicenseUrl = package.LicenseUrl;
LatestVersion = package.IsLatest;
LatestStableVersion = package.IsLatestStable;
- LastUpdated = package.LastUpdated;
+ PublishedDate = package.Published;
Listed = package.Listed;
DownloadCount = package.DownloadCount;
Prerelease = package.IsPrerelease;
@@ -42,7 +42,7 @@ public string Title
public string IconUrl { get; set; }
public string ProjectUrl { get; set; }
public string LicenseUrl { get; set; }
- public DateTime LastUpdated { get; set; }
+ public DateTime PublishedDate { get; set; }
public bool LatestVersion { get; set; }
public bool LatestStableVersion { get; set; }
public bool Prerelease { get; set; }
@@ -18,9 +18,9 @@
Downloads of v @Model.Version</p>
</div>
<div class="stat">
- <p class="stat-number">@Model.LastUpdated.ToShortDateString()</p>
+ <p class="stat-number">@Model.PublishedDate.ToShortDateString()</p>
<p class="stat-label">
- Last update</p>
+ Published date</p>
</div>
</div>
<nav>
@@ -168,7 +168,7 @@
</td>
<td>@packageVersion.DownloadCount
</td>
- <td>@packageVersion.LastUpdated.ToString("D")
+ <td>@packageVersion.PublishedDate.ToString("D")
</td>
@if (Model.IsOwner(User))
{

2 comments on commit 89afb35

@maartenba

Will these changes be reflected in the public API? If yes, this sounds like a breaking change for many NuGet consumers out there.

@pranavkm
Member

No, we'll continue pushing both those dates in our feed. That said this value is modified by the gallery when any metadata for a package changes. For instance, when you pushed a newer version of the package, the last updated value for both the current latest and the newly uploaded packages is set to the current time. https://github.com/NuGet/NuGetGallery/blob/89afb3508c3f03a06fb18614b603bc453c4d36ed/Website/Services/PackageService.cs#L376-380

This change makes this a little less confusing - See #447

Please sign in to comment.