Merge branch 'v8/8.17' into v9/feature/merge_v8.17-rc

This commit is contained in:
Ronald Barendse
2021-09-07 12:10:58 +02:00
335 changed files with 9119 additions and 2275 deletions

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using NPoco;
@@ -255,12 +255,12 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
if (contentType is IMemberType memberType)
{
// ensure that the group exists (ok if it already exists)
memberType.AddPropertyGroup(Cms.Core.Constants.Conventions.Member.StandardPropertiesGroupName);
memberType.AddPropertyGroup(Cms.Core.Constants.Conventions.Member.StandardPropertiesGroupName, Cms.Core.Constants.Conventions.Member.StandardPropertiesGroupAlias);
// ensure that property types exist (ok if they already exist)
foreach (var (alias, propertyType) in builtinProperties)
{
var added = memberType.AddPropertyType(propertyType, Cms.Core.Constants.Conventions.Member.StandardPropertiesGroupName);
var added = memberType.AddPropertyType(propertyType, Cms.Core.Constants.Conventions.Member.StandardPropertiesGroupAlias, Cms.Core.Constants.Conventions.Member.StandardPropertiesGroupName);
if (added)
{
@@ -278,9 +278,11 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
return new PropertyGroup(new PropertyTypeCollection(isPublishing))
{
Id = dto.Id,
Key = dto.UniqueId,
Type = (PropertyGroupType)dto.Type,
Name = dto.Text,
SortOrder = dto.SortOrder,
Key = dto.UniqueId
Alias = dto.Alias,
SortOrder = dto.SortOrder
};
}

View File

@@ -203,7 +203,6 @@ AND umbracoNode.nodeObjectType = @objectType",
});
}
//Insert Tabs
foreach (var propertyGroup in entity.PropertyGroups)
{
@@ -393,7 +392,7 @@ AND umbracoNode.id <> @id",
// see http://issues.umbraco.org/issue/U4-8663
orphanPropertyTypeIds = Database.Fetch<PropertyTypeDto>("WHERE propertyTypeGroupId IN (@ids)", new { ids = groupsToDelete })
.Select(x => x.Id).ToList();
Database.Update<PropertyTypeDto>("SET propertyTypeGroupId=NULL WHERE propertyTypeGroupId IN (@ids)", new { ids = groupsToDelete });
Database.Update<PropertyTypeDto>("SET propertyTypeGroupId = NULL WHERE propertyTypeGroupId IN (@ids)", new { ids = groupsToDelete });
// now we can delete the tabs
Database.Delete<PropertyTypeGroupDto>("WHERE id IN (@ids)", new { ids = groupsToDelete });
@@ -1384,9 +1383,9 @@ WHERE {Cms.Core.Constants.DatabaseSchema.Tables.Content}.nodeId IN (@ids) AND cm
"DELETE FROM cmsContentTypeAllowedContentType WHERE AllowedId = @id",
"DELETE FROM cmsContentType2ContentType WHERE parentContentTypeId = @id",
"DELETE FROM cmsContentType2ContentType WHERE childContentTypeId = @id",
"DELETE FROM " + Cms.Core.Constants.DatabaseSchema.Tables.PropertyData + " WHERE propertyTypeId IN (SELECT id FROM cmsPropertyType WHERE contentTypeId = @id)",
"DELETE FROM cmsPropertyType WHERE contentTypeId = @id",
"DELETE FROM cmsPropertyTypeGroup WHERE contenttypeNodeId = @id",
"DELETE FROM " + Constants.DatabaseSchema.Tables.PropertyData + " WHERE propertyTypeId IN (SELECT id FROM cmsPropertyType WHERE contentTypeId = @id)",
"DELETE FROM " + Constants.DatabaseSchema.Tables.PropertyType + " WHERE contentTypeId = @id",
"DELETE FROM " + Constants.DatabaseSchema.Tables.PropertyTypeGroup + " WHERE contenttypeNodeId = @id"
};
return list;
}

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.Logging;
@@ -146,11 +146,11 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
}
//By Convention we add 9 standard PropertyTypes to an Umbraco MemberType
entity.AddPropertyGroup(Cms.Core.Constants.Conventions.Member.StandardPropertiesGroupName);
entity.AddPropertyGroup(Cms.Core.Constants.Conventions.Member.StandardPropertiesGroupName, Cms.Core.Constants.Conventions.Member.StandardPropertiesGroupAlias);
var standardPropertyTypes = ConventionsHelper.GetStandardPropertyTypeStubs(_shortStringHelper);
foreach (var standardPropertyType in standardPropertyTypes)
{
entity.AddPropertyType(standardPropertyType.Value, Cms.Core.Constants.Conventions.Member.StandardPropertiesGroupName);
entity.AddPropertyType(standardPropertyType.Value, Cms.Core.Constants.Conventions.Member.StandardPropertiesGroupAlias, Cms.Core.Constants.Conventions.Member.StandardPropertiesGroupName);
}
EnsureExplicitDataTypeForBuiltInProperties(entity);

View File

@@ -39,22 +39,22 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
sql
.OrderBy<UserDto>(x => x.Id)
.OrderBy<NodeDto>(dto => dto.NodeId);
return AmbientScope.Database.Fetch<dynamic>(sql).Select(x => new Notification(x.nodeId, x.userId, x.action, objectType));
return AmbientScope.Database.Fetch<UserNotificationDto>(sql).Select(x => new Notification(x.NodeId, x.UserId, x.Action, objectType));
}
public IEnumerable<Notification> GetUserNotifications(IUser user)
{
var sql = AmbientScope.SqlContext.Sql()
.Select("DISTINCT umbracoNode.id, umbracoUser2NodeNotify.userId, umbracoNode.nodeObjectType, umbracoUser2NodeNotify.action")
.Select("DISTINCT umbracoNode.id AS nodeId, umbracoUser2NodeNotify.userId, umbracoNode.nodeObjectType, umbracoUser2NodeNotify.action")
.From<User2NodeNotifyDto>()
.InnerJoin<NodeDto>()
.On<User2NodeNotifyDto, NodeDto>(dto => dto.NodeId, dto => dto.NodeId)
.Where<User2NodeNotifyDto>(dto => dto.UserId == (int)user.Id)
.OrderBy<NodeDto>(dto => dto.NodeId);
var dtos = AmbientScope.Database.Fetch<dynamic>(sql);
var dtos = AmbientScope.Database.Fetch<UserNotificationDto>(sql);
//need to map the results
return dtos.Select(d => new Notification(d.id, d.userId, d.action, d.nodeObjectType)).ToList();
return dtos.Select(d => new Notification(d.NodeId, d.UserId, d.Action, d.NodeObjectType)).ToList();
}
public IEnumerable<Notification> SetNotifications(IUser user, IEntity entity, string[] actions)
@@ -66,16 +66,16 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
public IEnumerable<Notification> GetEntityNotifications(IEntity entity)
{
var sql = AmbientScope.SqlContext.Sql()
.Select("DISTINCT umbracoNode.id, umbracoUser2NodeNotify.userId, umbracoNode.nodeObjectType, umbracoUser2NodeNotify.action")
.Select("DISTINCT umbracoNode.id as nodeId, umbracoUser2NodeNotify.userId, umbracoNode.nodeObjectType, umbracoUser2NodeNotify.action")
.From<User2NodeNotifyDto>()
.InnerJoin<NodeDto>()
.On<User2NodeNotifyDto, NodeDto>(dto => dto.NodeId, dto => dto.NodeId)
.Where<User2NodeNotifyDto>(dto => dto.NodeId == entity.Id)
.OrderBy<NodeDto>(dto => dto.NodeId);
var dtos = AmbientScope.Database.Fetch<dynamic>(sql);
var dtos = AmbientScope.Database.Fetch<UserNotificationDto>(sql);
//need to map the results
return dtos.Select(d => new Notification(d.id, d.userId, d.action, d.nodeObjectType)).ToList();
return dtos.Select(d => new Notification(d.NodeId, d.UserId, d.Action, d.NodeObjectType)).ToList();
}
public int DeleteNotifications(IEntity entity)

View File

@@ -311,13 +311,14 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
.Where("umbracoNode." + SqlContext.SqlSyntax.GetQuotedColumnName("id") + " IN (@parentIds) OR umbracoNode.parentID IN (@childIds)",
new {parentIds = templates.Select(x => x.NodeDto.ParentId), childIds = templates.Select(x => x.NodeId)});
IEnumerable<EntitySlim> childIds = Database.Fetch<dynamic>(childIdsSql)
var childIds = Database.Fetch<AxisDefintionDto>(childIdsSql)
.Select(x => new EntitySlim
{
Id = x.nodeId,
ParentId = x.parentID,
Name = x.alias
Id = x.NodeId,
ParentId = x.ParentId,
Name = x.Alias
});
return childIds;
}

View File

@@ -15,6 +15,7 @@ using Umbraco.Cms.Core.Persistence.Querying;
using Umbraco.Cms.Core.Persistence.Repositories;
using Umbraco.Cms.Core.Scoping;
using Umbraco.Cms.Core.Serialization;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Infrastructure.Persistence.Dtos;
using Umbraco.Cms.Infrastructure.Persistence.Factories;
using Umbraco.Cms.Infrastructure.Persistence.Mappers;
@@ -32,19 +33,26 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
private readonly GlobalSettings _globalSettings;
private readonly UserPasswordConfigurationSettings _passwordConfiguration;
private readonly IJsonSerializer _jsonSerializer;
private readonly IRuntimeState _runtimeState;
private string _passwordConfigJson;
private bool _passwordConfigInitialized;
/// <summary>
/// Constructor
/// Initializes a new instance of the <see cref="UserRepository" /> class.
/// </summary>
/// <param name="scopeAccessor"></param>
/// <param name="appCaches"></param>
/// <param name="logger"></param>
/// <param name="mapperCollection">
/// A dictionary specifying the configuration for user passwords. If this is null then no password configuration will be persisted or read.
/// </param>
/// <param name="globalSettings"></param>
/// <param name="scopeAccessor">The scope accessor.</param>
/// <param name="appCaches">The application caches.</param>
/// <param name="logger">The logger.</param>
/// <param name="mapperCollection">A dictionary specifying the configuration for user passwords. If this is null then no password configuration will be persisted or read.</param>
/// <param name="globalSettings">The global settings.</param>
/// <param name="passwordConfiguration">The password configuration.</param>
/// <param name="jsonSerializer">The JSON serializer.</param>
/// <param name="runtimeState">State of the runtime.</param>
/// <exception cref="System.ArgumentNullException">mapperCollection
/// or
/// globalSettings
/// or
/// passwordConfiguration</exception>
public UserRepository(
IScopeAccessor scopeAccessor,
AppCaches appCaches,
@@ -52,13 +60,15 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
IMapperCollection mapperCollection,
IOptions<GlobalSettings> globalSettings,
IOptions<UserPasswordConfigurationSettings> passwordConfiguration,
IJsonSerializer jsonSerializer)
IJsonSerializer jsonSerializer,
IRuntimeState runtimeState)
: base(scopeAccessor, appCaches, logger)
{
_mapperCollection = mapperCollection ?? throw new ArgumentNullException(nameof(mapperCollection));
_globalSettings = globalSettings.Value ?? throw new ArgumentNullException(nameof(globalSettings));
_passwordConfiguration = passwordConfiguration.Value ?? throw new ArgumentNullException(nameof(passwordConfiguration));
_jsonSerializer = jsonSerializer;
_runtimeState = runtimeState;
}
/// <summary>
@@ -91,9 +101,21 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
// This will never resolve to a user, yet this is asked
// for all of the time (especially in cases of members).
// Don't issue a SQL call for this, we know it will not exist.
if (id == default || id < -1)
if (_runtimeState.Level == RuntimeLevel.Upgrade)
{
return null;
// when upgrading people might come from version 7 where user 0 was the default,
// only in upgrade mode do we want to fetch the user of Id 0
if (id < -1)
{
return null;
}
}
else
{
if (id == default || id < -1)
{
return null;
}
}
var sql = SqlContext.Sql()
@@ -154,30 +176,22 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
public IDictionary<UserState, int> GetUserStates()
{
var sql = @"SELECT '1CountOfAll' AS colName, COUNT(id) AS num FROM umbracoUser
// These keys in this query map to the `Umbraco.Core.Models.Membership.UserState` enum
var sql = @"SELECT -1 AS [Key], COUNT(id) AS [Value] FROM umbracoUser
UNION
SELECT '2CountOfActive' AS colName, COUNT(id) AS num FROM umbracoUser WHERE userDisabled = 0 AND userNoConsole = 0 AND lastLoginDate IS NOT NULL
SELECT 0 AS [Key], COUNT(id) AS [Value] FROM umbracoUser WHERE userDisabled = 0 AND userNoConsole = 0 AND lastLoginDate IS NOT NULL
UNION
SELECT '3CountOfDisabled' AS colName, COUNT(id) AS num FROM umbracoUser WHERE userDisabled = 1
SELECT 1 AS [Key], COUNT(id) AS [Value] FROM umbracoUser WHERE userDisabled = 1
UNION
SELECT '4CountOfLockedOut' AS colName, COUNT(id) AS num FROM umbracoUser WHERE userNoConsole = 1
SELECT 2 AS [Key], COUNT(id) AS [Value] FROM umbracoUser WHERE userNoConsole = 1
UNION
SELECT '5CountOfInvited' AS colName, COUNT(id) AS num FROM umbracoUser WHERE lastLoginDate IS NULL AND userDisabled = 1 AND invitedDate IS NOT NULL
SELECT 3 AS [Key], COUNT(id) AS [Value] FROM umbracoUser WHERE lastLoginDate IS NULL AND userDisabled = 1 AND invitedDate IS NOT NULL
UNION
SELECT '6CountOfDisabled' AS colName, COUNT(id) AS num FROM umbracoUser WHERE userDisabled = 0 AND userNoConsole = 0 AND lastLoginDate IS NULL
ORDER BY colName";
SELECT 4 AS [Key], COUNT(id) AS [Value] FROM umbracoUser WHERE userDisabled = 0 AND userNoConsole = 0 AND lastLoginDate IS NULL";
var result = Database.Fetch<dynamic>(sql);
var result = Database.Dictionary<int, int>(sql);
return new Dictionary<UserState, int>
{
{UserState.All, (int) result[0].num},
{UserState.Active, (int) result[1].num},
{UserState.Disabled, (int) result[2].num},
{UserState.LockedOut, (int) result[3].num},
{UserState.Invited, (int) result[4].num},
{UserState.Inactive, (int) result[5].num}
};
return result.ToDictionary(x => (UserState)x.Key, x => x.Value);
}
public Guid CreateLoginSession(int userId, string requestingIpAddress, bool cleanStaleSessions = true)