VirtusLab-Open-Source / strapi-plugin-comments

A plugin for Strapi Headless CMS that provides end to end comments feature with their moderation panel, bad words filtering, abuse reporting and more.
MIT License
405 stars 63 forks source link

[CU-2cq60k0] Maybe populate the author field? #113

Closed be90728 closed 2 years ago

be90728 commented 2 years ago

When the comment author is a registered strapi user For example, I populate authorUser.role, but the field role will be cleared because of buildAuthorModel in sanitizeCommentEntity.

Maybe we can add an author populate field to the plugin configuration page? In this way, there is no need to worry about the leakage of the author's confidential information due to illegal query populate.

cyp3rius commented 2 years ago

Hello @be90728 ,

That kind of request pops up already for v3 (in terms of avatar). We're going to consider extending support for fields population, the real challenge will be to do this on UI by easy to understand way ;)

cyp3rius commented 2 years ago

Released as part of 2.1.0

Tragio commented 2 years ago

@cyp3rius thank you for your awesome work. 🙏 I wonder would be the right way to add the avatar field 🤔

Shouldn't be like this to populate the avatar field? /api/comments/api::test:test:40/flat?populate[authorUser][populate][0]=avatar

cyp3rius commented 2 years ago

@Tragio yep that's the correct way to do this. Both examples should work:

/api/comments/api::page.page:1/flat?populate[authorUser][populate][0]=avatar
/api/comments/api::page.page:1/flat?populate[author][populate][0]=avatar

I got following result in one of my queries:

{
"id": 10,
"content": "Fusce bibendum molestie scelerisque.",
"blocked": false,
"blockedThread": false,
"blockReason": null,
"removed": null,
"approvalStatus": null,
"related":{"id": 1, "Title": "ghghghgh", "Content": null, "createdAt": "2022-03-30T20:54:53.162Z",…},
"createdAt": "2022-04-15T11:26:29.897Z",
"updatedAt": "2022-04-15T11:26:29.897Z",
"threadOf": null,
"gotThread": false,
"author":{
  "id": 1,
  "name": "Test",
  "email": "mziarko+1@virtuslab.com",
  "avatar":{
    "id": 1,
    "name": "Hand-Drawn-Blue-Bird-Avatar.jpeg",
    "alternativeText": "Hand-Drawn-Blue-Bird-Avatar.jpeg",
    "caption": "Hand-Drawn-Blue-Bird-Avatar.jpeg",
    "width": 480,
    "height": 480,
    "formats":{"thumbnail":{"ext": ".jpeg", "url": "/uploads/thumbnail_Hand_Drawn_Blue_Bird_Avatar_c9c6d8cc2b.jpeg",…},
    "hash": "Hand_Drawn_Blue_Bird_Avatar_c9c6d8cc2b",
    "ext": ".jpeg",
    "mime": "image/jpeg",
    "size": 15.13,
    "url": "/uploads/Hand_Drawn_Blue_Bird_Avatar_c9c6d8cc2b.jpeg",
    "previewUrl": null,
    "provider": "local",
    "provider_metadata": null,
    "createdAt": "2022-04-15T11:51:04.979Z",
    "updatedAt": "2022-04-15T11:51:04.979Z"
  }
}
}
Tragio commented 2 years ago

@cyp3rius hmmm strange that it was not working. I updated to version 2.1.2 to see if that was fixed but the plugin now stopped showing in the dashboard and the routes also give 404.

CleanShot 2022-04-25 at 09 48 51@2x

cyp3rius commented 2 years ago

in 2.1.1 there was fixed multiple fields population (the avatar was working without it)

Have you re-builded your admin tool?

cyp3rius commented 2 years ago

@Tragio found it, some files failed to transpile while publish. Fixed that and v2.1.3 got all in place.

Tragio commented 2 years ago

@cyp3rius with 2.1.3 is giving critical error:

[2022-04-25 09:38:09] yarn run v1.22.18
[2022-04-25 09:38:09] $ strapi start
[2022-04-25 09:38:16] [2022-04-25 09:38:16.293] debug: ⛔️ Server wasn't able to start properly.
[2022-04-25 09:38:16] [2022-04-25 09:38:16.297] error: Could not load js config file /app/node_modules/strapi-plugin-comments/strapi-server.js: Cannot find module 'nexus'
[2022-04-25 09:38:16] Require stack:
[2022-04-25 09:38:16] - /app/node_modules/strapi-plugin-comments/server/services/graphql.js
[2022-04-25 09:38:16] - /app/node_modules/strapi-plugin-comments/server/services/index.js
[2022-04-25 09:38:16] - /app/node_modules/strapi-plugin-comments/server/index.js
[2022-04-25 09:38:16] - /app/node_modules/strapi-plugin-comments/strapi-server.js
[2022-04-25 09:38:16] - /app/node_modules/@strapi/strapi/lib/core/app-configuration/load-config-file.js
[2022-04-25 09:38:16] - /app/node_modules/@strapi/strapi/lib/core/app-configuration/config-loader.js
[2022-04-25 09:38:16] - /app/node_modules/@strapi/strapi/lib/core/app-configuration/index.js
[2022-04-25 09:38:16] - /app/node_modules/@strapi/strapi/lib/Strapi.js
[2022-04-25 09:38:16] - /app/node_modules/@strapi/strapi/lib/index.js
[2022-04-25 09:38:16] - /app/node_modules/@strapi/strapi/lib/commands/start.js
[2022-04-25 09:38:16] - /app/node_modules/@strapi/strapi/bin/strapi.js
[2022-04-25 09:38:16] Error: Could not load js config file /app/node_modules/strapi-plugin-comments/strapi-server.js: Cannot find module 'nexus'
[2022-04-25 09:38:16] Require stack:
[2022-04-25 09:38:16] - /app/node_modules/strapi-plugin-comments/server/services/graphql.js
[2022-04-25 09:38:16] - /app/node_modules/strapi-plugin-comments/server/services/index.js
[2022-04-25 09:38:16] - /app/node_modules/strapi-plugin-comments/server/index.js
[2022-04-25 09:38:16] - /app/node_modules/strapi-plugin-comments/strapi-server.js
[2022-04-25 09:38:16] - /app/node_modules/@strapi/strapi/lib/core/app-configuration/load-config-file.js
[2022-04-25 09:38:16] - /app/node_modules/@strapi/strapi/lib/core/app-configuration/config-loader.js
[2022-04-25 09:38:16] - /app/node_modules/@strapi/strapi/lib/core/app-configuration/index.js
[2022-04-25 09:38:16] - /app/node_modules/@strapi/strapi/lib/Strapi.js
[2022-04-25 09:38:16] - /app/node_modules/@strapi/strapi/lib/index.js
[2022-04-25 09:38:16] - /app/node_modules/@strapi/strapi/lib/commands/start.js
[2022-04-25 09:38:16] - /app/node_modules/@strapi/strapi/bin/strapi.js
[2022-04-25 09:38:16]     at loadJsFile (/app/node_modules/@strapi/strapi/lib/core/app-configuration/load-config-file.js:18:11)
[2022-04-25 09:38:16]     at loadFile (/app/node_modules/@strapi/strapi/lib/core/app-configuration/load-config-file.js:35:14)
[2022-04-25 09:38:16]     at Object.loadPlugins (/app/node_modules/@strapi/strapi/lib/core/loaders/plugins/index.js:96:26)
[2022-04-25 09:38:16]     at async Strapi.loadPlugins (/app/node_modules/@strapi/strapi/lib/Strapi.js:284:5)
[2022-04-25 09:38:16]     at async Promise.all (index 1)
[2022-04-25 09:38:16]     at async Strapi.register (/app/node_modules/@strapi/strapi/lib/Strapi.js:316:5)
[2022-04-25 09:38:16]     at async Strapi.load (/app/node_modules/@strapi/strapi/lib/Strapi.js:414:5)
[2022-04-25 09:38:16]     at async Strapi.start (/app/node_modules/@strapi/strapi/lib/Strapi.js:163:9)
[2022-04-25 09:38:16] error Command failed with exit code 1.
[2022-04-25 09:38:16] info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
cyp3rius commented 2 years ago

There was a mess with dependencies seems, I've done some more deep checks and reverted to the same package.json as for 2.1.0 in the new 2.1.4. Issue #136 got different background.

Tragio commented 2 years ago

@cyp3rius so fresh morning, fresh mind. I forgot the avatar was created by me and not as default by Strapi, so it's called thumbnail and not avatar 🤦‍♂️ sorry for wasting your time, and really thank you for your support and awesome work!!

cyp3rius commented 2 years ago

No worries :D You've pushed me to double check the logic and define most strict tests and found the error with multiple fields population which has been solved already ;)

kwiat1990 commented 2 years ago

Hey, I don't quite understand how avatar field is populated? The default user collection type doesn't have this field. And what I'm looking for is to have only url string for avatar as my user are created using social providers. Is it currently possible?