Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v16: Start removing scope references #18074

Merged
merged 6 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<NeutralLanguage>en-US</NeutralLanguage>
<Nullable>enable</Nullable>
<WarningsAsErrors>nullable</WarningsAsErrors>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<ImplicitUsings>enable</ImplicitUsings>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<WarnOnPackingNonPackableProject>false</WarnOnPackingNonPackableProject>
Expand All @@ -40,7 +40,7 @@
<!-- Package Validation -->
<PropertyGroup>
<GenerateCompatibilitySuppressionFile>false</GenerateCompatibilitySuppressionFile>
<EnablePackageValidation>true</EnablePackageValidation>
<EnablePackageValidation>false</EnablePackageValidation>
<PackageValidationBaselineVersion>15.0.0</PackageValidationBaselineVersion>
<EnableStrictModeForCompatibleFrameworksInPackage>true</EnableStrictModeForCompatibleFrameworksInPackage>
<EnableStrictModeForCompatibleTfms>true</EnableStrictModeForCompatibleTfms>
Expand Down
29 changes: 4 additions & 25 deletions src/Umbraco.Infrastructure/Examine/ContentValueSetValidator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Globalization;

Check notice on line 1 in src/Umbraco.Infrastructure/Examine/ContentValueSetValidator.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (v16/dev)

✅ No longer an issue: Code Duplication

The module no longer contains too many functions with similar structure

Check notice on line 1 in src/Umbraco.Infrastructure/Examine/ContentValueSetValidator.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (v16/dev)

✅ No longer an issue: Overall Code Complexity

The mean cyclomatic complexity in this module is no longer above the threshold

Check notice on line 1 in src/Umbraco.Infrastructure/Examine/ContentValueSetValidator.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (v16/dev)

✅ No longer an issue: Primitive Obsession

The ratio of primivite types in function arguments is no longer above the threshold
using Examine;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Scoping;
Expand All @@ -15,20 +15,19 @@
private const string PathKey = "path";
private static readonly IEnumerable<string> ValidCategories = new[] { IndexTypes.Content, IndexTypes.Media };
private readonly IPublicAccessService? _publicAccessService;
private readonly IScopeProvider? _scopeProvider;
private readonly Scoping.IScopeProvider? _scopeProvider;

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

[Obsolete("Use the overload accepting includeFields and excludeFields instead. This overload will be removed in Umbraco 14.")]
public ContentValueSetValidator(
bool publishedValuesOnly,
bool supportProtectedContent,
IPublicAccessService? publicAccessService,
IScopeProvider? scopeProvider,
Scoping.IScopeProvider? scopeProvider,
int? parentId,
IEnumerable<string>? includeItemTypes,
IEnumerable<string>? excludeItemTypes)
Expand All @@ -40,27 +39,7 @@
_publicAccessService = publicAccessService;
_scopeProvider = scopeProvider;
}

Check notice on line 42 in src/Umbraco.Infrastructure/Examine/ContentValueSetValidator.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (v16/dev)

✅ No longer an issue: Constructor Over-Injection

ContentValueSetValidator is no longer above the threshold for number of arguments. This constructor has too many arguments, indicating an object with low cohesion or missing function argument abstraction. Avoid adding more arguments.
[Obsolete("This constructor is obsolete, the IScopeProvider will change to Infrastructure.Scoping.ScopeProvider instead, this will be removed in Umbraco 14.")]
public ContentValueSetValidator(
bool publishedValuesOnly,
bool supportProtectedContent,
IPublicAccessService? publicAccessService,
IScopeProvider? scopeProvider,
int? parentId = null,
IEnumerable<string>? includeItemTypes = null,
IEnumerable<string>? excludeItemTypes = null,
IEnumerable<string>? includeFields = null,
IEnumerable<string>? excludeFields = null)
: base(includeItemTypes, excludeItemTypes, includeFields, excludeFields)
{
PublishedValuesOnly = publishedValuesOnly;
SupportProtectedContent = supportProtectedContent;
ParentId = parentId;
_publicAccessService = publicAccessService;
_scopeProvider = scopeProvider;
}

protected override IEnumerable<string> ValidIndexCategories => ValidCategories;

public bool PublishedValuesOnly { get; }
Expand Down
6 changes: 3 additions & 3 deletions src/Umbraco.Infrastructure/Examine/UmbracoIndexConfig.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Examine;
using Umbraco.Cms.Core.Scoping;
using Umbraco.Cms.Core.Services;
using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider;

namespace Umbraco.Cms.Infrastructure.Examine;

Expand All @@ -17,10 +17,10 @@ public UmbracoIndexConfig(IPublicAccessService publicAccessService, IScopeProvid
protected IScopeProvider ScopeProvider { get; }

public IContentValueSetValidator GetContentValueSetValidator() =>
new ContentValueSetValidator(false, true, PublicAccessService, ScopeProvider);
new ContentValueSetValidator(false, true, PublicAccessService, ScopeProvider, null, null, null);

public IContentValueSetValidator GetPublishedContentValueSetValidator() =>
new ContentValueSetValidator(true, false, PublicAccessService, ScopeProvider);
new ContentValueSetValidator(true, false, PublicAccessService, ScopeProvider, null, null, null);

/// <summary>
/// Returns the <see cref="IValueSetValidator" /> for the member indexer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Umbraco.Cms.Infrastructure.Persistence;
using Umbraco.Cms.Tests.Integration.Testing;
using Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services;
using IScopeProvider = Umbraco.Cms.Infrastructure.Scoping.IScopeProvider;

namespace Umbraco.Cms.Tests.Integration.Umbraco.Examine.Lucene.UmbracoExamine;

Expand Down Expand Up @@ -113,7 +114,9 @@ protected IDisposable GetSynchronousContentIndex(
false,
publicAccessServiceMock.Object,
scopeProviderMock.Object,
parentId);
parentId,
null,
null);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
// Copyright (c) Umbraco.
// See LICENSE for more details.

using System.Collections.Generic;
using System.Linq;
using Examine;
using Moq;
using NUnit.Framework;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Scoping;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Infrastructure.Examine;
using Umbraco.Cms.Infrastructure.Scoping;

namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Infrastructure.Examine;

Expand All @@ -24,7 +22,10 @@ public void Invalid_Category()
false,
true,
Mock.Of<IPublicAccessService>(),
Mock.Of<IScopeProvider>());
Mock.Of<IScopeProvider>(),
null,
null,
null);

var result =
validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,555" }));
Expand All @@ -48,7 +49,10 @@ public void Must_Have_Path()
false,
true,
Mock.Of<IPublicAccessService>(),
Mock.Of<IScopeProvider>());
Mock.Of<IScopeProvider>(),
null,
null,
null);

var result = validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world" }));
Assert.AreEqual(ValueSetValidationStatus.Failed, result.Status);
Expand All @@ -68,7 +72,9 @@ public void Parent_Id()
true,
Mock.Of<IPublicAccessService>(),
Mock.Of<IScopeProvider>(),
555);
555,
null,
null);

var result =
validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,555" }));
Expand Down Expand Up @@ -170,7 +176,9 @@ public void Inclusion_Type_List()
true,
Mock.Of<IPublicAccessService>(),
Mock.Of<IScopeProvider>(),
includeItemTypes: new List<string> { "include-content" });
null,
new List<string> { "include-content" },
null);

var result = validator.Validate(ValueSet.FromObject(
"555",
Expand Down Expand Up @@ -201,7 +209,9 @@ public void Exclusion_Type_List()
true,
Mock.Of<IPublicAccessService>(),
Mock.Of<IScopeProvider>(),
excludeItemTypes: new List<string> { "exclude-content" });
null,
null,
new List<string> { "exclude-content" });

var result = validator.Validate(ValueSet.FromObject(
"555",
Expand Down Expand Up @@ -232,8 +242,9 @@ public void Inclusion_Exclusion_Type_List()
true,
Mock.Of<IPublicAccessService>(),
Mock.Of<IScopeProvider>(),
includeItemTypes: new List<string> { "include-content", "exclude-content" },
excludeItemTypes: new List<string> { "exclude-content" });
null,
new List<string> { "include-content", "exclude-content" },
new List<string> { "exclude-content" });

var result = validator.Validate(ValueSet.FromObject(
"555",
Expand Down Expand Up @@ -270,7 +281,10 @@ public void Recycle_Bin_Content()
true,
false,
Mock.Of<IPublicAccessService>(),
Mock.Of<IScopeProvider>());
Mock.Of<IScopeProvider>(),
null,
null,
null);

var result =
validator.Validate(ValueSet.FromObject(
Expand Down Expand Up @@ -310,7 +324,10 @@ public void Recycle_Bin_Media()
true,
false,
Mock.Of<IPublicAccessService>(),
Mock.Of<IScopeProvider>());
Mock.Of<IScopeProvider>(),
null,
null,
null);

var result =
validator.Validate(ValueSet.FromObject(
Expand All @@ -337,7 +354,10 @@ public void Published_Only()
true,
true,
Mock.Of<IPublicAccessService>(),
Mock.Of<IScopeProvider>());
Mock.Of<IScopeProvider>(),
null,
null,
null);

var result =
validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,555" }));
Expand Down Expand Up @@ -373,7 +393,10 @@ public void Published_Only_With_Variants()
true,
true,
Mock.Of<IPublicAccessService>(),
Mock.Of<IScopeProvider>());
Mock.Of<IScopeProvider>(),
null,
null,
null);

var result = validator.Validate(new ValueSet(
"555",
Expand Down Expand Up @@ -443,7 +466,10 @@ public void Non_Protected()
false,
false,
publicAccessService.Object,
Mock.Of<IScopeProvider>());
Mock.Of<IScopeProvider>(),
null,
null,
null);

var result =
validator.Validate(ValueSet.FromObject("555", IndexTypes.Content, new { hello = "world", path = "-1,555" }));
Expand Down
Loading