Browse Source

Merge pull request #13399 from abpframework/Auditing

Remove the setter from the auditing interfaces.
pull/13428/head
liangshiwei 4 years ago
committed by GitHub
parent
commit
8913e42327
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      framework/src/Volo.Abp.Auditing.Contracts/Volo/Abp/Auditing/IDeletionAuditedObject.cs
  2. 2
      framework/src/Volo.Abp.Auditing.Contracts/Volo/Abp/Auditing/IHasDeletionTime.cs
  3. 2
      framework/src/Volo.Abp.Auditing.Contracts/Volo/Abp/Auditing/IHasModificationTime.cs
  4. 4
      framework/src/Volo.Abp.Auditing.Contracts/Volo/Abp/Auditing/IModificationAuditedObject.cs
  5. 16
      framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditPropertySetter.cs
  6. 4
      framework/src/Volo.Abp.Core/Volo/Abp/ISoftDelete.cs
  7. 2
      framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs
  8. 2
      framework/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs
  9. 5
      framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs

4
framework/src/Volo.Abp.Auditing.Contracts/Volo/Abp/Auditing/IDeletionAuditedObject.cs

@ -10,7 +10,7 @@ public interface IDeletionAuditedObject : IHasDeletionTime
/// <summary> /// <summary>
/// Id of the deleter user. /// Id of the deleter user.
/// </summary> /// </summary>
Guid? DeleterId { get; set; } Guid? DeleterId { get; }
} }
/// <summary> /// <summary>
@ -22,5 +22,5 @@ public interface IDeletionAuditedObject<TUser> : IDeletionAuditedObject
/// <summary> /// <summary>
/// Reference to the deleter user. /// Reference to the deleter user.
/// </summary> /// </summary>
TUser Deleter { get; set; } TUser Deleter { get; }
} }

2
framework/src/Volo.Abp.Auditing.Contracts/Volo/Abp/Auditing/IHasDeletionTime.cs

@ -11,5 +11,5 @@ public interface IHasDeletionTime : ISoftDelete
/// <summary> /// <summary>
/// Deletion time. /// Deletion time.
/// </summary> /// </summary>
DateTime? DeletionTime { get; set; } DateTime? DeletionTime { get; }
} }

2
framework/src/Volo.Abp.Auditing.Contracts/Volo/Abp/Auditing/IHasModificationTime.cs

@ -10,5 +10,5 @@ public interface IHasModificationTime
/// <summary> /// <summary>
/// The last modified time for this entity. /// The last modified time for this entity.
/// </summary> /// </summary>
DateTime? LastModificationTime { get; set; } DateTime? LastModificationTime { get; }
} }

4
framework/src/Volo.Abp.Auditing.Contracts/Volo/Abp/Auditing/IModificationAuditedObject.cs

@ -10,7 +10,7 @@ public interface IModificationAuditedObject : IHasModificationTime
/// <summary> /// <summary>
/// Last modifier user for this entity. /// Last modifier user for this entity.
/// </summary> /// </summary>
Guid? LastModifierId { get; set; } Guid? LastModifierId { get; }
} }
/// <summary> /// <summary>
@ -22,5 +22,5 @@ public interface IModificationAuditedObject<TUser> : IModificationAuditedObject
/// <summary> /// <summary>
/// Reference to the last modifier user of this entity. /// Reference to the last modifier user of this entity.
/// </summary> /// </summary>
TUser LastModifier { get; set; } TUser LastModifier { get; }
} }

16
framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditPropertySetter.cs

@ -99,7 +99,7 @@ public class AuditPropertySetter : IAuditPropertySetter, ITransientDependency
{ {
if (targetObject is IHasModificationTime objectWithModificationTime) if (targetObject is IHasModificationTime objectWithModificationTime)
{ {
objectWithModificationTime.LastModificationTime = Clock.Now; ObjectHelper.TrySetProperty(objectWithModificationTime, x => x.LastModificationTime, () => Clock.Now);
} }
} }
@ -112,7 +112,7 @@ public class AuditPropertySetter : IAuditPropertySetter, ITransientDependency
if (!CurrentUser.Id.HasValue) if (!CurrentUser.Id.HasValue)
{ {
modificationAuditedObject.LastModifierId = null; ObjectHelper.TrySetProperty(modificationAuditedObject, x => x.LastModifierId, () => null);
return; return;
} }
@ -120,7 +120,7 @@ public class AuditPropertySetter : IAuditPropertySetter, ITransientDependency
{ {
if (multiTenantEntity.TenantId != CurrentUser.TenantId) if (multiTenantEntity.TenantId != CurrentUser.TenantId)
{ {
modificationAuditedObject.LastModifierId = null; ObjectHelper.TrySetProperty(modificationAuditedObject, x => x.LastModifierId, () => null);
return; return;
} }
} }
@ -134,7 +134,7 @@ public class AuditPropertySetter : IAuditPropertySetter, ITransientDependency
} }
*/ */
modificationAuditedObject.LastModifierId = CurrentUser.Id; ObjectHelper.TrySetProperty(modificationAuditedObject, x => x.LastModifierId, () => CurrentUser.Id);
} }
protected virtual void SetDeletionTime(object targetObject) protected virtual void SetDeletionTime(object targetObject)
@ -143,7 +143,7 @@ public class AuditPropertySetter : IAuditPropertySetter, ITransientDependency
{ {
if (objectWithDeletionTime.DeletionTime == null) if (objectWithDeletionTime.DeletionTime == null)
{ {
objectWithDeletionTime.DeletionTime = Clock.Now; ObjectHelper.TrySetProperty(objectWithDeletionTime, x => x.DeletionTime, () => Clock.Now);
} }
} }
} }
@ -162,7 +162,7 @@ public class AuditPropertySetter : IAuditPropertySetter, ITransientDependency
if (!CurrentUser.Id.HasValue) if (!CurrentUser.Id.HasValue)
{ {
deletionAuditedObject.DeleterId = null; ObjectHelper.TrySetProperty(deletionAuditedObject, x => x.DeleterId, () => null);
return; return;
} }
@ -170,11 +170,11 @@ public class AuditPropertySetter : IAuditPropertySetter, ITransientDependency
{ {
if (multiTenantEntity.TenantId != CurrentUser.TenantId) if (multiTenantEntity.TenantId != CurrentUser.TenantId)
{ {
deletionAuditedObject.DeleterId = null; ObjectHelper.TrySetProperty(deletionAuditedObject, x => x.DeleterId, () => null);
return; return;
} }
} }
deletionAuditedObject.DeleterId = CurrentUser.Id; ObjectHelper.TrySetProperty(deletionAuditedObject, x => x.DeleterId, () => CurrentUser.Id);
} }
} }

4
framework/src/Volo.Abp.Core/Volo/Abp/ISoftDelete.cs

@ -9,7 +9,7 @@
public interface ISoftDelete public interface ISoftDelete
{ {
/// <summary> /// <summary>
/// Used to mark an Entity as 'Deleted'. /// Used to mark an Entity as 'Deleted'.
/// </summary> /// </summary>
bool IsDeleted { get; set; } bool IsDeleted { get; }
} }

2
framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs

@ -485,7 +485,7 @@ public abstract class AbpDbContext<TDbContext> : DbContext, IAbpEfCoreDbContext,
} }
entry.Reload(); entry.Reload();
entry.Entity.As<ISoftDelete>().IsDeleted = true; ObjectHelper.TrySetProperty(entry.Entity.As<ISoftDelete>(), x => x.IsDeleted, () => true);
SetDeletionAuditProperties(entry); SetDeletionAuditProperties(entry);
} }

2
framework/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs

@ -253,7 +253,7 @@ public class MemoryDbRepository<TMemoryDbContext, TEntity> : RepositoryBase<TEnt
if (entity is ISoftDelete softDeleteEntity && !IsHardDeleted(entity)) if (entity is ISoftDelete softDeleteEntity && !IsHardDeleted(entity))
{ {
softDeleteEntity.IsDeleted = true; ObjectHelper.TrySetProperty(softDeleteEntity, x => x.IsDeleted, () => true);
(await GetCollectionAsync()).Update(entity); (await GetCollectionAsync()).Update(entity);
} }
else else

5
framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs

@ -294,7 +294,7 @@ public class MongoDbRepository<TMongoDbContext, TEntity>
if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity)) && !IsHardDeleted(entity)) if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity)) && !IsHardDeleted(entity))
{ {
((ISoftDelete)entity).IsDeleted = true; ObjectHelper.TrySetProperty(((ISoftDelete)entity), x => x.IsDeleted, () => true);
ApplyAbpConceptsForDeletedEntity(entity); ApplyAbpConceptsForDeletedEntity(entity);
ReplaceOneResult result; ReplaceOneResult result;
@ -365,8 +365,7 @@ public class MongoDbRepository<TMongoDbContext, TEntity>
{ {
if (typeof(ISoftDelete).IsAssignableFrom(typeof(TEntity)) && !IsHardDeleted(entity)) 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)); softDeletedEntities.Add(entity, SetNewConcurrencyStamp(entity));
} }
else else

Loading…
Cancel
Save