Define IMayHaveCreator and IMustHaveCreator interfaces.

pull/318/head
Halil ibrahim Kalkan 7 years ago
parent d72fdb4dc3
commit f2010f405f

@ -12,8 +12,8 @@ namespace Volo.Abp.Auditing
protected IClock Clock { get; }
public AuditPropertySetter(
ICurrentUser currentUser,
ICurrentTenant currentTenant,
ICurrentUser currentUser,
ICurrentTenant currentTenant,
IClock clock)
{
CurrentUser = currentUser;
@ -54,16 +54,6 @@ namespace Volo.Abp.Auditing
private void SetCreatorId(object targetObject)
{
if (!(targetObject is ICreationAudited creationAuditedObject))
{
return;
}
if (creationAuditedObject.CreatorId != null)
{
return;
}
if (!CurrentUser.Id.HasValue)
{
return;
@ -78,16 +68,33 @@ namespace Volo.Abp.Auditing
}
/* TODO: The code below is from old ABP, not implemented yet
if (tenantId.HasValue && MultiTenancyHelper.IsHostEntity(entity))
if (tenantId.HasValue && MultiTenancyHelper.IsHostEntity(entity))
{
//Tenant user created a host entity
return;
}
*/
if (targetObject is IMayHaveCreator mayHaveCreatorObject)
{
//Tenant user created a host entity
return;
if (mayHaveCreatorObject.CreatorId.HasValue && mayHaveCreatorObject.CreatorId.Value != default)
{
return;
}
mayHaveCreatorObject.CreatorId = CurrentUser.Id;
}
*/
else if (targetObject is IMustHaveCreator mustHaveCreatorObject)
{
if (mustHaveCreatorObject.CreatorId != default)
{
return;
}
creationAuditedObject.CreatorId = CurrentUser.Id;
mustHaveCreatorObject.CreatorId = CurrentUser.Id.Value;
}
}
private void SetLastModificationTime(object targetObject)
{
if (targetObject is IHasModificationTime objectWithModificationTime)

@ -1,27 +1,19 @@
using System;
namespace Volo.Abp.Auditing
{
/// <summary>
/// This interface can be implemented to store creation information (who and when created).
/// </summary>
public interface ICreationAudited : IHasCreationTime
public interface ICreationAudited : IHasCreationTime, IMayHaveCreator
{
/// <summary>
/// Id of the creator user.
/// </summary>
Guid? CreatorId { get; set; }
}
/// <summary>
/// Adds navigation properties to <see cref="ICreationAudited"/> interface for user.
/// Adds navigation property (object reference) to <see cref="ICreationAudited"/> interface.
/// </summary>
/// <typeparam name="TUser">Type of the user</typeparam>
public interface ICreationAudited<TUser> : ICreationAudited
/// <typeparam name="TCreator">Type of the user</typeparam>
public interface ICreationAudited<TCreator> : ICreationAudited, IMayHaveCreator<TCreator>
{
/// <summary>
/// Reference to the creator user.
/// </summary>
TUser Creator { get; set; }
}
}

@ -0,0 +1,25 @@
using System;
using JetBrains.Annotations;
namespace Volo.Abp.Auditing
{
public interface IMayHaveCreator<TCreator>
{
/// <summary>
/// Reference to the creator.
/// </summary>
[CanBeNull]
TCreator Creator { get; set; }
}
/// <summary>
/// Standard interface for an entity that MAY have a creator.
/// </summary>
public interface IMayHaveCreator
{
/// <summary>
/// Id of the creator.
/// </summary>
Guid? CreatorId { get; set; }
}
}

@ -0,0 +1,28 @@
using System;
using JetBrains.Annotations;
namespace Volo.Abp.Auditing
{
/// <summary>
/// Standard interface for an entity that MUST have a creator of type <typeparamref name="TCreator"/>.
/// </summary>
public interface IMustHaveCreator<TCreator> : IMustHaveCreator
{
/// <summary>
/// Reference to the creator.
/// </summary>
[NotNull]
TCreator Creator { get; set; }
}
/// <summary>
/// Standard interface for an entity that MUST have a creator.
/// </summary>
public interface IMustHaveCreator
{
/// <summary>
/// Id of the creator.
/// </summary>
Guid CreatorId { get; set; }
}
}

@ -33,6 +33,18 @@ namespace Volo.Abp.EntityFrameworkCore.Modeling
b.Property(x => x.DeletionTime).IsRequired(false).HasColumnName(nameof(IHasDeletionTime.DeletionTime));
}
public static void ConfigureMayHaveCreator<T>(this EntityTypeBuilder<T> b)
where T : class, IMayHaveCreator
{
b.Property(x => x.CreatorId).IsRequired(false).HasColumnName(nameof(IMayHaveCreator.CreatorId));
}
public static void ConfigureMustHaveCreator<T>(this EntityTypeBuilder<T> b)
where T : class, IMustHaveCreator
{
b.Property(x => x.CreatorId).IsRequired().HasColumnName(nameof(IMustHaveCreator.CreatorId));
}
public static void ConfigureDeletionAudited<T>(this EntityTypeBuilder<T> b)
where T : class, IDeletionAudited
{

Loading…
Cancel
Save