Skip to content

Commit

Permalink
Merge branch 'v8/dev' into v8/contrib
Browse files Browse the repository at this point in the history
  • Loading branch information
nul800sebastiaan committed Mar 1, 2021
2 parents 187db95 + dafca14 commit ece7008
Show file tree
Hide file tree
Showing 12 changed files with 216 additions and 74 deletions.
4 changes: 2 additions & 2 deletions src/SolutionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
[assembly: AssemblyVersion("8.0.0")]

// these are FYI and changed automatically
[assembly: AssemblyFileVersion("8.11.1")]
[assembly: AssemblyInformationalVersion("8.11.1")]
[assembly: AssemblyFileVersion("8.12.0")]
[assembly: AssemblyInformationalVersion("8.12.0-rc")]
6 changes: 2 additions & 4 deletions src/Umbraco.Core/Services/Implement/PublicAccessService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,10 @@ public PublicAccessEntry GetEntryForContent(string contentPath)
//start with the deepest id
ids.Reverse();

using (var scope = ScopeProvider.CreateScope())
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
{
//This will retrieve from cache!
var entries = _publicAccessRepository.GetMany().ToArray();

scope.Complete();
var entries = _publicAccessRepository.GetMany().ToList();
foreach (var id in ids)
{
var found = entries.FirstOrDefault(x => x.ProtectedNodeId == id);
Expand Down
47 changes: 36 additions & 11 deletions src/Umbraco.Examine/ContentValueSetValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
using Examine;
using Examine.LuceneEngine.Providers;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Models;
using Umbraco.Core.Scoping;
using Umbraco.Core.Services;

namespace Umbraco.Examine
Expand All @@ -15,9 +17,9 @@ namespace Umbraco.Examine
public class ContentValueSetValidator : ValueSetValidator, IContentValueSetValidator
{
private readonly IPublicAccessService _publicAccessService;

private readonly IScopeProvider _scopeProvider;
private const string PathKey = "path";
private static readonly IEnumerable<string> ValidCategories = new[] {IndexTypes.Content, IndexTypes.Media};
private static readonly IEnumerable<string> ValidCategories = new[] { IndexTypes.Content, IndexTypes.Media };
protected override IEnumerable<string> ValidIndexCategories => ValidCategories;

public bool PublishedValuesOnly { get; }
Expand Down Expand Up @@ -53,32 +55,55 @@ public bool ValidateRecycleBin(string path, string category)

public bool ValidateProtectedContent(string path, string category)
{
if (category == IndexTypes.Content
&& !SupportProtectedContent
//if the service is null we can't look this up so we'll return false
&& (_publicAccessService == null || _publicAccessService.IsProtected(path)))
if (category == IndexTypes.Content && !SupportProtectedContent)
{
return false;
//if the service is null we can't look this up so we'll return false
if (_publicAccessService == null || _scopeProvider == null)
{
return false;
}

// explicit scope since we may be in a background thread
using (_scopeProvider.CreateScope(autoComplete: true))
{
if (_publicAccessService.IsProtected(path))
{
return false;
}
}
}

return true;
}

// used for tests
public ContentValueSetValidator(bool publishedValuesOnly, int? parentId = null,
IEnumerable<string> includeItemTypes = null, IEnumerable<string> excludeItemTypes = null)
: this(publishedValuesOnly, true, null, parentId, includeItemTypes, excludeItemTypes)
: this(publishedValuesOnly, true, null, null, parentId, includeItemTypes, excludeItemTypes)
{
}

public ContentValueSetValidator(bool publishedValuesOnly, bool supportProtectedContent,
IPublicAccessService publicAccessService, int? parentId = null,
IPublicAccessService publicAccessService,
IScopeProvider scopeProvider,
int? parentId = null,
IEnumerable<string> includeItemTypes = null, IEnumerable<string> excludeItemTypes = null)
: base(includeItemTypes, excludeItemTypes, null, null)
{
PublishedValuesOnly = publishedValuesOnly;
SupportProtectedContent = supportProtectedContent;
ParentId = parentId;
_publicAccessService = publicAccessService;
_scopeProvider = scopeProvider;
}

[Obsolete("Use the ctor with all parameters instead")]
public ContentValueSetValidator(bool publishedValuesOnly, bool supportProtectedContent,
IPublicAccessService publicAccessService, int? parentId = null,
IEnumerable<string> includeItemTypes = null, IEnumerable<string> excludeItemTypes = null)
: this(publishedValuesOnly, supportProtectedContent, publicAccessService, Current.ScopeProvider,
parentId, includeItemTypes, excludeItemTypes)
{
}

public override ValueSetValidationResult Validate(ValueSet valueSet)
Expand All @@ -103,7 +128,7 @@ public override ValueSetValidationResult Validate(ValueSet valueSet)
&& variesByCulture.Count > 0 && variesByCulture[0].Equals("y"))
{
//so this valueset is for a content that varies by culture, now check for non-published cultures and remove those values
foreach(var publishField in valueSet.Values.Where(x => x.Key.StartsWith($"{UmbracoExamineIndex.PublishedFieldName}_")).ToList())
foreach (var publishField in valueSet.Values.Where(x => x.Key.StartsWith($"{UmbracoExamineIndex.PublishedFieldName}_")).ToList())
{
if (publishField.Value.Count <= 0 || !publishField.Value[0].Equals("y"))
{
Expand Down Expand Up @@ -134,7 +159,7 @@ public override ValueSetValidationResult Validate(ValueSet valueSet)
|| !ValidateProtectedContent(path, valueSet.Category))
return ValueSetValidationResult.Filtered;

return isFiltered ? ValueSetValidationResult.Filtered: ValueSetValidationResult.Valid;
return isFiltered ? ValueSetValidationResult.Filtered : ValueSetValidationResult.Valid;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ context('Content', () => {

// Create content with content picker
cy.get('.umb-tree-root-link').rightclick();
cy.get('.-opens-dialog > .umb-action-link').click();
cy.get('[data-element="action-create"]').click();
cy.get('[data-element="action-create-' + pickerDocTypeAlias + '"] > .umb-action-link').click();
// Fill out content
cy.umbracoEditorHeaderName('ContentPickerContent');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Umbraco.Core.Models;
using System;
using System.Linq;
using Umbraco.Core.Scoping;

namespace Umbraco.Tests.UmbracoExamine
{
Expand All @@ -17,10 +18,14 @@ public class UmbracoContentValueSetValidatorTests
[Test]
public void Invalid_Category()
{
var validator = new ContentValueSetValidator(false, true, Mock.Of<IPublicAccessService>());
var validator = new ContentValueSetValidator(
false,
true,
Mock.Of<IPublicAccessService>(),
Mock.Of<IScopeProvider>());

var result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,555" }));
Assert.AreEqual(ValueSetValidationResult.Valid, result);
Assert.AreEqual(ValueSetValidationResult.Valid, result);

result = validator.Validate(ValueSet.FromObject("777", IndexTypes.Media, new { hello = "world", path = "-1,555" }));
Assert.AreEqual(ValueSetValidationResult.Valid, result);
Expand All @@ -33,7 +38,11 @@ public void Invalid_Category()
[Test]
public void Must_Have_Path()
{
var validator = new ContentValueSetValidator(false, true, Mock.Of<IPublicAccessService>());
var validator = new ContentValueSetValidator(
false,
true,
Mock.Of<IPublicAccessService>(),
Mock.Of<IScopeProvider>());

var result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world" }));
Assert.AreEqual(ValueSetValidationResult.Failed, result);
Expand All @@ -45,7 +54,12 @@ public void Must_Have_Path()
[Test]
public void Parent_Id()
{
var validator = new ContentValueSetValidator(false, true, Mock.Of<IPublicAccessService>(), 555);
var validator = new ContentValueSetValidator(
false,
true,
Mock.Of<IPublicAccessService>(),
Mock.Of<IScopeProvider>(),
555);

var result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,555" }));
Assert.AreEqual(ValueSetValidationResult.Filtered, result);
Expand All @@ -63,7 +77,9 @@ public void Parent_Id()
[Test]
public void Inclusion_Field_List()
{
var validator = new ValueSetValidator(null, null,
var validator = new ValueSetValidator(
null,
null,
new[] { "hello", "world" },
null);

Expand All @@ -79,7 +95,9 @@ public void Inclusion_Field_List()
[Test]
public void Exclusion_Field_List()
{
var validator = new ValueSetValidator(null, null,
var validator = new ValueSetValidator(
null,
null,
null,
new[] { "hello", "world" });

Expand All @@ -95,7 +113,9 @@ public void Exclusion_Field_List()
[Test]
public void Inclusion_Exclusion_Field_List()
{
var validator = new ValueSetValidator(null, null,
var validator = new ValueSetValidator(
null,
null,
new[] { "hello", "world" },
new[] { "world" });

Expand All @@ -111,7 +131,11 @@ public void Inclusion_Exclusion_Field_List()
[Test]
public void Inclusion_Type_List()
{
var validator = new ContentValueSetValidator(false, true, Mock.Of<IPublicAccessService>(),
var validator = new ContentValueSetValidator(
false,
true,
Mock.Of<IPublicAccessService>(),
Mock.Of<IScopeProvider>(),
includeItemTypes: new List<string> { "include-content" });

var result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, "test-content", new { hello = "world", path = "-1,555" }));
Expand All @@ -127,7 +151,11 @@ public void Inclusion_Type_List()
[Test]
public void Exclusion_Type_List()
{
var validator = new ContentValueSetValidator(false, true, Mock.Of<IPublicAccessService>(),
var validator = new ContentValueSetValidator(
false,
true,
Mock.Of<IPublicAccessService>(),
Mock.Of<IScopeProvider>(),
excludeItemTypes: new List<string> { "exclude-content" });

var result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, "test-content", new { hello = "world", path = "-1,555" }));
Expand All @@ -143,7 +171,11 @@ public void Exclusion_Type_List()
[Test]
public void Inclusion_Exclusion_Type_List()
{
var validator = new ContentValueSetValidator(false, true, Mock.Of<IPublicAccessService>(),
var validator = new ContentValueSetValidator(
false,
true,
Mock.Of<IPublicAccessService>(),
Mock.Of<IScopeProvider>(),
includeItemTypes: new List<string> { "include-content", "exclude-content" },
excludeItemTypes: new List<string> { "exclude-content" });

Expand All @@ -163,7 +195,11 @@ public void Inclusion_Exclusion_Type_List()
[Test]
public void Recycle_Bin_Content()
{
var validator = new ContentValueSetValidator(true, false, Mock.Of<IPublicAccessService>());
var validator = new ContentValueSetValidator(
true,
false,
Mock.Of<IPublicAccessService>(),
Mock.Of<IScopeProvider>());

var result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,-20,555" }));
Assert.AreEqual(ValueSetValidationResult.Failed, result);
Expand All @@ -187,7 +223,11 @@ public void Recycle_Bin_Content()
[Test]
public void Recycle_Bin_Media()
{
var validator = new ContentValueSetValidator(true, false, Mock.Of<IPublicAccessService>());
var validator = new ContentValueSetValidator(
true,
false,
Mock.Of<IPublicAccessService>(),
Mock.Of<IScopeProvider>());

var result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Media, new { hello = "world", path = "-1,-21,555" }));
Assert.AreEqual(ValueSetValidationResult.Filtered, result);
Expand All @@ -203,7 +243,11 @@ public void Recycle_Bin_Media()
[Test]
public void Published_Only()
{
var validator = new ContentValueSetValidator(true, true, Mock.Of<IPublicAccessService>());
var validator = new ContentValueSetValidator(
true,
true,
Mock.Of<IPublicAccessService>(),
Mock.Of<IScopeProvider>());

var result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,555" }));
Assert.AreEqual(ValueSetValidationResult.Failed, result);
Expand All @@ -230,7 +274,10 @@ public void Published_Only()
[Test]
public void Published_Only_With_Variants()
{
var validator = new ContentValueSetValidator(true, true, Mock.Of<IPublicAccessService>());
var validator = new ContentValueSetValidator(true,
true,
Mock.Of<IPublicAccessService>(),
Mock.Of<IScopeProvider>());

var result = validator.Validate(new ValueSet("555", IndexTypes.Content,
new Dictionary<string, object>
Expand Down Expand Up @@ -288,7 +335,11 @@ public void Non_Protected()
.Returns(Attempt.Succeed(new PublicAccessEntry(Guid.NewGuid(), 555, 444, 333, Enumerable.Empty<PublicAccessRule>())));
publicAccessService.Setup(x => x.IsProtected("-1,777"))
.Returns(Attempt.Fail<PublicAccessEntry>());
var validator = new ContentValueSetValidator(false, false, publicAccessService.Object);
var validator = new ContentValueSetValidator(
false,
false,
publicAccessService.Object,
Mock.Of<IScopeProvider>());

var result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,555" }));
Assert.AreEqual(ValueSetValidationResult.Filtered, result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h5><localize key="create_createUnder">Create an item under</localize> {{current
</button>
</li>
<li data-element="action-documentTypeWithIsElementTypeChecked" class="umb-action">
<button type="button" ng-click="createElement()" class="umb-action-link umb-outline btn-reset" umb-auto-focus>
<button type="button" ng-click="createElement()" class="umb-action-link umb-outline btn-reset">
<i class="large icon icon-science" aria-hidden="true"></i>
<span class="menu-label">
<localize key="create_elementType">Element Type</localize>
Expand Down
4 changes: 2 additions & 2 deletions src/Umbraco.Web.UI/Umbraco.Web.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,9 @@
<WebProjectProperties>
<UseIIS>False</UseIIS>
<AutoAssignPort>True</AutoAssignPort>
<DevelopmentServerPort>8111</DevelopmentServerPort>
<DevelopmentServerPort>8120</DevelopmentServerPort>
<DevelopmentServerVPath>/</DevelopmentServerVPath>
<IISUrl>http://localhost:8111</IISUrl>
<IISUrl>http://localhost:8120</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>False</UseCustomServer>
<CustomServerUrl>
Expand Down
Loading

0 comments on commit ece7008

Please sign in to comment.