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

RecordFetching event not triggering in the backoffice v2 #639

Closed
DennisBoonkP opened this issue Sep 10, 2021 · 6 comments
Closed

RecordFetching event not triggering in the backoffice v2 #639

DennisBoonkP opened this issue Sep 10, 2021 · 6 comments

Comments

@DennisBoonkP
Copy link

DennisBoonkP commented Sep 10, 2021

Hi guys,

I'm working on an package do encrypt Umbraco Forms data in the db. The encryption is implemented but when retrieving the data in the backoffice we have a problem and hopefully you can take a look shortly, so we can fix this and release the new and improved package. This report is a follow up on #29.

We hoped that we could decrypt the data when plugging into the event
RecordStorage.RecordFetching += RecordStorage_RecordFetching;
So if we clicked on "Entries" in the backoffice forms-section this would get called and we could decrypt every record. But this isn't triggered.

Could you think for just a moment how we could achieve the decryption in the backoffice without rewriting whole parts of the work you've done?

Thank you very much!

Bug summary

RecordStorage.RecordFetching event not triggerd in the backoffice

Specifics

Tested with Umbraco 7.15.7 and UmbracoForms 7.5.4

Steps to reproduce

  • Add an event handler, Example:
namespace Test2.Code
{
    public class RecordEvents : ApplicationEventHandler
    {
        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {

            RecordStorage.RecordFetching += RecordStorage_RecordFetching;
        }

        private void RecordStorage_RecordFetching(object sender, Umbraco.Forms.Core.RecordEventArgs e)
        {
            throw new NotImplementedException();
        }
    }
}
  • Open the "Entries "of a form in the backoffice.
  • Nothing happens but I expect the event to betriggerd.

Expected result

The event is triggerd when retching a record.

Actual result

Nothing

@AndyButland
Copy link

AndyButland commented Sep 28, 2021

I've had a look into this. The issue here is that actually, the RecordStorage class isn't used to populate the "Entries" screens in the back-office, hence the event associated with that class isn't going to fire. Rather the FormRecordSearcher (V7) or IFormRecordSearcher (V8) is used.

This doesn't have an equivalent event, but it seems like we could add one, allowing for the the amends to the records as you are looking to do. There's a couple of PRs linked for V7 and V8, so will see how they go through review.

@DennisBoonkP
Copy link
Author

Hé Andy,

Thank you for your effort! An event would be great. When do you expect the new version with the new event is released? Then I can give an update to the customer.

With kind regards,
Dennis Boonk

@AndyButland
Copy link

No set date yet I'm afraid @DennisBoonkP - but once the fix is reviewed and tested I'll make a nightly build available to you. It'll come officially in the next minor, hopefully within the next few weeks.

@AndyButland
Copy link

AndyButland commented Oct 18, 2021

I've made available a couple of preview builds containing this amend @DennisBoonkP :

You can just extract the dlls and copy them over your current versions.

You're welcome to use these to progress your development work, and if you can confirm the change meets your requirements that would be appreciated, as then I can look to get it out in patch for V7. For V8 it'll come with the next minor release.

To use it, for V7 you can use the new event as per this example:

    public class RecordEvents : ApplicationEventHandler
    {
        protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            FormRecordSearcher.EntrySearchResultFetching += FormRecordSearcher_EntrySearchResultFetching;
        }

        private void FormRecordSearcher_EntrySearchResultFetching(object sender, EntrySearchResultEventArgs e)
        {
            // Do something with e.EntrySearchResult.Fields
        }
    }

With V8 you should be able to write a composer/component like this to use the new event (note that we've had to add a new interface here to avoid a breaking change by introducing the event on IFormRecordSearcher):

    public class TestSiteComposer : IComposer
    {
        /// <inheritdoc/>
        public void Compose(Composition composition) =>
            composition.Components().Append<TestSiteComponent>();
    }
	
    public class TestSiteComponent : IComponent
    {
        private readonly IFormRecordSearcher _formRecordSearcher;

        public TestSiteComponent(IFormRecordSearcher formRecordSearcher) => _formRecordSearcher = formRecordSearcher;

        public void Initialize()
        {
            if (_formRecordSearcher is IFormRecordSearcherWithEvents formRecordSearcherWithEvents)
            {
                formRecordSearcherWithEvents.EntrySearchResultFetching += FormRecordSearcher_EntrySearchResultFetching;
            }
        }

        private void FormRecordSearcher_EntrySearchResultFetching(object sender, EntrySearchResultEventArgs e)
        {
            // Do something with e.EntrySearchResult.Fields
        }

        public void Terminate()
        {
            if (_formRecordSearcher is IFormRecordSearcherWithEvents formRecordSearcherWithEvents)
            {
                formRecordSearcherWithEvents.EntrySearchResultFetching -= FormRecordSearcher_EntrySearchResultFetching;
            }
        }
    }

And for completeness, for V9, it looks like this:

    public class TestSiteComposer : IComposer
    {
        public void Compose(IUmbracoBuilder builder) =>
            builder.AddNotificationHandler<EntrySearchResultFetchingNotification, EntrySearchResultFetchingNotificationHandler>();
    }
	
    public class EntrySearchResultFetchingNotificationHandler : INotificationHandler<EntrySearchResultFetchingNotification>
    {
        public void Handle(EntrySearchResultFetchingNotification notification)
        {
            // Do something with notification.EntrySearchResult.Fields
        }
    }	

@RunnicFusion
Copy link

Hi Andy,

Thank you for making this event available. I can confirm it works on v7 when using the patched Umbraco Forms dll's you've provided above.

Do you have an estimated release date for Umbraco Forms v7? Can't find any futher info on 7.5.5 at this moment.

Kind regards,
Roy

@AndyButland
Copy link

AndyButland commented Oct 28, 2021

Hi @RunnicFusion - that's good to hear. With regards release date we aren't doing feature work on V7 at the moment, so really I was just waiting for you to confirm that the provided solution works for you, as including this will be the only update for 7.5.5. I'm off now for a couple of days but will arrange the release next week, and you can likely expect it about a week after.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants