From 3ba79c9846c7f6bda527291dd51b065c4dc72bac Mon Sep 17 00:00:00 2001 From: Ibrahim Nada Date: Fri, 11 Oct 2024 15:34:19 +0300 Subject: [PATCH 1/4] fix inline params --- .../Builders/Extensions/BuilderExtensions.cs | 3 +-- .../Umbraco.Tests.Common/Builders/MediaTypeEditingBuilder.cs | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/Umbraco.Tests.Common/Builders/Extensions/BuilderExtensions.cs b/tests/Umbraco.Tests.Common/Builders/Extensions/BuilderExtensions.cs index a44c5c7ba9ae..aeec0ccb290e 100644 --- a/tests/Umbraco.Tests.Common/Builders/Extensions/BuilderExtensions.cs +++ b/tests/Umbraco.Tests.Common/Builders/Extensions/BuilderExtensions.cs @@ -232,8 +232,7 @@ public static T WithSupportsPublishing(this T builder, bool supportsPublishin return builder; } - public static T WithPropertyValues(this T builder, object propertyValues, string? culture = null, - string? segment = null) + public static T WithPropertyValues(this T builder, object propertyValues, string? culture = null,string? segment = null) where T : IWithPropertyValues { builder.PropertyValues = propertyValues; diff --git a/tests/Umbraco.Tests.Common/Builders/MediaTypeEditingBuilder.cs b/tests/Umbraco.Tests.Common/Builders/MediaTypeEditingBuilder.cs index c1291d64db2f..164778d5fbc4 100644 --- a/tests/Umbraco.Tests.Common/Builders/MediaTypeEditingBuilder.cs +++ b/tests/Umbraco.Tests.Common/Builders/MediaTypeEditingBuilder.cs @@ -1,4 +1,4 @@ -using Umbraco.Cms.Core; +using Umbraco.Cms.Core; using Umbraco.Cms.Core.Models.ContentTypeEditing; using Umbraco.Cms.Tests.Common.Builders.Extensions; using Umbraco.Cms.Tests.Common.Builders.Interfaces; @@ -41,8 +41,7 @@ public static MediaTypeCreateModel CreateBasicMediaType(string alias = "umbImage .Build(); } - public static MediaTypeCreateModel CreateBasicFolderMediaType(string alias = "basicFolder", - string name = "BasicFolder") + public static MediaTypeCreateModel CreateBasicFolderMediaType(string alias = "basicFolder",string name = "BasicFolder") { var builder = new MediaTypeEditingBuilder(); return (MediaTypeCreateModel)builder From 7fc92d6bd0b1b29807db964a0a5f1f6288149b1e Mon Sep 17 00:00:00 2001 From: Ibrahim Nada Date: Fri, 11 Oct 2024 15:34:35 +0300 Subject: [PATCH 2/4] adding user valdiation into Audit Save Method --- .../Repositories/Implement/AuditRepository.cs | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/AuditRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/AuditRepository.cs index 9f0df27897e9..81d012d1163f 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/AuditRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/AuditRepository.cs @@ -14,9 +14,11 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement; internal class AuditRepository : EntityRepositoryBase, IAuditRepository { + private readonly ICollection _cachedUserIds; public AuditRepository(IScopeAccessor scopeAccessor, ILogger logger) : base(scopeAccessor, AppCaches.NoCache, logger) { + _cachedUserIds = new List(); } public IEnumerable Get(AuditType type, IQuery query) @@ -69,10 +71,7 @@ public IEnumerable GetPagedResultsByQuery( AuditType[]? auditTypeFilter, IQuery? customFilter) { - if (auditTypeFilter == null) - { - auditTypeFilter = Array.Empty(); - } + auditTypeFilter ??= Array.Empty(); Sql sql = GetBaseQuery(false); @@ -187,4 +186,17 @@ protected override Sql GetBaseQuery(bool isCount) protected override string GetBaseWhereClause() => "id = @id"; protected override IEnumerable GetDeleteClauses() => throw new NotImplementedException(); + + public override void Save(IAuditItem entity) + { + if (!_cachedUserIds.Any(x => x == entity.UserId)) + { + + int? userIdQueryResult = Database.FirstOrDefault( + " select id from umbracoUser where " + GetBaseWhereClause(), + new { id = entity.UserId }) ?? throw new InvalidOperationException("The user id does not exist"); + _cachedUserIds.Add(userIdQueryResult.Value); + } + base.Save(entity); + } } From e29282a6e17ae6f5ff00b2de1d95fc43aa203798 Mon Sep 17 00:00:00 2001 From: Ibrahim Nada Date: Fri, 11 Oct 2024 16:05:30 +0300 Subject: [PATCH 3/4] change to [umbracoUser] --- .../Persistence/Repositories/Implement/AuditRepository.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/AuditRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/AuditRepository.cs index 81d012d1163f..4e7736e180cd 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/AuditRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/AuditRepository.cs @@ -193,7 +193,7 @@ public override void Save(IAuditItem entity) { int? userIdQueryResult = Database.FirstOrDefault( - " select id from umbracoUser where " + GetBaseWhereClause(), + " select id from [umbracoUser] where " + GetBaseWhereClause(), new { id = entity.UserId }) ?? throw new InvalidOperationException("The user id does not exist"); _cachedUserIds.Add(userIdQueryResult.Value); } From af3d13a8de3754fba4a336be614988368f6f0cf4 Mon Sep 17 00:00:00 2001 From: Ibrahim Nada Date: Fri, 11 Oct 2024 16:08:07 +0300 Subject: [PATCH 4/4] remove for sql providers --- .../Persistence/Repositories/Implement/AuditRepository.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/AuditRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/AuditRepository.cs index 4e7736e180cd..81d012d1163f 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/AuditRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/AuditRepository.cs @@ -193,7 +193,7 @@ public override void Save(IAuditItem entity) { int? userIdQueryResult = Database.FirstOrDefault( - " select id from [umbracoUser] where " + GetBaseWhereClause(), + " select id from umbracoUser where " + GetBaseWhereClause(), new { id = entity.UserId }) ?? throw new InvalidOperationException("The user id does not exist"); _cachedUserIds.Add(userIdQueryResult.Value); }