Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the setter from the auditing interfaces. #13399

Merged
merged 1 commit into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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