Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
maartenba committed Apr 22, 2016
2 parents 16cdd74 + a7ea7a9 commit d9c53a7
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 54 deletions.
Binary file removed src/NuGetGallery/Content/clippy.swf
Binary file not shown.
8 changes: 8 additions & 0 deletions src/NuGetGallery/Controllers/ODataV2CuratedFeedController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ public async Task<IHttpActionResult> Get(ODataQueryOptions<V2FeedPackage> option
[CacheOutput(ServerTimeSpan = NuGetODataConfig.GetByIdAndVersionCacheTimeInSeconds, Private = true, ClientTimeSpan = NuGetODataConfig.GetByIdAndVersionCacheTimeInSeconds)]
public async Task<IHttpActionResult> FindPackagesById(ODataQueryOptions<V2FeedPackage> options, string curatedFeedName, [FromODataUri]string id)
{
if (string.IsNullOrEmpty(curatedFeedName) || string.IsNullOrEmpty(id))
{
var emptyResult = Enumerable.Empty<Package>().AsQueryable()
.ToV2FeedPackageQuery(GetSiteRoot(), _configurationService.Features.FriendlyLicenses);

return QueryResult(options, emptyResult, MaxPageSize);
}

return await GetCore(options, curatedFeedName, id, version: null, return404NotFoundWhenNoResults: false);
}

Expand Down
8 changes: 8 additions & 0 deletions src/NuGetGallery/Controllers/ODataV2FeedController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ public async Task<IHttpActionResult> Get(ODataQueryOptions<V2FeedPackage> option
[CacheOutput(ServerTimeSpan = NuGetODataConfig.GetByIdAndVersionCacheTimeInSeconds, Private = true, ClientTimeSpan = NuGetODataConfig.GetByIdAndVersionCacheTimeInSeconds)]
public async Task<IHttpActionResult> FindPackagesById(ODataQueryOptions<V2FeedPackage> options, [FromODataUri]string id)
{
if (string.IsNullOrEmpty(id))
{
var emptyResult = Enumerable.Empty<Package>().AsQueryable()
.ToV2FeedPackageQuery(GetSiteRoot(), _configurationService.Features.FriendlyLicenses);

return QueryResult(options, emptyResult, MaxPageSize);
}

return await GetCore(options, id, version: null, return404NotFoundWhenNoResults: false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public partial class AddIndexForPackageDeletes : DbMigration
{
public override void Up()
{
Sql("IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'nci_wi_Packages_Deleted' AND object_id = OBJECT_ID('Packages')) CREATE NONCLUSTERED INDEX [nci_wi_Packages_Deleted] ON [dbo].[Packages] ([Deleted], [Listed]) INCLUDE ([Description], [FlattenedDependencies], [IsPrerelease], [PackageRegistrationKey], [Tags], [Version]) WITH (ONLINE = ON)");
Sql("IF NOT EXISTS(SELECT * FROM sys.indexes WHERE name = 'nci_wi_Packages_Deleted' AND object_id = OBJECT_ID('Packages')) CREATE NONCLUSTERED INDEX [nci_wi_Packages_Deleted] ON [dbo].[Packages] ([Deleted], [Listed]) INCLUDE ([Description], [FlattenedDependencies], [IsPrerelease], [PackageRegistrationKey], [Tags], [Version])");
}

public override void Down()
Expand Down
1 change: 0 additions & 1 deletion src/NuGetGallery/NuGetGallery.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -1590,7 +1590,6 @@
<Content Include="Areas\Admin\DynamicData\PageTemplates\List.aspx" />
<Content Include="Areas\Admin\DynamicData\Site.css" />
<Content Include="Public\clientaccesspolicy.xml" />
<Content Include="Content\clippy.swf" />
<Content Include="Content\font-awesome\font-awesome-ie7.min.css" />
<Content Include="Content\font-awesome\font-awesome.css" />
<Content Include="Content\font-awesome\font-awesome.min.css" />
Expand Down
99 changes: 47 additions & 52 deletions src/NuGetGallery/Views/Users/Account.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -421,31 +421,7 @@
else
{
<span id="key">@apiKey.Value</span>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
width="110"
height="14"
class="s-reqflash"
aria-hidden="true"
role="presentation">
<param name="movie" value="@Url.Content("~/Content/clippy.swf")">
<param name="allowScriptAccess" value="always" />
<param name="quality" value="high" />
<param name="scale" value="noscale" />
<param name="FlashVars" value="text=@apiKey.Value">
<param name="bgcolor" value="#eff7fa">
<embed src="@Url.Content("~/Content/clippy.swf")"
width="110"
height="14"
aria-hidden="true"
role="presentation"
name="clippy"
quality="high"
allowscriptaccess="always"
type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer"
flashvars="text=@apiKey.Value"
bgcolor="#eff7fa" />
</object>
<button class="btn btn-small" title="Copy to clipboard" type="button" onclick="copyToClipboard('@apiKey.Value', this)"><i class="icon-copy"></i></button>
}
</text>,
actions: @<text>
Expand Down Expand Up @@ -495,35 +471,54 @@
<div id="account-apikeysample">
<div>
nuget.exe setApiKey @apiKey.Value
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
width="110"
height="14"
class="s-reqflash"
aria-hidden="true"
role="presentation">
<param name="movie" value="@Url.Content("~/Content/clippy.swf")">
<param name="allowScriptAccess" value="always" />
<param name="quality" value="high" />
<param name="scale" value="noscale" />
<param name="FlashVars" value="text=nuget.exe setApiKey @apiKey.Value">
<param name="bgcolor" value="#202020">
<embed src="@Url.Content("~/Content/clippy.swf")"
width="110"
height="14"
aria-hidden="true"
role="presentation"
name="clippy"
quality="high"
allowscriptaccess="always"
type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer"
flashvars="text=nuget.exe setApiKey @apiKey.Value"
bgcolor="#202020" />
</object>
<button class="btn btn-small" title="Copy to clipboard" type="button" onclick="copyToClipboard('nuget.exe setApiKey @apiKey.Value', this)"><i class="icon-copy"></i></button>
</div>
<div>nuget.exe push MyPackage.1.0.nupkg</div>
</div>
</p>
}
</text>)
</ul>
</text>)
</ul>


@section bottomScripts {
<script>
function detectIE() {
var ua = window.navigator.userAgent;

var msie = ua.indexOf('MSIE ');
if (msie > 0) {
// IE 10 or older => return version number
return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
}

var trident = ua.indexOf('Trident/');
if (trident > 0) {
// IE 11 => return version number
var rv = ua.indexOf('rv:');
return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
}

// other browser or edge
return false;
}

// use execCommand copy and a dynamic textarea as source for the text
// requestingElement is used as the parent for the dynamic textarea, otherwise
// MS Edge might "jump" to the newly created item if you append it as child of the body
function copyToClipboard(text, requestingElement) {
if (detectIE()) {
window.clipboardData.setData('Text', text);
} else {
var textField = document.createElement('textarea');
textField.setAttribute('style', 'display: hidden');
textField.innerText = text;
requestingElement.appendChild(textField);
textField.select();
document.execCommand('copy');
textField.remove();
}

}
</script>
}
26 changes: 26 additions & 0 deletions tests/NuGetGallery.Facts/Services/FeedServiceFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,32 @@ public async Task V2FeedFindPackagesByIdReturnsEmptyCollectionWhenNoPackages()
Assert.Equal(0, result.Count());
}

[Fact]
public async Task V2FeedFindPackagesByIdDoesNotHitBackendWhenIdIsEmpty()
{
// Arrange
var repo = new Mock<IEntityRepository<Package>>(MockBehavior.Loose);

var configuration = new Mock<ConfigurationService>(MockBehavior.Strict);
configuration.Setup(c => c.GetSiteRoot(It.IsAny<bool>())).Returns("https://localhost:8081/");
configuration.Setup(c => c.Features).Returns(new FeatureConfiguration() { FriendlyLicenses = true });

var v2Service = new TestableV2Feed(repo.Object, configuration.Object, null);
v2Service.Request = new HttpRequestMessage(HttpMethod.Get, "https://localhost:8081/");

// Act
var result = (await v2Service.FindPackagesById(
new ODataQueryOptions<V2FeedPackage>(new ODataQueryContext(NuGetODataV2FeedConfig.GetEdmModel(), typeof(V2FeedPackage)), v2Service.Request),
""))
.ExpectQueryResult<V2FeedPackage>()
.GetInnerResult()
.ExpectOkNegotiatedContentResult<IQueryable<V2FeedPackage>>();

// Assert
repo.Verify(r => r.GetAll(), Times.Never);
Assert.Equal(0, result.Count());
}

[Fact]
public async Task V2FeedFindPackagesByIdDoesNotReturnDeletedPackages()
{
Expand Down

0 comments on commit d9c53a7

Please sign in to comment.