Skip to content

Commit 7f061bd

Browse files
authored
Merge pull request #11570 from umbraco/v9/feature/merge_v9_contrib_03-11-2021
V9: Merge `v9/contrib` 03-11-2021
2 parents be65f12 + 6760465 commit 7f061bd

File tree

83 files changed

+1392
-502
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+1392
-502
lines changed

.github/CONTRIBUTING.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ Great question! The short version goes like this:
7272

7373
![Clone the fork](img/clonefork.png)
7474

75-
* **Switch to the correct branch** - switch to the `v8/contrib` branch
75+
* **Switch to the correct branch** - switch to the `v9/contrib` branch
7676
* **Build** - build your fork of Umbraco locally as described in [building Umbraco from source code](BUILD.md)
7777
* **Change** - make your changes, experiment, have fun, explore and learn, and don't be afraid. We welcome all contributions and will [happily give feedback](#questions)
78-
* **Commit** - done? Yay! 🎉 **Important:** create a new branch now and name it after the issue you're fixing, we usually follow the format: `temp-12345`. This means it's a temporary branch for the particular issue you're working on, in this case `12345`. When you have a branch, commit your changes. Don't commit to `v8/contrib`, create a new branch first.
78+
* **Commit** - done? Yay! 🎉 **Important:** create a new branch now and name it after the issue you're fixing, we usually follow the format: `temp-12345`. This means it's a temporary branch for the particular issue you're working on, in this case `12345`. When you have a branch, commit your changes. Don't commit to `v9/contrib`, create a new branch first.
7979
* **Push** - great, now you can push the changes up to your fork on GitHub
8080
* **Create pull request** - exciting! You're ready to show us your changes (or not quite ready, you just need some feedback to progress - you can now make use of GitHub's draft pull request status, detailed [here](https://github.blog/2019-02-14-introducing-draft-pull-requests/)). GitHub has picked up on the new branch you've pushed and will offer to create a Pull Request. Click that green button and away you go.
8181

@@ -173,7 +173,7 @@ To find the general areas for something you're looking to fix or improve, have a
173173

174174
### Which branch should I target for my contributions?
175175

176-
We like to use [Gitflow as much as possible](https://jeffkreeftmeijer.com/git-flow/), but don't worry if you are not familiar with it. The most important thing you need to know is that when you fork the Umbraco repository, the default branch is set to something, usually `v8/contrib`. If you are working on v8, this is the branch you should be targetting. For v7 contributions, please target 'v7/dev'.
176+
We like to use [Gitflow as much as possible](https://jeffkreeftmeijer.com/git-flow/), but don't worry if you are not familiar with it. The most important thing you need to know is that when you fork the Umbraco repository, the default branch is set to something, usually `v9/contrib`. If you are working on v9, this is the branch you should be targetting. For v8 contributions, please target 'v8/contrib'
177177

178178
Please note: we are no longer accepting features for v7 but will continue to merge bug fixes as and when they arise.
179179

@@ -199,10 +199,10 @@ Then when you want to get the changes from the main repository:
199199

200200
```
201201
git fetch upstream
202-
git rebase upstream/v8/contrib
202+
git rebase upstream/v9/contrib
203203
```
204204

205-
In this command we're syncing with the `v8/contrib` branch, but you can of course choose another one if needed.
205+
In this command we're syncing with the `v9/contrib` branch, but you can of course choose another one if needed.
206206

207207
(More info on how this works: [http://robots.thoughtbot.com/post/5133345960/keeping-a-git-fork-updated](http://robots.thoughtbot.com/post/5133345960/keeping-a-git-fork-updated))
208208

.vscode/launch.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"args": [],
1515
"cwd": "${workspaceFolder}/src/Umbraco.Web.UI",
1616
"stopAtEntry": false,
17+
"requireExactSource": false,
1718
// Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
1819
"serverReadyAction": {
1920
"action": "openExternally",

NuGet.Config

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/Umbraco.Core/HealthChecks/Checks/Security/BaseHttpHeaderCheck.cs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Umbraco.
1+
// Copyright (c) Umbraco.
22
// See LICENSE for more details.
33

44
using System;
@@ -20,39 +20,45 @@ namespace Umbraco.Cms.Core.HealthChecks.Checks.Security
2020
public abstract class BaseHttpHeaderCheck : HealthCheck
2121
{
2222
private readonly IHostingEnvironment _hostingEnvironment;
23+
private readonly ILocalizedTextService _textService;
2324
private readonly string _header;
24-
private readonly string _value;
2525
private readonly string _localizedTextPrefix;
2626
private readonly bool _metaTagOptionAvailable;
2727
private static HttpClient s_httpClient;
2828

29+
[Obsolete("Use ctor without value.")]
30+
protected BaseHttpHeaderCheck(
31+
IHostingEnvironment hostingEnvironment,
32+
ILocalizedTextService textService,
33+
string header,
34+
string value,
35+
string localizedTextPrefix,
36+
bool metaTagOptionAvailable) :this(hostingEnvironment, textService, header, localizedTextPrefix, metaTagOptionAvailable)
37+
{
38+
39+
}
40+
41+
[Obsolete("Save ILocalizedTextService in a field on the super class instead of using this")]
42+
protected ILocalizedTextService LocalizedTextService => _textService;
2943
/// <summary>
3044
/// Initializes a new instance of the <see cref="BaseHttpHeaderCheck"/> class.
3145
/// </summary>
3246
protected BaseHttpHeaderCheck(
3347
IHostingEnvironment hostingEnvironment,
3448
ILocalizedTextService textService,
3549
string header,
36-
string value,
3750
string localizedTextPrefix,
3851
bool metaTagOptionAvailable)
3952
{
40-
LocalizedTextService = textService ?? throw new ArgumentNullException(nameof(textService));
53+
_textService = textService ?? throw new ArgumentNullException(nameof(textService));
4154
_hostingEnvironment = hostingEnvironment;
4255
_header = header;
43-
_value = value;
4456
_localizedTextPrefix = localizedTextPrefix;
4557
_metaTagOptionAvailable = metaTagOptionAvailable;
4658
}
4759

4860
private static HttpClient HttpClient => s_httpClient ??= new HttpClient();
4961

50-
51-
/// <summary>
52-
/// Gets the localized text service.
53-
/// </summary>
54-
protected ILocalizedTextService LocalizedTextService { get; }
55-
5662
/// <summary>
5763
/// Gets a link to an external read more page.
5864
/// </summary>
@@ -95,12 +101,12 @@ protected async Task<HealthCheckStatus> CheckForHeader()
95101
}
96102

97103
message = success
98-
? LocalizedTextService.Localize($"healthcheck", $"{_localizedTextPrefix}CheckHeaderFound")
99-
: LocalizedTextService.Localize($"healthcheck", $"{_localizedTextPrefix}CheckHeaderNotFound");
104+
? _textService.Localize($"healthcheck", $"{_localizedTextPrefix}CheckHeaderFound")
105+
: _textService.Localize($"healthcheck", $"{_localizedTextPrefix}CheckHeaderNotFound");
100106
}
101107
catch (Exception ex)
102108
{
103-
message = LocalizedTextService.Localize("healthcheck","healthCheckInvalidUrl", new[] { url.ToString(), ex.Message });
109+
message = _textService.Localize("healthcheck","healthCheckInvalidUrl", new[] { url.ToString(), ex.Message });
104110
}
105111

106112
return

src/Umbraco.Core/HealthChecks/Checks/Security/ClickJackingCheck.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Umbraco.
1+
// Copyright (c) Umbraco.
22
// See LICENSE for more details.
33

44
using Umbraco.Cms.Core.Hosting;
@@ -20,7 +20,7 @@ public class ClickJackingCheck : BaseHttpHeaderCheck
2020
/// Initializes a new instance of the <see cref="ClickJackingCheck"/> class.
2121
/// </summary>
2222
public ClickJackingCheck(IHostingEnvironment hostingEnvironment, ILocalizedTextService textService)
23-
: base(hostingEnvironment, textService, "X-Frame-Options", "sameorigin", "clickJacking", true)
23+
: base(hostingEnvironment, textService, "X-Frame-Options", "clickJacking", true)
2424
{
2525
}
2626

src/Umbraco.Core/HealthChecks/Checks/Security/ExcessiveHeadersCheck.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Umbraco.
1+
// Copyright (c) Umbraco.
22
// See LICENSE for more details.
33

44
using System;
@@ -53,7 +53,7 @@ private async Task<HealthCheckStatus> CheckForHeaders()
5353
{
5454
string message;
5555
var success = false;
56-
var url = _hostingEnvironment.ApplicationMainUrl.GetLeftPart(UriPartial.Authority);;
56+
var url = _hostingEnvironment.ApplicationMainUrl.GetLeftPart(UriPartial.Authority);
5757

5858
// Access the site home page and check for the headers
5959
var request = new HttpRequestMessage(HttpMethod.Head, url);
@@ -65,7 +65,7 @@ private async Task<HealthCheckStatus> CheckForHeaders()
6565
var headersToCheckFor = new List<string> {"Server", "X-Powered-By", "X-AspNet-Version", "X-AspNetMvc-Version" };
6666

6767
// Ignore if server header is present and it's set to cloudflare
68-
if (allHeaders.InvariantContains("Server") && response.Headers.TryGetValues("Server", out var serverHeaders) && serverHeaders.ToString().InvariantEquals("cloudflare"))
68+
if (allHeaders.InvariantContains("Server") && response.Headers.TryGetValues("Server", out var serverHeaders) && serverHeaders.FirstOrDefault().InvariantEquals("cloudflare"))
6969
{
7070
headersToCheckFor.Remove("Server");
7171
}

src/Umbraco.Core/HealthChecks/Checks/Security/HstsCheck.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Umbraco.
1+
// Copyright (c) Umbraco.
22
// See LICENSE for more details.
33

44
using Umbraco.Cms.Core.Hosting;
@@ -27,7 +27,7 @@ public class HstsCheck : BaseHttpHeaderCheck
2727
/// but then you should include subdomains and I wouldn't suggest to do that for Umbraco-sites.
2828
/// </remarks>
2929
public HstsCheck(IHostingEnvironment hostingEnvironment, ILocalizedTextService textService)
30-
: base(hostingEnvironment, textService, "Strict-Transport-Security", "max-age=10886400", "hSTS", true)
30+
: base(hostingEnvironment, textService, "Strict-Transport-Security", "hSTS", true)
3131
{
3232
}
3333

src/Umbraco.Core/HealthChecks/Checks/Security/NoSniffCheck.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Umbraco.
1+
// Copyright (c) Umbraco.
22
// See LICENSE for more details.
33

44
using Umbraco.Cms.Core.Hosting;
@@ -20,7 +20,7 @@ public class NoSniffCheck : BaseHttpHeaderCheck
2020
/// Initializes a new instance of the <see cref="NoSniffCheck"/> class.
2121
/// </summary>
2222
public NoSniffCheck(IHostingEnvironment hostingEnvironment, ILocalizedTextService textService)
23-
: base(hostingEnvironment, textService, "X-Content-Type-Options", "nosniff", "noSniff", false)
23+
: base(hostingEnvironment, textService, "X-Content-Type-Options", "noSniff", false)
2424
{
2525
}
2626

src/Umbraco.Core/HealthChecks/Checks/Security/XssProtectionCheck.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Umbraco.
1+
// Copyright (c) Umbraco.
22
// See LICENSE for more details.
33

44
using Umbraco.Cms.Core.Hosting;
@@ -27,7 +27,7 @@ public class XssProtectionCheck : BaseHttpHeaderCheck
2727
/// but then you should include subdomains and I wouldn't suggest to do that for Umbraco-sites.
2828
/// </remarks>
2929
public XssProtectionCheck(IHostingEnvironment hostingEnvironment, ILocalizedTextService textService)
30-
: base(hostingEnvironment, textService, "X-XSS-Protection", "1; mode=block", "xssProtection", true)
30+
: base(hostingEnvironment, textService, "X-XSS-Protection", "xssProtection", true)
3131
{
3232
}
3333

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using System.Text;
2+
using Umbraco.Extensions;
3+
4+
namespace Umbraco.Cms.Core.IO
5+
{
6+
public class DefaultViewContentProvider : IDefaultViewContentProvider
7+
{
8+
public string GetDefaultFileContent(string layoutPageAlias = null, string modelClassName = null, string modelNamespace = null, string modelNamespaceAlias = null)
9+
{
10+
var content = new StringBuilder();
11+
12+
if (string.IsNullOrWhiteSpace(modelNamespaceAlias))
13+
modelNamespaceAlias = "ContentModels";
14+
15+
// either
16+
// @inherits Umbraco.Web.Mvc.UmbracoViewPage
17+
// @inherits Umbraco.Web.Mvc.UmbracoViewPage<ModelClass>
18+
content.AppendLine("@using Umbraco.Cms.Web.Common.PublishedModels;");
19+
content.Append("@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage");
20+
if (modelClassName.IsNullOrWhiteSpace() == false)
21+
{
22+
content.Append("<");
23+
if (modelNamespace.IsNullOrWhiteSpace() == false)
24+
{
25+
content.Append(modelNamespaceAlias);
26+
content.Append(".");
27+
}
28+
content.Append(modelClassName);
29+
content.Append(">");
30+
}
31+
content.Append("\r\n");
32+
33+
// if required, add
34+
// @using ContentModels = ModelNamespace;
35+
if (modelClassName.IsNullOrWhiteSpace() == false && modelNamespace.IsNullOrWhiteSpace() == false)
36+
{
37+
content.Append("@using ");
38+
content.Append(modelNamespaceAlias);
39+
content.Append(" = ");
40+
content.Append(modelNamespace);
41+
content.Append(";\r\n");
42+
}
43+
44+
// either
45+
// Layout = null;
46+
// Layout = "layoutPage.cshtml";
47+
content.Append("@{\r\n\tLayout = ");
48+
if (layoutPageAlias.IsNullOrWhiteSpace())
49+
{
50+
content.Append("null");
51+
}
52+
else
53+
{
54+
content.Append("\"");
55+
content.Append(layoutPageAlias);
56+
content.Append(".cshtml\"");
57+
}
58+
content.Append(";\r\n}");
59+
return content.ToString();
60+
}
61+
}
62+
}

0 commit comments

Comments
 (0)