-
Notifications
You must be signed in to change notification settings - Fork 643
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4456 from NuGet/dev
[ReleasePrep][2017.07.24]RI of dev into master
- Loading branch information
Showing
37 changed files
with
690 additions
and
84 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
src/NuGetGallery.Core/Cookies/CookieComplianceServiceBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
32
src/NuGetGallery.Core/Cookies/NullCookieComplianceService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.