VirtusLab-Open-Source/strapi-plugin-comments

Autopopulate on different authorType ?

tiberiumihai opened this issue · 4 comments

I've see that the authorUser can be used for strapi user and other author particular fields can be used for other type of users (let's say a profile). I don't like this method because if the user changes his name or his avatar, these fields become obsolete.

And because I store the user account data (auth) in a different content type than the user profile data, is it possible to create a comment using in payload:
{ authorType: "profile", authorId: "<profile-id>" }
and the plugin to auto-populate this attribute?

Maybe this way, the duplicated fields can become only one, strapi user or other related content type (user profile).

I would look up on how I might add this functionality but I'm not entirely sure if this is what the plugin wants in the future.

Let me know and I can take a look.

Thanks for the awesome work!

Hello @tiberiumihai,
Your case is not a common one unfortunately :) Anyway populating a user profile sounds like a good idea.

In my opinion it should be done much more flexible by using configuration parameters, where you are going to set a reference to Content Type that is dedicated for profile.
Such approach won’t cause breaking change in the codebase and API payloads.

authorProfile might be then atrached to the GET API responses as an additional field if relation between user and profile exist and is enabled by relevant config parameter.

What you think?

You are right. When I extend the User content type from users-permissions by adding profile relation to it, it gets added to the authorUser attribute. Then I only need to specify the "authorUser.profile" in the population array.

I think we can set this up via a config attribute, either as the profile attribute, or either as an option to auto-populate additional fields on authorUser.

For the testing purposes I just tested using this in findAll service function and it works perfectly:

const entitiesRoot = query && query._q ?
            await strapi.query( model.modelName, pluginName)
                .search(criteria, ['authorUser', 'authorUser.profile', 'authorUser.profile.avatar', 'authorUser.profile.cover', 'related', 'reports']) :
            await strapi.query( model.modelName, pluginName)
                .find(criteria, ['authorUser', 'authorUser.profile', 'authorUser.profile.avatar', 'authorUser.profile.cover', 'related', 'reports']);

What do you think?

We're going to implement it for v4 supported version.

Done as part of #113