Skip to content

Commit

Permalink
Merge pull request #4456 from NuGet/dev
Browse files Browse the repository at this point in the history
[ReleasePrep][2017.07.24]RI of dev into master
  • Loading branch information
loic-sharma authored Jul 24, 2017
2 parents c60708d + 94d86ae commit c08fbca
Show file tree
Hide file tree
Showing 37 changed files with 690 additions and 84 deletions.
51 changes: 51 additions & 0 deletions src/NuGetGallery.Core/Cookies/CookieComplianceServiceBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// 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.Threading;
using System.Threading.Tasks;
using System.Web;
using NuGetGallery.Diagnostics;

namespace NuGetGallery.Cookies
{
/// <summary>
/// Base cookie compliance service with access to some Gallery resources.
/// </summary>
public abstract class CookieComplianceServiceBase : ICookieComplianceService
{
private string _domain;
private IDiagnosticsSource _diagnostics;

protected string Domain => _domain ?? throw new InvalidOperationException(CoreStrings.CookieComplianceServiceNotInitialized);

protected IDiagnosticsSource Diagnostics => _diagnostics ?? throw new InvalidOperationException(CoreStrings.CookieComplianceServiceNotInitialized);

public virtual Task InitializeAsync(string domain, IDiagnosticsService diagnostics, CancellationToken cancellationToken)
{
// Service should only be initialized once.
if (_domain != null)
{
throw new InvalidOperationException(CoreStrings.CookieComplianceServiceAlreadyInitialized);
}

_domain = domain;
_diagnostics = diagnostics.GetSource(GetType().Name);

return Task.Delay(0);
}

public abstract bool CanWriteNonEssentialCookies(HttpRequestBase request);

public abstract bool NeedsConsentForNonEssentialCookies(HttpRequestBase request);

public abstract CookieConsentMessage GetConsentMessage(HttpRequestBase request, string locale = null);

public abstract string GetConsentMarkup(HttpRequestBase request, string locale = null);

public abstract IEnumerable<string> GetConsentScripts(HttpRequestBase request, string locale = null);

public abstract IEnumerable<string> GetConsentStylesheets(HttpRequestBase request, string locale = null);
}
}
18 changes: 18 additions & 0 deletions src/NuGetGallery.Core/Cookies/CookieConsentMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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.

namespace NuGetGallery.Cookies
{
public class CookieConsentMessage
{
public string Message { get; set; }

public string MoreInfoUrl { get; set; }

public string MoreInfoText { get; set; }

public string MoreInfoAriaLabel { get; set; }

public string[] Javascripts { get; set; }
}
}
51 changes: 51 additions & 0 deletions src/NuGetGallery.Core/Cookies/ICookieComplianceService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// 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.Collections.Generic;
using System.Web;

namespace NuGetGallery.Cookies
{
/// <summary>
/// Cookie compliance service, used to comply with EU privacy laws.
/// </summary>
public interface ICookieComplianceService
{
/// <summary>
/// Determine if consent is still needed for writing non-essential cookies.
/// </summary>
/// <returns>True if consent is needed, false if consent is already provided or not required.</returns>
bool NeedsConsentForNonEssentialCookies(HttpRequestBase request);

/// <summary>
/// Determine if non-essential cookies can be written.
/// </summary>
/// <returns>True if non-essential cookies can be written, false otherwise.</returns>
bool CanWriteNonEssentialCookies(HttpRequestBase request);

/// <summary>
/// Get the cookie consent banner message and resources. This API is an alternative to the default
/// rendering APIs below and can be used to customize the UI. Note that the messaging must remain intact.
/// </summary>
CookieConsentMessage GetConsentMessage(HttpRequestBase request, string locale = null);

#region Default CookieConsent rendering

/// <summary>
/// Get the default HTML markup for the cookie consent banner.
/// </summary>
string GetConsentMarkup(HttpRequestBase request, string locale = null);

/// <summary>
/// Get the default CSS links for the cookie consent banner.
/// </summary>
IEnumerable<string> GetConsentStylesheets(HttpRequestBase request, string locale = null);

/// <summary>
/// Get the default Javascript links for the cookie consent banner.
/// </summary>
IEnumerable<string> GetConsentScripts(HttpRequestBase request, string locale = null);

#endregion
}
}
32 changes: 32 additions & 0 deletions src/NuGetGallery.Core/Cookies/NullCookieComplianceService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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.Collections.Generic;
using System.Web;

namespace NuGetGallery.Cookies
{
/// <summary>
/// Default, no-op instance of the cookie compliance service, used when no shim is registered.
/// </summary>
public class NullCookieComplianceService: CookieComplianceServiceBase
{
private static readonly string[] EmptyStringArray = new string[0];

// Consent is not necessary and cookies can be written.

public override bool NeedsConsentForNonEssentialCookies(HttpRequestBase request) => false;

public override bool CanWriteNonEssentialCookies(HttpRequestBase request) => true;

// No markdown or scripts will be included.

public override CookieConsentMessage GetConsentMessage(HttpRequestBase request, string locale = null) => null;

public override string GetConsentMarkup(HttpRequestBase request, string locale = null) => string.Empty;

public override IEnumerable<string> GetConsentScripts(HttpRequestBase request, string locale = null) => EmptyStringArray;

public override IEnumerable<string> GetConsentStylesheets(HttpRequestBase request, string locale = null) => EmptyStringArray;
}
}
20 changes: 19 additions & 1 deletion src/NuGetGallery.Core/CoreStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/NuGetGallery.Core/CoreStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,10 @@
<data name="Manifest_InvalidDependencyVersion" xml:space="preserve">
<value>The package manifest contains an invalid Dependency Version: '{0}'</value>
</data>
<data name="CookieComplianceServiceNotInitialized" xml:space="preserve">
<value>The cookie compliance service is not initialized.</value>
</data>
<data name="CookieComplianceServiceAlreadyInitialized" xml:space="preserve">
<value>The cookie compliance service is already initialized.</value>
</data>
</root>
14 changes: 14 additions & 0 deletions src/NuGetGallery.Core/Diagnostics/IDiagnosticsService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// 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.

namespace NuGetGallery.Diagnostics
{
public interface IDiagnosticsService
{
/// <summary>
/// Gets an <see cref="IDiagnosticsSource"/> by the specified name.
/// </summary>
/// <param name="name">The name of the source. It's recommended that you use the unqualified type name (i.e. 'UserService').</param>
IDiagnosticsSource GetSource(string name);
}
}
20 changes: 20 additions & 0 deletions src/NuGetGallery.Core/Diagnostics/IDiagnosticsSource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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.Diagnostics;
using System.Runtime.CompilerServices;

namespace NuGetGallery.Diagnostics
{
public interface IDiagnosticsSource
{
void ExceptionEvent(Exception exception);

void TraceEvent(TraceEventType type, int id, string message,
[CallerMemberName] string member = null, [CallerFilePath] string file = null, [CallerLineNumber] int line = 0);

void PerfEvent(string name, TimeSpan time, IEnumerable<KeyValuePair<string, object>> payload);
}
}
11 changes: 11 additions & 0 deletions src/NuGetGallery.Core/Entities/Package.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ public Package()
/// </remarks>
public string ProjectUrl { get; set; }

/// <remarks>
/// Has a max length of 4000. Is not indexed and not used for searches. Db column is nvarchar(max).
/// </remarks>
public string RepositoryUrl { get; set; }

/// <summary>
/// Signifies whether or not ReadMe exists (optimization for pulling from blob storage)
/// </summary>
public bool? HasReadMe { get; set; }

public bool RequiresLicenseAcceptance { get; set; }

/// <remarks>
Expand Down Expand Up @@ -211,6 +221,7 @@ public void ApplyEdit(PackageEdit edit, string hashAlgorithm, string hash, long
IconUrl = edit.IconUrl;
LicenseUrl = edit.LicenseUrl;
ProjectUrl = edit.ProjectUrl;
RepositoryUrl = edit.RepositoryUrl;
ReleaseNotes = edit.ReleaseNotes;
RequiresLicenseAcceptance = edit.RequiresLicenseAcceptance;
Summary = edit.Summary;
Expand Down
5 changes: 5 additions & 0 deletions src/NuGetGallery.Core/Entities/PackageEdit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public class PackageEdit
public string IconUrl { get; set; }
public string LicenseUrl { get; set; }
public string ProjectUrl { get; set; }
public string RepositoryUrl { get; set; }
/// <summary>
/// changed, null (means unchanged), deleted
/// </summary>
public string ReadMeState { get; set; }
public string ReleaseNotes { get; set; }
public bool RequiresLicenseAcceptance { get; set; }
public string Summary { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions src/NuGetGallery.Core/Entities/PackageHistory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public PackageHistory(Package package)
IconUrl = package.IconUrl;
LicenseUrl = package.LicenseUrl;
ProjectUrl = package.ProjectUrl;
RepositoryUrl = package.RepositoryUrl;
ReleaseNotes = package.ReleaseNotes;
RequiresLicenseAcceptance = package.RequiresLicenseAcceptance;
Summary = package.Summary;
Expand Down Expand Up @@ -65,6 +66,7 @@ public PackageHistory(Package package)
public string IconUrl { get; set; }
public string LicenseUrl { get; set; }
public string ProjectUrl { get; set; }
public string RepositoryUrl { get; set; }
public string ReleaseNotes { get; set; }
public bool RequiresLicenseAcceptance { get; set; }
public string Summary { get; set; }
Expand Down
6 changes: 6 additions & 0 deletions src/NuGetGallery.Core/NuGetGallery.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,15 @@
<Compile Include="Auditing\PackageAuditRecord.cs" />
<Compile Include="Auditing\ScopeAuditRecord.cs" />
<Compile Include="Auditing\UserAuditRecord.cs" />
<Compile Include="Cookies\CookieComplianceServiceBase.cs" />
<Compile Include="Cookies\CookieConsentMessage.cs" />
<Compile Include="Cookies\ICookieComplianceService.cs" />
<Compile Include="Cookies\NullCookieComplianceService.cs" />
<Compile Include="CoreConstants.cs" />
<Compile Include="CredentialTypes.cs" />
<Compile Include="Completion.cs" />
<Compile Include="Diagnostics\IDiagnosticsService.cs" />
<Compile Include="Diagnostics\IDiagnosticsSource.cs" />
<Compile Include="DisposableAction.cs" />
<Compile Include="Entities\Credential.cs" />
<Compile Include="Entities\CuratedFeed.cs" />
Expand Down
1 change: 0 additions & 1 deletion src/NuGetGallery.Core/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,3 @@
// AssemblyVersion, AssemblyFileVersion, AssemblyInformationalVersion, AssemblyMetadata (for Branch, CommitId, and BuildDateUtc)

[assembly: AssemblyMetadata("RepositoryUrl", "https://www.github.com/NuGet/NuGetGallery")]

Loading

0 comments on commit c08fbca

Please sign in to comment.