Autofill values in nested component fields

System Information
  • Strapi Version: 3.6.8
  • Operating System: MacOS Catalina
  • Database: Sqlite
  • Node Version: 14.17.5
  • NPM Version: 6.14.14
  • Yarn Version: 1.22.18

I have an Article collection with some fields in. For each entry I wish I could store some fields related to the approval workflow and a list of simple text messages for internal use only (a messaging system between users editing the content).

My first try was to create a second collection (InternalMessage) with a many-to-one relation with Article. But in the Strapi Admin Interface during the insertion of an Article you can only choose from existing content of InternalMessage.
For a good “editorial experience” I would like to configure a way to dynamically insert the InternalMessage during the edit phase of an Article.

So, instead of creating a second collection, I created a quite complex custom component with another custom component in it (holding the repeatable messages). A 2-level nested custom component as per the image below.

Then I used this new “Approval-fields” custom component in the Article content-type so the Editors can dynamically insert messages in this structure.
At this point I decided to find a way to autofill the history_notes.admin_user field with the current Editor User reference (or id).

I know Strapi gives the opportunity to configure Lifecycle Hooks. And that is surely the way to do the job. So first of all I set history_notes.admin_user as non editable and started editing the api/articles/models/articles.js. I tried to configure the beforeCreate and beforeUpdate methods, to try to obtain the value of current Admin User editing the content and use this value to autofill the history_notes.admin_user .
But at this point I felt lost.
I tried to log the payload:

beforeUpdate -  {
  title: 'Test Article Title field',
  approval: {
    id: 2,
    ready_for_revision: true,
    ready_for_approval: false,
    history_notes: [ [Object], [Object] ]
  updated_by: 1

How can I reach the correct nested record in both methods to set/update the right history_notes.admin_user field? How can I discover which of the 2 [Object] I need to point.
And also: my scope is "to autofill admin_user", so if it is not involved in the current update event of the Article the autofill is not necessary.

I gave a look to the DB, and discover the complex structure used to manage the custom components. It’s very well planned but very complex if I have to traverse it to find or update something.

Even if I find a solution to my autofill need I fear for the future. What will happen in case the content type has to be changed in some part? Will the custom code I wrote break silently?

As soon as I found a solution for this 1st step the second would be: once a single “history_note” is inserted, the short_comment should be not editable any more.

Thanks in advance for any help given.

And sorry for the long post!!