Merge remote-tracking branch 'origin/v13/dev' into v15/merge-from-13
This commit is contained in:
@@ -70,6 +70,11 @@ public abstract class MigrationExpressionBase : IMigrationExpression
|
||||
}
|
||||
else
|
||||
{
|
||||
if (stmtBuilder.Length > 0)
|
||||
{
|
||||
stmtBuilder.Append(Environment.NewLine);
|
||||
}
|
||||
|
||||
stmtBuilder.Append(line);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,15 @@ public class TextBuilder : Builder
|
||||
/// Outputs an "auto-generated" header to a string builder.
|
||||
/// </summary>
|
||||
/// <param name="sb">The string builder.</param>
|
||||
public static void WriteHeader(StringBuilder sb) => TextHeaderWriter.WriteHeader(sb);
|
||||
[Obsolete("Please use the overload taking all parameters. Scheduled for removal in Umbraco 17.")]
|
||||
public static void WriteHeader(StringBuilder sb) => WriteHeader(sb, true);
|
||||
|
||||
/// <summary>
|
||||
/// Outputs an "auto-generated" header to a string builder.
|
||||
/// </summary>
|
||||
/// <param name="sb">The string builder.</param>
|
||||
/// <param name="includeVersion">Flag indicating whether the tool version number should be included in the output.</param>
|
||||
public static void WriteHeader(StringBuilder sb, bool includeVersion) => TextHeaderWriter.WriteHeader(sb, includeVersion);
|
||||
|
||||
/// <summary>
|
||||
/// Outputs a generated model to a string builder.
|
||||
@@ -60,7 +68,7 @@ public class TextBuilder : Builder
|
||||
/// <param name="typeModel">The model to generate.</param>
|
||||
public void Generate(StringBuilder sb, TypeModel typeModel)
|
||||
{
|
||||
WriteHeader(sb);
|
||||
WriteHeader(sb, Config.IncludeVersionNumberInGeneratedModels);
|
||||
|
||||
foreach (var t in TypesUsing)
|
||||
{
|
||||
@@ -83,7 +91,7 @@ public class TextBuilder : Builder
|
||||
/// <param name="typeModels">The models to generate.</param>
|
||||
public void Generate(StringBuilder sb, IEnumerable<TypeModel> typeModels)
|
||||
{
|
||||
WriteHeader(sb);
|
||||
WriteHeader(sb, Config.IncludeVersionNumberInGeneratedModels);
|
||||
|
||||
foreach (var t in TypesUsing)
|
||||
{
|
||||
|
||||
@@ -8,13 +8,30 @@ internal static class TextHeaderWriter
|
||||
/// Outputs an "auto-generated" header to a string builder.
|
||||
/// </summary>
|
||||
/// <param name="sb">The string builder.</param>
|
||||
public static void WriteHeader(StringBuilder sb)
|
||||
[Obsolete("Please use the overload taking all parameters. Scheduled for removal in Umbraco 17.")]
|
||||
public static void WriteHeader(StringBuilder sb) => WriteHeader(sb, true);
|
||||
|
||||
/// <summary>
|
||||
/// Outputs an "auto-generated" header to a string builder.
|
||||
/// </summary>
|
||||
/// <param name="sb">The string builder.</param>
|
||||
/// <param name="includeVersion">Flag indicating whether the tool version number should be included in the output.</param>
|
||||
public static void WriteHeader(StringBuilder sb, bool includeVersion)
|
||||
{
|
||||
sb.Append("//------------------------------------------------------------------------------\n");
|
||||
sb.Append("// <auto-generated>\n");
|
||||
sb.Append("// This code was generated by a tool.\n");
|
||||
sb.Append("//\n");
|
||||
sb.AppendFormat("// Umbraco.ModelsBuilder.Embedded v{0}\n", ApiVersion.Current.Version);
|
||||
|
||||
if (includeVersion)
|
||||
{
|
||||
sb.AppendFormat("// Umbraco.ModelsBuilder.Embedded v{0}\n", ApiVersion.Current.Version);
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append("// Umbraco.ModelsBuilder.Embedded\n");
|
||||
}
|
||||
|
||||
sb.Append("//\n");
|
||||
sb.Append("// Changes to this file will be lost if the code is regenerated.\n");
|
||||
sb.Append("// </auto-generated>\n");
|
||||
|
||||
@@ -68,7 +68,13 @@ public static class HttpContextExtensions
|
||||
// Otherwise we can't log in as both a member and a backoffice user
|
||||
// For instance if you've enabled basic auth.
|
||||
ClaimsPrincipal? authenticatedPrincipal = result.Principal;
|
||||
IEnumerable<ClaimsIdentity> existingIdentities = httpContext.User.Identities.Where(x => x.IsAuthenticated && x.AuthenticationType != authenticatedPrincipal.Identity.AuthenticationType);
|
||||
|
||||
// Make sure to copy into a list before attempting to update the authenticated principal, so we don't attempt to modify
|
||||
// the collection while iterating it.
|
||||
// See: https://github.com/umbraco/Umbraco-CMS/issues/18509
|
||||
var existingIdentities = httpContext.User.Identities
|
||||
.Where(x => x.IsAuthenticated && x.AuthenticationType != authenticatedPrincipal.Identity.AuthenticationType)
|
||||
.ToList();
|
||||
authenticatedPrincipal.AddIdentities(existingIdentities);
|
||||
|
||||
httpContext.User = authenticatedPrincipal;
|
||||
|
||||
@@ -18,7 +18,6 @@ using Umbraco.Cms.Persistence.SqlServer.Services;
|
||||
using Umbraco.Cms.Tests.Common.TestHelpers;
|
||||
using Umbraco.Cms.Tests.Common.Testing;
|
||||
using Umbraco.Cms.Tests.Integration.Testing;
|
||||
using Umbraco.Extensions;
|
||||
|
||||
namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.SyntaxProvider;
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
// Copyright (c) Umbraco.
|
||||
// See LICENSE for more details.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Cms.Core.Configuration.Models;
|
||||
@@ -118,6 +116,102 @@ namespace Umbraco.Cms.Web.Common.PublishedModels
|
||||
Assert.AreEqual(expected.ClearLf(), gen);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateSimpleType_WithoutVersion()
|
||||
{
|
||||
// Umbraco returns nice, pascal-cased names.
|
||||
var type1 = new TypeModel
|
||||
{
|
||||
Id = 1,
|
||||
Alias = "type1",
|
||||
ClrName = "Type1",
|
||||
Name = "type1Name",
|
||||
ParentId = 0,
|
||||
BaseType = null,
|
||||
ItemType = TypeModel.ItemTypes.Content,
|
||||
};
|
||||
type1.Properties.Add(new PropertyModel
|
||||
{
|
||||
Alias = "prop1",
|
||||
ClrName = "Prop1",
|
||||
Name = "prop1Name",
|
||||
ModelClrType = typeof(string),
|
||||
});
|
||||
|
||||
TypeModel[] types = { type1 };
|
||||
|
||||
var modelsBuilderConfig = new ModelsBuilderSettings { IncludeVersionNumberInGeneratedModels = false };
|
||||
var builder = new TextBuilder(modelsBuilderConfig, types);
|
||||
|
||||
var sb = new StringBuilder();
|
||||
builder.Generate(sb, builder.GetModelsToGenerate().First());
|
||||
var gen = sb.ToString();
|
||||
|
||||
var expected = @"//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
//
|
||||
// Umbraco.ModelsBuilder.Embedded
|
||||
//
|
||||
// Changes to this file will be lost if the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Linq.Expressions;
|
||||
using Umbraco.Cms.Core.Models.PublishedContent;
|
||||
using Umbraco.Cms.Core.PublishedCache;
|
||||
using Umbraco.Cms.Infrastructure.ModelsBuilder;
|
||||
using Umbraco.Cms.Core;
|
||||
using Umbraco.Extensions;
|
||||
|
||||
namespace Umbraco.Cms.Web.Common.PublishedModels
|
||||
{
|
||||
/// <summary>type1Name</summary>
|
||||
[PublishedModel(""type1"")]
|
||||
public partial class Type1 : PublishedContentModel
|
||||
{
|
||||
// helpers
|
||||
#pragma warning disable 0109 // new is redundant
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Umbraco.ModelsBuilder.Embedded"", """")]
|
||||
public new const string ModelTypeAlias = ""type1"";
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Umbraco.ModelsBuilder.Embedded"", """")]
|
||||
public new const PublishedItemType ModelItemType = PublishedItemType.Content;
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Umbraco.ModelsBuilder.Embedded"", """")]
|
||||
[return: global::System.Diagnostics.CodeAnalysis.MaybeNull]
|
||||
public new static IPublishedContentType GetModelContentType(IPublishedSnapshotAccessor publishedSnapshotAccessor)
|
||||
=> PublishedModelUtility.GetModelContentType(publishedSnapshotAccessor, ModelItemType, ModelTypeAlias);
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Umbraco.ModelsBuilder.Embedded"", """")]
|
||||
[return: global::System.Diagnostics.CodeAnalysis.MaybeNull]
|
||||
public static IPublishedPropertyType GetModelPropertyType<TValue>(IPublishedSnapshotAccessor publishedSnapshotAccessor, Expression<Func<Type1, TValue>> selector)
|
||||
=> PublishedModelUtility.GetModelPropertyType(GetModelContentType(publishedSnapshotAccessor), selector);
|
||||
#pragma warning restore 0109
|
||||
|
||||
private IPublishedValueFallback _publishedValueFallback;
|
||||
|
||||
// ctor
|
||||
public Type1(IPublishedContent content, IPublishedValueFallback publishedValueFallback)
|
||||
: base(content, publishedValueFallback)
|
||||
{
|
||||
_publishedValueFallback = publishedValueFallback;
|
||||
}
|
||||
|
||||
// properties
|
||||
|
||||
///<summary>
|
||||
/// prop1Name
|
||||
///</summary>
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Umbraco.ModelsBuilder.Embedded"", """")]
|
||||
[global::System.Diagnostics.CodeAnalysis.MaybeNull]
|
||||
[ImplementPropertyType(""prop1"")]
|
||||
public virtual string Prop1 => this.Value<string>(_publishedValueFallback, ""prop1"");
|
||||
}
|
||||
}
|
||||
";
|
||||
Console.WriteLine(gen);
|
||||
Assert.AreEqual(expected.ClearLf(), gen);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GenerateSimpleType_Ambiguous_Issue()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user