Open Closed

Set LastMdifierId in tenant with user in host and sending email by cms in contact form #4260


User avatar
0
Merna created

Hello, I have 2 Questions: 1.I am using "IMultiTenant" interface for an entity used in tenant with "FullAuditedAggregateRoot" interface and everything works fine until I have a business request to update the record in db by user in administration (host) and here is the problem as the "LastModifierId" is always null but "LastModificationTime" is sets correctly

  • Is there a way to set LastModifierId with a userId that not in the same tenant ?

2.I am using Contact form in cms module, set the email on cms settings then in web public, try to send message by submit contact form but nothing received on email. may I miss any configuration?

  • ABP Framework version: v7.0.0 rc3
  • UI type: MVC
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): yes

3 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    HI,

    1.

    This is by ABP design https://github.com/abpframework/abp/blob/2c37e56751a3ff9a7e4c0cd44541e6a1a33f031d/framework/src/Volo.Abp.Auditing/Volo/Abp/Auditing/AuditPropertySetter.cs#L127-L134

    You can create your own AuditPropertySetter to replace the default implement, for example:

    [ExposeServices(typeof(IAuditPropertySetter))]
    [Dependency(ReplaceServices = true)]
    public class MyAuditPropertySetter: AuditPropertySetter
    {
        protected override void SetLastModifierId(object targetObject)
        {
            if (!(targetObject is IModificationAuditedObject modificationAuditedObject))
            {
                return;
            }
    
            if (!CurrentUser.Id.HasValue)
            {
                ObjectHelper.TrySetProperty(modificationAuditedObject, x => x.LastModifierId, () => null);
                return;
            }
    
            // if (modificationAuditedObject is IMultiTenant multiTenantEntity)
            // {
            //     if (multiTenantEntity.TenantId != CurrentUser.TenantId)
            //     {
            //         ObjectHelper.TrySetProperty(modificationAuditedObject, x => x.LastModifierId, () => null);
            //         return;
            //     }
            // }
    
            ObjectHelper.TrySetProperty(modificationAuditedObject, x => x.LastModifierId, () => CurrentUser.Id);
        }
    }
    

    We use the NullEmailSender in the debug mode, you can remove it

    and we have an example to check email configure: https://github.com/abpframework/abp-samples/tree/master/EmailSendDemo

  • User Avatar
    0
    Merna created

    Hello liangshiwei, Sorry for late respose. I did apply change about setting LastModifiedId and works perfectly thanks. but yet didnt check on cms solution once I check it, I'll give feedback.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    ok

Made with ❤️ on ABP v9.1.0-preview. Updated on December 26, 2024, 06:07