Remove `JsonIgnoreAttribute` and use `AbpIgnorePropertiesModifiers`.

pull/16777/head
maliming 2 years ago
parent 8099cd1115
commit a04417529a
No known key found for this signature in database
GPG Key ID: A646B9CB645ECEA4

@ -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; }

@ -7,13 +7,6 @@ namespace Volo.Abp.FeatureManagement;
public class FeatureDefinitionRecord : BasicAggregateRoot<Guid>, 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; }

@ -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<Guid>, 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; }

@ -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<string> deletedFeatureGroups,
IEnumerable<string> deletedFeatures)
{
var jsonSerializerOptions = new JsonSerializerOptions
{
TypeInfoResolver = new DefaultJsonTypeInfoResolver
{
Modifiers =
{
new AbpIgnorePropertiesModifiers<FeatureGroupDefinitionRecord, Guid>().CreateModifyAction(x => x.Id),
new AbpIgnorePropertiesModifiers<FeatureDefinitionRecord, Guid>().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(","));

@ -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<FeatureGroupDefinitionRecord, Guid>().CreateModifyAction(x => x.Id),
new AbpIgnorePropertiesModifiers<FeatureDefinitionRecord, Guid>().CreateModifyAction(x => x.Id)
}
}
};
var id = Guid.NewGuid();
var json = JsonSerializer.Serialize(new List<FeatureGroupDefinitionRecord>()
{
new FeatureGroupDefinitionRecord(id, "Test", "Test")
},
jsonSerializerOptions);
json.ShouldNotContain("\"Id\"");
json.ShouldNotContain(id.ToString("D"));
json = JsonSerializer.Serialize(new List<FeatureDefinitionRecord>()
{
new FeatureDefinitionRecord(id, "Test", "Test", "Test", "Test", "Test", "Test", true, true,"Test", "Test")
},
jsonSerializerOptions);
json.ShouldNotContain("\"Id\"");
json.ShouldNotContain(id.ToString("D"));
}
}

@ -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<Guid>, 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; }
/// <summary>
/// Comma separated list of provider names.
/// </summary>
@ -36,7 +28,7 @@ public class PermissionDefinitionRecord : BasicAggregateRoot<Guid>, IHasExtraPro
/// Serialized string to store info about the state checkers.
/// </summary>
public string StateCheckers { get; set; }
public ExtraPropertyDictionary ExtraProperties { get; protected set; }
public PermissionDefinitionRecord()
@ -44,7 +36,7 @@ public class PermissionDefinitionRecord : BasicAggregateRoot<Guid>, IHasExtraPro
ExtraProperties = new ExtraPropertyDictionary();
this.SetDefaultsForExtraProperties();
}
public PermissionDefinitionRecord(
Guid id,
string groupName,
@ -76,37 +68,37 @@ public class PermissionDefinitionRecord : BasicAggregateRoot<Guid>, 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<Guid>, 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<Guid>, IHasExtraPro
if (!this.HasSameExtraProperties(otherRecord))
{
this.ExtraProperties.Clear();
foreach (var property in otherRecord.ExtraProperties)
{
this.ExtraProperties.Add(property.Key, property.Value);
}
}
}
}
}

@ -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<Guid>, 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<Guid>, IHasExt
ExtraProperties = new ExtraPropertyDictionary();
this.SetDefaultsForExtraProperties();
}
public PermissionGroupDefinitionRecord(
Guid id,
string name,
@ -45,7 +37,7 @@ public class PermissionGroupDefinitionRecord : BasicAggregateRoot<Guid>, IHasExt
{
return false;
}
if (DisplayName != otherRecord.DisplayName)
{
return false;
@ -70,15 +62,15 @@ public class PermissionGroupDefinitionRecord : BasicAggregateRoot<Guid>, IHasExt
{
DisplayName = otherRecord.DisplayName;
}
if (!this.HasSameExtraProperties(otherRecord))
{
this.ExtraProperties.Clear();
foreach (var property in otherRecord.ExtraProperties)
{
this.ExtraProperties.Add(property.Key, property.Value);
}
}
}
}
}

@ -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<string> deletedPermissionGroups,
IEnumerable<string> deletedPermissions)
{
var jsonSerializerOptions = new JsonSerializerOptions
{
TypeInfoResolver = new DefaultJsonTypeInfoResolver
{
Modifiers =
{
new AbpIgnorePropertiesModifiers<PermissionGroupDefinitionRecord, Guid>().CreateModifyAction(x => x.Id),
new AbpIgnorePropertiesModifiers<PermissionDefinitionRecord, Guid>().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(","));

@ -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<PermissionGroupDefinitionRecord, Guid>().CreateModifyAction(x => x.Id),
new AbpIgnorePropertiesModifiers<PermissionDefinitionRecord, Guid>().CreateModifyAction(x => x.Id)
}
}
};
var id = Guid.NewGuid();
var json = JsonSerializer.Serialize(new List<PermissionGroupDefinitionRecord>()
{
new PermissionGroupDefinitionRecord(id, "Test", "Test")
},
jsonSerializerOptions);
json.ShouldNotContain("\"Id\"");
json.ShouldNotContain(id.ToString("D"));
json = JsonSerializer.Serialize(new List<PermissionDefinitionRecord>()
{
new PermissionDefinitionRecord(id, "Test", "Test", "Test", "Test")
},
jsonSerializerOptions);
json.ShouldNotContain("\"Id\"");
json.ShouldNotContain(id.ToString("D"));
}
}
Loading…
Cancel
Save