Skip to content

Commit

Permalink
Remove the setter from the auditing interfaces.
Browse files Browse the repository at this point in the history
Resolve #12229
  • Loading branch information
maliming committed Jul 25, 2022
1 parent 83f1ac0 commit e0b7e7b
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public interface IDeletionAuditedObject : IHasDeletionTime
/// <summary>
/// Id of the deleter user.
/// </summary>
Guid? DeleterId { get; set; }
Guid? DeleterId { get; }
}

/// <summary>
Expand All @@ -22,5 +22,5 @@ public interface IDeletionAuditedObject<TUser> : IDeletionAuditedObject
/// <summary>
/// Reference to the deleter user.
/// </summary>
TUser Deleter { get; set; }
TUser Deleter { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ public interface IHasDeletionTime : ISoftDelete
/// <summary>
/// Deletion time.
/// </summary>
DateTime? DeletionTime { get; set; }
DateTime? DeletionTime { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ public interface IHasModificationTime
/// <summary>
/// The last modified time for this entity.
/// </summary>
DateTime? LastModificationTime { get; set; }
DateTime? LastModificationTime { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public interface IModificationAuditedObject : IHasModificationTime
/// <summary>
/// Last modifier user for this entity.
/// </summary>
Guid? LastModifierId { get; set; }
Guid? LastModifierId { get; }
}

/// <summary>
Expand All @@ -22,5 +22,5 @@ public interface IModificationAuditedObject<TUser> : IModificationAuditedObject
/// <summary>
/// Reference to the last modifier user of this entity.
/// </summary>
TUser LastModifier { get; set; }
TUser LastModifier { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected virtual void SetLastModificationTime(object targetObject)
{
if (targetObject is IHasModificationTime objectWithModificationTime)
{
objectWithModificationTime.LastModificationTime = Clock.Now;
ObjectHelper.TrySetProperty(objectWithModificationTime, x => x.LastModificationTime, () => Clock.Now);
}
}

Expand All @@ -112,15 +112,15 @@ protected virtual void SetLastModifierId(object targetObject)

if (!CurrentUser.Id.HasValue)
{
modificationAuditedObject.LastModifierId = null;
ObjectHelper.TrySetProperty(modificationAuditedObject, x => x.LastModifierId, () => null);
return;
}

if (modificationAuditedObject is IMultiTenant multiTenantEntity)
{
if (multiTenantEntity.TenantId != CurrentUser.TenantId)
{
modificationAuditedObject.LastModifierId = null;
ObjectHelper.TrySetProperty(modificationAuditedObject, x => x.LastModifierId, () => null);
return;
}
}
Expand All @@ -134,7 +134,7 @@ protected virtual void SetLastModifierId(object targetObject)
}
*/

modificationAuditedObject.LastModifierId = CurrentUser.Id;
ObjectHelper.TrySetProperty(modificationAuditedObject, x => x.LastModifierId, () => CurrentUser.Id);
}

protected virtual void SetDeletionTime(object targetObject)
Expand All @@ -143,7 +143,7 @@ protected virtual void SetDeletionTime(object targetObject)
{
if (objectWithDeletionTime.DeletionTime == null)
{
objectWithDeletionTime.DeletionTime = Clock.Now;
ObjectHelper.TrySetProperty(objectWithDeletionTime, x => x.DeletionTime, () => Clock.Now);
}
}
}
Expand All @@ -162,19 +162,19 @@ protected virtual void SetDeleterId(object targetObject)

if (!CurrentUser.Id.HasValue)
{
deletionAuditedObject.DeleterId = null;
ObjectHelper.TrySetProperty(deletionAuditedObject, x => x.DeleterId, () => null);
return;
}

if (deletionAuditedObject is IMultiTenant multiTenantEntity)
{
if (multiTenantEntity.TenantId != CurrentUser.TenantId)
{
deletionAuditedObject.DeleterId = null;
ObjectHelper.TrySetProperty(deletionAuditedObject, x => x.DeleterId, () => null);
return;
}
}

deletionAuditedObject.DeleterId = CurrentUser.Id;
ObjectHelper.TrySetProperty(deletionAuditedObject, x => x.DeleterId, () => CurrentUser.Id);
}
}
4 changes: 2 additions & 2 deletions framework/src/Volo.Abp.Core/Volo/Abp/ISoftDelete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public interface ISoftDelete
{
/// <summary>
/// Used to mark an Entity as 'Deleted'.
/// Used to mark an Entity as 'Deleted'.
/// </summary>
bool IsDeleted { get; set; }
bool IsDeleted { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ protected virtual void ApplyAbpConceptsForDeletedEntity(EntityEntry entry)
}

entry.Reload();
entry.Entity.As<ISoftDelete>().IsDeleted = true;
ObjectHelper.TrySetProperty(entry.Entity.As<ISoftDelete>(), x => x.IsDeleted, () => true);
SetDeletionAuditProperties(entry);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public override async Task DeleteAsync(

if (entity is ISoftDelete softDeleteEntity && !IsHardDeleted(entity))
{
softDeleteEntity.IsDeleted = true;
ObjectHelper.TrySetProperty(softDeleteEntity, x => x.IsDeleted, () => true);
(await GetCollectionAsync()).Update(entity);
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public async override Task DeleteAsync(

if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity)) && !IsHardDeleted(entity))
{
((ISoftDelete)entity).IsDeleted = true;
ObjectHelper.TrySetProperty(((ISoftDelete)entity), x => x.IsDeleted, () => true);
ApplyAbpConceptsForDeletedEntity(entity);

ReplaceOneResult result;
Expand Down Expand Up @@ -365,8 +365,7 @@ public async override Task DeleteManyAsync(
{
if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity)) && !IsHardDeleted(entity))
{
((ISoftDelete)entity).IsDeleted = true;

ObjectHelper.TrySetProperty(((ISoftDelete)entity), x => x.IsDeleted, () => true);
softDeletedEntities.Add(entity, SetNewConcurrencyStamp(entity));
}
else
Expand Down

0 comments on commit e0b7e7b

Please sign in to comment.