diff --git a/framework/test/Volo.Abp.Auditing.Tests/Volo/Abp/Auditing/JsonAuditSerializer_Test.cs b/framework/test/Volo.Abp.Auditing.Tests/Volo/Abp/Auditing/JsonAuditSerializer_Test.cs index eb9dec3b5e..648325862a 100644 --- a/framework/test/Volo.Abp.Auditing.Tests/Volo/Abp/Auditing/JsonAuditSerializer_Test.cs +++ b/framework/test/Volo.Abp.Auditing.Tests/Volo/Abp/Auditing/JsonAuditSerializer_Test.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Text.Json.Serialization; using Microsoft.Extensions.DependencyInjection; using Shouldly; using Xunit; @@ -58,7 +57,6 @@ public class JsonAuditSerializer_Test : AbpAuditingTestBase [DisableAuditing] public string Password { get; set; } - [JsonIgnore] public string PrivateEmail { get; set; } public DateTime Birthday { get; set; } diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/FeatureDefinitionRecord.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/FeatureDefinitionRecord.cs index 0c181ab632..20ba414b08 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/FeatureDefinitionRecord.cs +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/FeatureDefinitionRecord.cs @@ -7,13 +7,6 @@ namespace Volo.Abp.FeatureManagement; public class FeatureDefinitionRecord : BasicAggregateRoot, IHasExtraProperties { - /* Ignoring Id because it is different whenever we create an instance of - * this class, and we are using Json Serialize, than Hash to understand - * if feature definitions have changed (in StaticFeatureSaver.CalculateHash()). - */ - [JsonIgnore] //TODO: TODO: Use JSON modifier to ignore this property - public override Guid Id { get; protected set; } - public string GroupName { get; set; } public string Name { get; set; } diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/FeatureGroupDefinitionRecord.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/FeatureGroupDefinitionRecord.cs index 677f055f3e..61c7e60473 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/FeatureGroupDefinitionRecord.cs +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/FeatureGroupDefinitionRecord.cs @@ -1,5 +1,4 @@ using System; -using System.Text.Json.Serialization; using Volo.Abp.Data; using Volo.Abp.Domain.Entities; @@ -7,13 +6,6 @@ namespace Volo.Abp.FeatureManagement; public class FeatureGroupDefinitionRecord : BasicAggregateRoot, IHasExtraProperties { - /* Ignoring Id because it is different whenever we create an instance of - * this class, and we are using Json Serialize, than Hash to understand - * if feature definitions have changed (in StaticFeatureSaver.CalculateHash()). - */ - [JsonIgnore] //TODO: TODO: Use JSON modifier to ignore this property - public override Guid Id { get; protected set; } - public string Name { get; set; } public string DisplayName { get; set; } diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/StaticFeatureSaver.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/StaticFeatureSaver.cs index 5b3e581518..129ce0200b 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/StaticFeatureSaver.cs +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.Domain/Volo/Abp/FeatureManagement/StaticFeatureSaver.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.Json; +using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.Options; @@ -10,6 +11,7 @@ using Volo.Abp.Caching; using Volo.Abp.DependencyInjection; using Volo.Abp.DistributedLocking; using Volo.Abp.Features; +using Volo.Abp.Json.SystemTextJson.Modifiers; using Volo.Abp.Threading; using Volo.Abp.Uow; @@ -273,13 +275,25 @@ public class StaticFeatureSaver : IStaticFeatureSaver, ITransientDependency IEnumerable deletedFeatureGroups, IEnumerable deletedFeatures) { + var jsonSerializerOptions = new JsonSerializerOptions + { + TypeInfoResolver = new DefaultJsonTypeInfoResolver + { + Modifiers = + { + new AbpIgnorePropertiesModifiers().CreateModifyAction(x => x.Id), + new AbpIgnorePropertiesModifiers().CreateModifyAction(x => x.Id) + } + } + }; + var stringBuilder = new StringBuilder(); stringBuilder.Append("FeatureGroupRecords:"); - stringBuilder.AppendLine(JsonSerializer.Serialize(featureGroupRecords)); + stringBuilder.AppendLine(JsonSerializer.Serialize(featureGroupRecords, jsonSerializerOptions)); stringBuilder.Append("FeatureRecords:"); - stringBuilder.AppendLine(JsonSerializer.Serialize(featureRecords)); + stringBuilder.AppendLine(JsonSerializer.Serialize(featureRecords, jsonSerializerOptions)); stringBuilder.Append("DeletedFeatureGroups:"); stringBuilder.AppendLine(deletedFeatureGroups.JoinAsString(",")); diff --git a/modules/feature-management/test/Volo.Abp.FeatureManagement.Domain.Tests/Volo/Abp/FeatureManagement/CalculateHash_Tests.cs b/modules/feature-management/test/Volo.Abp.FeatureManagement.Domain.Tests/Volo/Abp/FeatureManagement/CalculateHash_Tests.cs new file mode 100644 index 0000000000..048d9f465e --- /dev/null +++ b/modules/feature-management/test/Volo.Abp.FeatureManagement.Domain.Tests/Volo/Abp/FeatureManagement/CalculateHash_Tests.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Text.Json; +using System.Text.Json.Serialization.Metadata; +using Shouldly; +using Volo.Abp.Json.SystemTextJson.Modifiers; +using Xunit; + +namespace Volo.Abp.FeatureManagement; + +public class CalculateHash_Tests : FeatureManagementDomainTestBase +{ + [Fact] + public void Test() + { + var jsonSerializerOptions = new JsonSerializerOptions + { + TypeInfoResolver = new DefaultJsonTypeInfoResolver + { + Modifiers = + { + new AbpIgnorePropertiesModifiers().CreateModifyAction(x => x.Id), + new AbpIgnorePropertiesModifiers().CreateModifyAction(x => x.Id) + } + } + }; + + var id = Guid.NewGuid(); + var json = JsonSerializer.Serialize(new List() + { + new FeatureGroupDefinitionRecord(id, "Test", "Test") + }, + jsonSerializerOptions); + + json.ShouldNotContain("\"Id\""); + json.ShouldNotContain(id.ToString("D")); + + json = JsonSerializer.Serialize(new List() + { + new FeatureDefinitionRecord(id, "Test", "Test", "Test", "Test", "Test", "Test", true, true,"Test", "Test") + }, + jsonSerializerOptions); + + json.ShouldNotContain("\"Id\""); + json.ShouldNotContain(id.ToString("D")); + } +} diff --git a/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/PermissionDefinitionRecord.cs b/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/PermissionDefinitionRecord.cs index 2ba9ffa26a..7473eb2589 100644 --- a/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/PermissionDefinitionRecord.cs +++ b/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/PermissionDefinitionRecord.cs @@ -1,5 +1,4 @@ using System; -using System.Text.Json.Serialization; using Volo.Abp.Data; using Volo.Abp.Domain.Entities; using Volo.Abp.MultiTenancy; @@ -8,25 +7,18 @@ namespace Volo.Abp.PermissionManagement; public class PermissionDefinitionRecord : BasicAggregateRoot, IHasExtraProperties { - /* Ignoring Id because it is different whenever we create an instance of - * this class, and we are using Json Serialize, than Hash to understand - * if permission definitions have changed (in StaticPermissionSaver.CalculateHash()). - */ - [JsonIgnore] - public override Guid Id { get; protected set; } - public string GroupName { get; set; } - + public string Name { get; set; } - + public string ParentName { get; set; } - + public string DisplayName { get; set; } public bool IsEnabled { get; set; } - + public MultiTenancySides MultiTenancySide { get; set; } - + /// /// Comma separated list of provider names. /// @@ -36,7 +28,7 @@ public class PermissionDefinitionRecord : BasicAggregateRoot, IHasExtraPro /// Serialized string to store info about the state checkers. /// public string StateCheckers { get; set; } - + public ExtraPropertyDictionary ExtraProperties { get; protected set; } public PermissionDefinitionRecord() @@ -44,7 +36,7 @@ public class PermissionDefinitionRecord : BasicAggregateRoot, IHasExtraPro ExtraProperties = new ExtraPropertyDictionary(); this.SetDefaultsForExtraProperties(); } - + public PermissionDefinitionRecord( Guid id, string groupName, @@ -76,37 +68,37 @@ public class PermissionDefinitionRecord : BasicAggregateRoot, IHasExtraPro { return false; } - + if (GroupName != otherRecord.GroupName) { return false; } - + if (ParentName != otherRecord.ParentName) { return false; } - + if (DisplayName != otherRecord.DisplayName) { return false; } - + if (IsEnabled != otherRecord.IsEnabled) { return false; } - + if (MultiTenancySide != otherRecord.MultiTenancySide) { return false; } - + if (Providers != otherRecord.Providers) { return false; } - + if (StateCheckers != otherRecord.StateCheckers) { return false; @@ -126,37 +118,37 @@ public class PermissionDefinitionRecord : BasicAggregateRoot, IHasExtraPro { Name = otherRecord.Name; } - + if (GroupName != otherRecord.GroupName) { GroupName = otherRecord.GroupName; } - + if (ParentName != otherRecord.ParentName) { ParentName = otherRecord.ParentName; } - + if (DisplayName != otherRecord.DisplayName) { DisplayName = otherRecord.DisplayName; } - + if (IsEnabled != otherRecord.IsEnabled) { IsEnabled = otherRecord.IsEnabled; } - + if (MultiTenancySide != otherRecord.MultiTenancySide) { MultiTenancySide = otherRecord.MultiTenancySide; } - + if (Providers != otherRecord.Providers) { Providers = otherRecord.Providers; } - + if (StateCheckers != otherRecord.StateCheckers) { StateCheckers = otherRecord.StateCheckers; @@ -165,11 +157,11 @@ public class PermissionDefinitionRecord : BasicAggregateRoot, IHasExtraPro if (!this.HasSameExtraProperties(otherRecord)) { this.ExtraProperties.Clear(); - + foreach (var property in otherRecord.ExtraProperties) { this.ExtraProperties.Add(property.Key, property.Value); } } } -} \ No newline at end of file +} diff --git a/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/PermissionGroupDefinitionRecord.cs b/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/PermissionGroupDefinitionRecord.cs index f93bf57e21..4cd9c90894 100644 --- a/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/PermissionGroupDefinitionRecord.cs +++ b/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/PermissionGroupDefinitionRecord.cs @@ -1,5 +1,4 @@ using System; -using System.Text.Json.Serialization; using Volo.Abp.Data; using Volo.Abp.Domain.Entities; @@ -7,17 +6,10 @@ namespace Volo.Abp.PermissionManagement; public class PermissionGroupDefinitionRecord : BasicAggregateRoot, IHasExtraProperties { - /* Ignoring Id because it is different whenever we create an instance of - * this class, and we are using Json Serialize, than Hash to understand - * if permission definitions have changed (in StaticPermissionSaver.CalculateHash()). - */ - [JsonIgnore] - public override Guid Id { get; protected set; } - public string Name { get; set; } - + public string DisplayName { get; set; } - + public ExtraPropertyDictionary ExtraProperties { get; protected set; } public PermissionGroupDefinitionRecord() @@ -25,7 +17,7 @@ public class PermissionGroupDefinitionRecord : BasicAggregateRoot, IHasExt ExtraProperties = new ExtraPropertyDictionary(); this.SetDefaultsForExtraProperties(); } - + public PermissionGroupDefinitionRecord( Guid id, string name, @@ -45,7 +37,7 @@ public class PermissionGroupDefinitionRecord : BasicAggregateRoot, IHasExt { return false; } - + if (DisplayName != otherRecord.DisplayName) { return false; @@ -70,15 +62,15 @@ public class PermissionGroupDefinitionRecord : BasicAggregateRoot, IHasExt { DisplayName = otherRecord.DisplayName; } - + if (!this.HasSameExtraProperties(otherRecord)) { this.ExtraProperties.Clear(); - + foreach (var property in otherRecord.ExtraProperties) { this.ExtraProperties.Add(property.Key, property.Value); } } } -} \ No newline at end of file +} diff --git a/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/StaticPermissionSaver.cs b/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/StaticPermissionSaver.cs index 594f400a43..b0a4b271e2 100644 --- a/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/StaticPermissionSaver.cs +++ b/modules/permission-management/src/Volo.Abp.PermissionManagement.Domain/Volo/Abp/PermissionManagement/StaticPermissionSaver.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.Json; +using System.Text.Json.Serialization.Metadata; using System.Threading.Tasks; using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.Options; @@ -10,6 +11,7 @@ using Volo.Abp.Authorization.Permissions; using Volo.Abp.Caching; using Volo.Abp.DependencyInjection; using Volo.Abp.DistributedLocking; +using Volo.Abp.Json.SystemTextJson.Modifiers; using Volo.Abp.Threading; using Volo.Abp.Uow; @@ -273,13 +275,25 @@ public class StaticPermissionSaver : IStaticPermissionSaver, ITransientDependenc IEnumerable deletedPermissionGroups, IEnumerable deletedPermissions) { + var jsonSerializerOptions = new JsonSerializerOptions + { + TypeInfoResolver = new DefaultJsonTypeInfoResolver + { + Modifiers = + { + new AbpIgnorePropertiesModifiers().CreateModifyAction(x => x.Id), + new AbpIgnorePropertiesModifiers().CreateModifyAction(x => x.Id) + } + } + }; + var stringBuilder = new StringBuilder(); stringBuilder.Append("PermissionGroupRecords:"); - stringBuilder.AppendLine(JsonSerializer.Serialize(permissionGroupRecords)); + stringBuilder.AppendLine(JsonSerializer.Serialize(permissionGroupRecords, jsonSerializerOptions)); stringBuilder.Append("PermissionRecords:"); - stringBuilder.AppendLine(JsonSerializer.Serialize(permissionRecords)); + stringBuilder.AppendLine(JsonSerializer.Serialize(permissionRecords, jsonSerializerOptions)); stringBuilder.Append("DeletedPermissionGroups:"); stringBuilder.AppendLine(deletedPermissionGroups.JoinAsString(",")); diff --git a/modules/permission-management/test/Volo.Abp.PermissionManagement.Domain.Tests/Volo/Abp/PermissionManagement/CalculateHash_Tests.cs b/modules/permission-management/test/Volo.Abp.PermissionManagement.Domain.Tests/Volo/Abp/PermissionManagement/CalculateHash_Tests.cs new file mode 100644 index 0000000000..2e862c8f85 --- /dev/null +++ b/modules/permission-management/test/Volo.Abp.PermissionManagement.Domain.Tests/Volo/Abp/PermissionManagement/CalculateHash_Tests.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Text.Json; +using System.Text.Json.Serialization.Metadata; +using Shouldly; +using Volo.Abp.Json.SystemTextJson.Modifiers; +using Xunit; + +namespace Volo.Abp.PermissionManagement; + +public class CalculateHash_Tests: PermissionTestBase +{ + [Fact] + public void Test() + { + var jsonSerializerOptions = new JsonSerializerOptions + { + TypeInfoResolver = new DefaultJsonTypeInfoResolver + { + Modifiers = + { + new AbpIgnorePropertiesModifiers().CreateModifyAction(x => x.Id), + new AbpIgnorePropertiesModifiers().CreateModifyAction(x => x.Id) + } + } + }; + var id = Guid.NewGuid(); + var json = JsonSerializer.Serialize(new List() + { + new PermissionGroupDefinitionRecord(id, "Test", "Test") + }, + jsonSerializerOptions); + json.ShouldNotContain("\"Id\""); + json.ShouldNotContain(id.ToString("D")); + json = JsonSerializer.Serialize(new List() + { + new PermissionDefinitionRecord(id, "Test", "Test", "Test", "Test") + }, + jsonSerializerOptions); + json.ShouldNotContain("\"Id\""); + json.ShouldNotContain(id.ToString("D")); + } +}