Add support for auditing entities with user names (e.g., CreatorName, DeleterName)
Is there an existing issue for this?
- [X] I have searched the existing issues
Is your feature request related to a problem? Please describe the problem.
No response
Describe the solution you'd like
Hello,
I am currently using the FullAuditedEntityWithUser class to audit entities in my project, and I see that it provides properties like Creator, Deleter, and LastModifier, which are of type TUser.
I would like to inquire if there is built-in support or any recommended way to extend these auditing properties to include the respective user names, such as CreatorName, DeleterName, and LastModifierName. This would be helpful in scenarios where we want to display user-friendly names in the UI or logs, instead of only referencing the user object.
If this functionality is not currently available, would it be possible to consider adding support for auditing with both the user entity and the user's name directly?
Thank you for your assistance.
Additional context
No response
I have the same need.
expanded the methods of auditing.
public interface IMayHaveCreatorName
{
string CreatorName { get; }
}
[Dependency(ReplaceServices = true)]
[ExposeServices(typeof(IAuditPropertySetter))]
public class CreationNameAuditPropertySetter : AuditPropertySetter
{
public CreationNameAuditPropertySetter(ICurrentUser currentUser, ICurrentTenant currentTenant, IClock clock)
: base(currentUser, currentTenant, clock)
{
}
public override void SetCreationProperties(object targetObject)
{
base.SetCreationProperties(targetObject);
SetCreatorName(targetObject);
}
protected virtual void SetCreatorName(object targetObject)
{
if (!CurrentUser.Id.HasValue)
{
return;
}
if (targetObject is IMultiTenant multiTenantEntity)
{
if (multiTenantEntity.TenantId != CurrentUser.TenantId)
{
return;
}
}
if (targetObject is IMayHaveCreatorName mayHaveCreatorObject)
{
if (!string.IsNullOrEmpty(mayHaveCreatorObject.CreatorName))
{
return;
}
ObjectHelper.TrySetProperty(mayHaveCreatorObject, x => x.CreatorName, () => CurrentUser.UserName);
}
}
}
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.