strapi-plugin-comments 2.0.10 β†’ 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (269) hide show
  1. package/README.md +204 -124
  2. package/admin/src/components/ActionButton/styles.d.ts +2 -0
  3. package/admin/src/components/ActionButton/styles.js +13 -8
  4. package/admin/src/components/Avatar/index.d.ts +12 -0
  5. package/admin/src/components/Avatar/index.js +26 -0
  6. package/admin/src/components/ConfirmationDialog/index.d.ts +26 -0
  7. package/admin/src/components/ConfirmationDialog/index.js +36 -55
  8. package/admin/src/components/DiscussionStatus/index.d.ts +9 -0
  9. package/admin/src/components/DiscussionStatus/index.js +22 -31
  10. package/admin/src/components/DiscussionThread/index.d.ts +16 -0
  11. package/admin/src/components/DiscussionThread/index.js +39 -56
  12. package/admin/src/components/DiscussionThreadItem/index.d.ts +9 -0
  13. package/admin/src/components/DiscussionThreadItem/index.js +28 -52
  14. package/admin/src/components/DiscussionThreadItem/styles.d.ts +4 -0
  15. package/admin/src/components/DiscussionThreadItem/styles.js +16 -11
  16. package/admin/src/components/DiscussionThreadItemActions/index.d.ts +19 -0
  17. package/admin/src/components/DiscussionThreadItemActions/index.js +121 -158
  18. package/admin/src/components/DiscussionThreadItemActions/styles.d.ts +2 -0
  19. package/admin/src/components/DiscussionThreadItemActions/styles.js +13 -7
  20. package/admin/src/components/DiscussionThreadItemApprovalFlowActions/index.d.ts +17 -0
  21. package/admin/src/components/DiscussionThreadItemApprovalFlowActions/index.js +38 -48
  22. package/admin/src/components/DiscussionThreadItemApprovalFlowActions/styles.d.ts +2 -0
  23. package/admin/src/components/DiscussionThreadItemApprovalFlowActions/styles.js +12 -6
  24. package/admin/src/components/DiscussionThreadItemFooter/index.d.ts +16 -0
  25. package/admin/src/components/DiscussionThreadItemFooter/index.js +34 -42
  26. package/admin/src/components/DiscussionThreadItemFooter/styles.d.ts +3 -0
  27. package/admin/src/components/DiscussionThreadItemFooter/styles.js +17 -12
  28. package/admin/src/components/DiscussionThreadItemReviewAction/index.d.ts +30 -0
  29. package/admin/src/components/DiscussionThreadItemReviewAction/index.js +77 -91
  30. package/admin/src/components/FormSwitch/index.d.ts +7 -0
  31. package/admin/src/components/FormSwitch/index.js +15 -18
  32. package/admin/src/components/FormSwitch/styles.d.ts +2 -0
  33. package/admin/src/components/FormSwitch/styles.js +14 -8
  34. package/admin/src/components/IconButton/styles.d.ts +2 -0
  35. package/admin/src/components/IconButton/styles.js +16 -9
  36. package/admin/src/components/Initializer/index.d.ts +5 -0
  37. package/admin/src/components/Initializer/index.js +12 -24
  38. package/admin/src/components/LoadingIndicatorOverlay/index.d.ts +3 -0
  39. package/admin/src/components/LoadingIndicatorOverlay/index.js +12 -15
  40. package/admin/src/components/LoadingIndicatorOverlay/styles.d.ts +3 -0
  41. package/admin/src/components/LoadingIndicatorOverlay/styles.js +22 -17
  42. package/admin/src/components/Nav/index.d.ts +7 -0
  43. package/admin/src/components/Nav/index.js +25 -48
  44. package/admin/src/components/PluginIcon/index.d.ts +3 -0
  45. package/admin/src/components/PluginIcon/index.js +10 -12
  46. package/admin/src/components/ReportsReviewModal/index.d.ts +21 -0
  47. package/admin/src/components/ReportsReviewModal/index.js +31 -46
  48. package/admin/src/components/ReportsReviewTable/index.d.ts +21 -0
  49. package/admin/src/components/ReportsReviewTable/index.js +120 -140
  50. package/admin/src/components/StatusBadge/index.d.ts +7 -0
  51. package/admin/src/components/StatusBadge/index.js +12 -17
  52. package/admin/src/components/StatusBadge/styles.d.ts +2 -0
  53. package/admin/src/components/StatusBadge/styles.js +19 -13
  54. package/admin/src/components/TableFilters/index.d.ts +10 -0
  55. package/admin/src/components/TableFilters/index.js +52 -49
  56. package/admin/src/components/TablePagination/index.d.ts +17 -0
  57. package/admin/src/components/TablePagination/index.js +27 -29
  58. package/admin/src/components/icons/comments.d.ts +6 -0
  59. package/admin/src/components/icons/comments.js +11 -8
  60. package/admin/src/components/icons/index.d.ts +6 -0
  61. package/admin/src/components/icons/index.js +15 -6
  62. package/admin/src/components/icons/lock.d.ts +7 -0
  63. package/admin/src/components/icons/lock.js +11 -21
  64. package/admin/src/components/icons/review.d.ts +7 -0
  65. package/admin/src/components/icons/review.js +11 -17
  66. package/admin/src/components/icons/unlock.d.ts +7 -0
  67. package/admin/src/components/icons/unlock.js +11 -19
  68. package/admin/src/hooks/useConfig.d.ts +8 -0
  69. package/admin/src/hooks/useConfig.js +40 -45
  70. package/admin/src/index.d.ts +7 -0
  71. package/admin/src/index.js +98 -92
  72. package/admin/src/pages/App/index.d.ts +4 -0
  73. package/admin/src/pages/App/index.js +43 -67
  74. package/admin/src/pages/App/reducer/actions.d.ts +8 -0
  75. package/admin/src/pages/App/reducer/actions.js +11 -7
  76. package/admin/src/pages/App/reducer/constants.d.ts +4 -0
  77. package/admin/src/pages/App/reducer/constants.js +7 -4
  78. package/admin/src/pages/App/reducer/index.d.ts +9 -0
  79. package/admin/src/pages/App/reducer/index.js +24 -22
  80. package/admin/src/pages/App/reducer/init.d.ts +3 -0
  81. package/admin/src/pages/App/reducer/init.js +6 -4
  82. package/admin/src/pages/App/reducer/selectors.d.ts +6 -0
  83. package/admin/src/pages/App/reducer/selectors.js +17 -34
  84. package/admin/src/pages/App/utils/api.d.ts +2 -0
  85. package/admin/src/pages/App/utils/api.js +14 -11
  86. package/admin/src/pages/ComingSoonPage/index.d.ts +3 -0
  87. package/admin/src/pages/ComingSoonPage/index.js +42 -24
  88. package/admin/src/pages/Details/components/DetailsEntity/index.d.ts +18 -0
  89. package/admin/src/pages/Details/components/DetailsEntity/index.js +49 -77
  90. package/admin/src/pages/Details/components/DetailsFilters/index.d.ts +12 -0
  91. package/admin/src/pages/Details/components/DetailsFilters/index.js +19 -26
  92. package/admin/src/pages/Details/components/DetailsFilters/styles.d.ts +2 -0
  93. package/admin/src/pages/Details/components/DetailsFilters/styles.js +14 -8
  94. package/admin/src/pages/Details/index.d.ts +4 -0
  95. package/admin/src/pages/Details/index.js +94 -133
  96. package/admin/src/pages/Discover/components/DiscoverTableRow/index.d.ts +20 -0
  97. package/admin/src/pages/Discover/components/DiscoverTableRow/index.js +128 -139
  98. package/admin/src/pages/Discover/components/DiscoverTableRow/styles.d.ts +2 -0
  99. package/admin/src/pages/Discover/components/DiscoverTableRow/styles.js +14 -8
  100. package/admin/src/pages/Discover/index.d.ts +4 -0
  101. package/admin/src/pages/Discover/index.js +129 -170
  102. package/admin/src/pages/Discover/utils/api.d.ts +2 -0
  103. package/admin/src/pages/Discover/utils/api.js +15 -13
  104. package/admin/src/pages/Discover/utils/filtersSchema.d.ts +11 -0
  105. package/admin/src/pages/Discover/utils/filtersSchema.js +8 -6
  106. package/admin/src/pages/Settings/components/RestartAlert/styles.d.ts +2 -0
  107. package/admin/src/pages/Settings/components/RestartAlert/styles.js +14 -8
  108. package/admin/src/pages/Settings/index.d.ts +3 -0
  109. package/admin/src/pages/Settings/index.js +225 -391
  110. package/admin/src/pages/Settings/utils/api.d.ts +7 -0
  111. package/admin/src/pages/Settings/utils/api.js +60 -55
  112. package/admin/src/pages/utils/api.d.ts +12 -0
  113. package/admin/src/pages/utils/api.js +58 -53
  114. package/admin/src/permissions.d.ts +28 -0
  115. package/admin/src/permissions.js +31 -17
  116. package/admin/src/pluginId.d.ts +2 -0
  117. package/admin/src/pluginId.js +29 -5
  118. package/admin/src/reducers.d.ts +7 -0
  119. package/admin/src/reducers.js +10 -6
  120. package/admin/src/translations/en.json +131 -131
  121. package/admin/src/translations/fr.json +132 -1
  122. package/admin/src/translations/pt-BR.json +130 -130
  123. package/admin/src/utils/axiosInstance.d.ts +3 -0
  124. package/admin/src/utils/axiosInstance.js +21 -27
  125. package/admin/src/utils/constants.d.ts +25 -0
  126. package/admin/src/utils/constants.js +23 -22
  127. package/admin/src/utils/getApiUrl.d.ts +3 -0
  128. package/admin/src/utils/getApiUrl.js +6 -5
  129. package/admin/src/utils/getMessage.d.ts +4 -0
  130. package/admin/src/utils/getMessage.js +15 -15
  131. package/admin/src/utils/getRelatedGroups.d.ts +4 -0
  132. package/admin/src/utils/getRelatedGroups.js +5 -3
  133. package/admin/src/utils/getUrl.d.ts +3 -0
  134. package/admin/src/utils/getUrl.js +6 -5
  135. package/admin/src/utils/handleAPIError.d.ts +4 -0
  136. package/admin/src/utils/handleAPIError.js +12 -11
  137. package/admin/src/utils/index.d.ts +12 -0
  138. package/admin/src/utils/index.js +29 -11
  139. package/admin/src/utils/parseRegExp.d.ts +6 -0
  140. package/admin/src/utils/parseRegExp.js +6 -5
  141. package/admin/src/utils/renderEntryTitle.d.ts +4 -0
  142. package/admin/src/utils/renderEntryTitle.js +11 -12
  143. package/admin/src/utils/renderInitials.d.ts +3 -0
  144. package/admin/src/utils/renderInitials.js +10 -5
  145. package/admin/src/utils/resolveCommentStatus.d.ts +4 -0
  146. package/admin/src/utils/resolveCommentStatus.js +17 -21
  147. package/admin/src/utils/resolveCommentStatusColor.d.ts +4 -0
  148. package/admin/src/utils/resolveCommentStatusColor.js +19 -19
  149. package/content-types/comment.d.ts +91 -0
  150. package/content-types/comment.js +87 -88
  151. package/content-types/index.d.ts +143 -0
  152. package/content-types/index.js +15 -10
  153. package/content-types/report.d.ts +48 -0
  154. package/content-types/report.js +44 -49
  155. package/package.json +24 -19
  156. package/permissions.d.ts +18 -0
  157. package/permissions.js +12 -13
  158. package/server/bootstrap.d.ts +4 -0
  159. package/server/bootstrap.js +56 -62
  160. package/server/config/index.d.ts +4 -0
  161. package/server/config/index.js +17 -15
  162. package/server/controllers/admin.d.ts +4 -0
  163. package/server/controllers/admin.js +134 -167
  164. package/server/controllers/client.d.ts +4 -0
  165. package/server/controllers/client.js +120 -112
  166. package/server/controllers/index.d.ts +6 -0
  167. package/server/controllers/index.js +12 -8
  168. package/server/controllers/utils/functions.d.ts +7 -0
  169. package/server/controllers/utils/functions.js +22 -17
  170. package/server/controllers/utils/parsers.d.ts +10 -0
  171. package/server/controllers/utils/parsers.js +47 -19
  172. package/server/destroy.d.ts +3 -0
  173. package/server/destroy.js +3 -4
  174. package/server/graphql/index.d.ts +4 -0
  175. package/server/graphql/index.js +27 -25
  176. package/server/graphql/mutations/createAbuseReport.d.ts +11 -0
  177. package/server/graphql/mutations/createAbuseReport.js +22 -24
  178. package/server/graphql/mutations/createComment.d.ts +14 -0
  179. package/server/graphql/mutations/createComment.js +22 -24
  180. package/server/graphql/mutations/index.d.ts +4 -0
  181. package/server/graphql/mutations/index.js +24 -19
  182. package/server/graphql/mutations/removeComment.d.ts +11 -0
  183. package/server/graphql/mutations/removeComment.js +22 -24
  184. package/server/graphql/mutations/updateComment.d.ts +11 -0
  185. package/server/graphql/mutations/updateComment.js +22 -24
  186. package/server/graphql/queries/findAllFlat.d.ts +19 -0
  187. package/server/graphql/queries/findAllFlat.js +36 -34
  188. package/server/graphql/queries/findAllInHierarchy.d.ts +17 -0
  189. package/server/graphql/queries/findAllInHierarchy.js +30 -30
  190. package/server/graphql/queries/index.d.ts +4 -0
  191. package/server/graphql/queries/index.js +20 -17
  192. package/server/graphql/resolvers-config.d.ts +23 -0
  193. package/server/graphql/resolvers-config.js +11 -11
  194. package/server/graphql/types/comment-author.d.ts +4 -0
  195. package/server/graphql/types/comment-author.js +10 -8
  196. package/server/graphql/types/comment-nested.d.ts +4 -0
  197. package/server/graphql/types/comment-nested.js +17 -15
  198. package/server/graphql/types/comment.d.ts +4 -0
  199. package/server/graphql/types/comment.js +16 -14
  200. package/server/graphql/types/create-comment-author.d.ts +4 -0
  201. package/server/graphql/types/create-comment-author.js +10 -8
  202. package/server/graphql/types/create-comment.d.ts +4 -0
  203. package/server/graphql/types/create-comment.js +10 -8
  204. package/server/graphql/types/create-report.d.ts +4 -0
  205. package/server/graphql/types/create-report.js +10 -8
  206. package/server/graphql/types/id.d.ts +4 -0
  207. package/server/graphql/types/id.js +24 -23
  208. package/server/graphql/types/identify-comment-author.d.ts +4 -0
  209. package/server/graphql/types/identify-comment-author.js +7 -5
  210. package/server/graphql/types/index.d.ts +4 -0
  211. package/server/graphql/types/index.js +36 -17
  212. package/server/graphql/types/remove-comment.d.ts +4 -0
  213. package/server/graphql/types/remove-comment.js +9 -7
  214. package/server/graphql/types/report-reason.d.ts +4 -0
  215. package/server/graphql/types/report-reason.js +10 -8
  216. package/server/graphql/types/report.d.ts +4 -0
  217. package/server/graphql/types/report.js +12 -10
  218. package/server/graphql/types/response-find-all.d.ts +4 -0
  219. package/server/graphql/types/response-find-all.js +8 -6
  220. package/server/graphql/types/response-meta.d.ts +4 -0
  221. package/server/graphql/types/response-meta.js +7 -5
  222. package/server/graphql/types/response-pagination.d.ts +4 -0
  223. package/server/graphql/types/response-pagination.js +12 -10
  224. package/server/graphql/types/update-comment.d.ts +4 -0
  225. package/server/graphql/types/update-comment.js +10 -8
  226. package/server/index.d.ts +26 -0
  227. package/server/index.js +24 -21
  228. package/server/register.d.ts +3 -0
  229. package/server/register.js +3 -4
  230. package/server/routes/admin.d.ts +4 -0
  231. package/server/routes/admin.js +103 -109
  232. package/server/routes/client.d.ts +4 -0
  233. package/server/routes/client.js +84 -46
  234. package/server/routes/index.d.ts +11 -0
  235. package/server/routes/index.js +18 -14
  236. package/server/services/admin.d.ts +5 -0
  237. package/server/services/admin.js +134 -161
  238. package/server/services/client.d.ts +5 -0
  239. package/server/services/client.js +164 -168
  240. package/server/services/common.d.ts +5 -0
  241. package/server/services/common.js +192 -202
  242. package/server/services/graphql.d.ts +5 -0
  243. package/server/services/graphql.js +117 -182
  244. package/server/services/index.d.ts +8 -0
  245. package/server/services/index.js +15 -12
  246. package/server/services/utils/functions.d.ts +13 -0
  247. package/server/services/utils/functions.js +105 -109
  248. package/server/utils/constants.d.ts +9 -0
  249. package/server/utils/constants.js +19 -23
  250. package/server/utils/error.d.ts +19 -0
  251. package/server/utils/error.js +23 -18
  252. package/server/utils/functions.d.ts +6 -0
  253. package/server/utils/functions.js +35 -18
  254. package/strapi-admin.d.ts +3 -0
  255. package/strapi-admin.js +8 -3
  256. package/strapi-server.d.ts +177 -0
  257. package/strapi-server.js +43 -46
  258. package/tsconfig.tsbuildinfo +1 -0
  259. package/types/contentTypes.d.ts +48 -0
  260. package/types/contentTypes.js +3 -0
  261. package/.husky/pre-commit +0 -4
  262. package/LICENSE.md +0 -7
  263. package/__mocks__/initSetup.js +0 -108
  264. package/jest.config.js +0 -7
  265. package/server/controllers/utils/__tests__/functions.test.js +0 -43
  266. package/server/controllers/utils/__tests__/parsers.test.js +0 -94
  267. package/server/services/__tests__/common.test.js +0 -399
  268. package/server/services/utils/__tests__/functions.test.js +0 -53
  269. package/server/utils/__tests__/functions.test.js +0 -17
package/README.md CHANGED
@@ -30,9 +30,21 @@
30
30
  <img style="width: 100%; height: auto;" src="public/assets/preview.png" alt="UI preview" />
31
31
  </div>
32
32
 
33
-
34
33
  A plugin for [Strapi Headless CMS](https://github.com/strapi/strapi) that provides end to end comments feature with their moderation panel, bad words filtering, abuse reporting and much more.
35
34
 
35
+ ### Table of Contents
36
+
37
+ 1. [✨ Features](#-features)
38
+ 2. [⏳ Installation](#-installation)
39
+ 3. [πŸ– Requirements](#-requirements)
40
+ 4. [πŸ”§ Configuration](#-configuration)
41
+ - [Settings page](#in-v203-and-newer)
42
+ - [Plugin file](#in-v202-and-older--default-configuration-state-for-v203-and-newer)
43
+ 5. [πŸ•ΈοΈ Public API - REST](#%EF%B8%8F-public-rest-api-specification)
44
+ 6. [πŸ•ΈοΈ Public API - GraphQL](#%EF%B8%8F-public-graphql-specification)
45
+ 7. [🀝 Contributing](#-contributing)
46
+ 8. [πŸ‘¨β€πŸ’» Community support](#-community-support)
47
+
36
48
  ## ✨ Features
37
49
 
38
50
  - **Comments Public REST + GraphQL API:** Elegant, entirely customizable and a fully extensible admin panel.
@@ -49,13 +61,23 @@ A plugin for [Strapi Headless CMS](https://github.com/strapi/strapi) that provid
49
61
 
50
62
  ## ⏳ Installation
51
63
 
64
+ ### Via Strapi Markerplace
65
+
66
+ As a βœ… **verified** plugin by Strapi team we're available on the [**Strapi Marketplace**](https://market.strapi.io/plugins/strapi-plugin-comments) as well as **In-App Marketplace** where you can follow the installation instructions.
67
+
68
+ <div style="margin: 20px 0" align="center">
69
+ <img style="width: 100%; height: auto;" src="public/assets/marketplace.png" alt="Strapi In-App Marketplace" />
70
+ </div>
71
+
72
+ ### Via command line
73
+
52
74
  (Use **yarn** to install this plugin within your Strapi project (recommended). [Install yarn with these docs](https://yarnpkg.com/lang/en/docs/install/).)
53
75
 
54
76
  ```bash
55
77
  yarn add strapi-plugin-comments@latest
56
78
  ```
57
79
 
58
- After successful installation you've to build a fresh package that includes plugin UI. To archive that simply use:
80
+ After successful installation you've to re-build your Strapi instance. To archive that simply use:
59
81
 
60
82
  ```bash
61
83
  yarn build
@@ -70,13 +92,39 @@ yarn develop --watch-admin
70
92
 
71
93
  The **Comments** plugin should appear in the **Plugins** section of Strapi sidebar after you run app again.
72
94
 
73
- Enjoy πŸŽ‰
95
+ As a next step you must configure your the plugin by the way you want to. See [**Configuration**](#πŸ”§-configuration) section.
96
+
97
+ All done. Enjoy πŸŽ‰
98
+
99
+ ### Working in development mode
100
+
101
+ 1. Clone repository
102
+
103
+ ```
104
+ git clone git@github.com:VirtusLab-Open-Source/strapi-plugin-comments.git
105
+ ```
106
+
107
+ 2. Create a soft link in your strapi project to plugin build folder
108
+
109
+ ```sh
110
+ ln -s <your path>/strapi-plugin-comments/build <your path>/strapi-project/src/plugins/comments
111
+ ```
112
+
113
+ 3. Run develop or build command
114
+
115
+ ```ts
116
+ // Watch for file changes
117
+ yarn develop
118
+ // or run build without nodemon
119
+ yarn build:dev
120
+ ```
74
121
 
75
122
  ## πŸ– Requirements
76
123
 
77
124
  Complete installation requirements are exact same as for Strapi itself and can be found in the documentation under [Installation Requirements](https://docs.strapi.io/developer-docs/latest/getting-started/introduction.html).
78
125
 
79
126
  **Minimum environment requirements**
127
+
80
128
  - Node.js `>=14.x.x`
81
129
  - NPM `>=7.x.x`
82
130
 
@@ -84,7 +132,7 @@ In our minimum support we're following [official Node.js releases timelines](htt
84
132
 
85
133
  **Supported Strapi versions**:
86
134
 
87
- - Strapi v4.1.2 (recently tested)
135
+ - Strapi v4.1.7 (recently tested)
88
136
  - Strapi v4.x
89
137
 
90
138
  > This plugin is designed for **Strapi v4** and is not working with v3.x. To get version for **Strapi v3** install version [v1.x](https://github.com/VirtusLab-Open-Source/strapi-plugin-comments/tree/strapi-v3).
@@ -93,92 +141,108 @@ In our minimum support we're following [official Node.js releases timelines](htt
93
141
 
94
142
  ## πŸ”§ Configuration
95
143
 
96
- ### In `v2.0.3` and newest
144
+ To start your journey with **Comments plugin** you must first setup it using the dedicated Settings page (`v2.0.3` and newer) or for any version, put your configuration in `config/plugins.js`. Anyway we're recommending the click-through option where your configuration is going to be properly validated.
145
+
146
+ ### In `v2.0.3` and newer
97
147
 
98
148
  Version `2.0.3` introduce the intuitive **Settings** page which you can easly access via `Strapi Settings -> Section: Comments Plugin -> Configuration`. On dedicated page you will be able to setup all crucial properties which drives the plugin and customize each individual collection for which **Comments plugin** should be enabled.
99
149
 
100
- > *Note*
150
+ On the dedicated page, you will be able to set up all crucial properties which drive the plugin and customize each individual collection for which **Comments plugin** should be enabled.
151
+
152
+ <div style="margin: 20px 0" align="center">
153
+ <img style="width: 100%; height: auto;" src="public/assets/configuration.png" alt="Plugin configuration" />
154
+ </div>
155
+
156
+ > _Note_
101
157
  > Default configuration for your plugin is fetched from `config/plugins.js` or directly from the plugin itself. If you would like to customize the default state to which you might revert, please follow the next section.
102
158
 
103
- ### In `v2.0.2` and older + default configuration state for `v2.0.3` and newest
159
+ ### In `v2.0.2` and older + default configuration state for `v2.0.3` and newer
104
160
 
105
161
  To setup amend default plugin configuration we recommend to put following snippet as part of `config/plugins.js` or `config/<env>/plugins.js` file. If the file does not exist yet, you have to create it manually. If you've got already configurations for other plugins stores by this way, use just the `comments` part within exising `plugins` item.
106
162
 
107
-
108
163
  ```js
109
- module.exports = ({ env }) => ({
110
- //...
111
- comments: {
112
- enabled: true,
113
- config: {
114
- badWords: false,
115
- moderatorRoles: ["Authenticated"],
116
- approvalFlow: ['api::page.page'],
117
- entryLabel: {
118
- '*': ['Title', 'title', 'Name', 'name', 'Subject', 'subject'],
119
- 'api::page.page': ['MyField'],
120
- },
121
- reportReasons: {
122
- 'MY_CUSTOM_REASON': 'MY_CUSTOM_REASON',
123
- },
124
- gql: {
125
- // ...
126
- },
127
- },
128
- },
129
- //...
130
- });
164
+ module.exports = ({ env }) => ({
165
+ //...
166
+ comments: {
167
+ enabled: true,
168
+ config: {
169
+ badWords: false,
170
+ moderatorRoles: ["Authenticated"],
171
+ approvalFlow: ["api::page.page"],
172
+ entryLabel: {
173
+ "*": ["Title", "title", "Name", "name", "Subject", "subject"],
174
+ "api::page.page": ["MyField"],
175
+ },
176
+ reportReasons: {
177
+ MY_CUSTOM_REASON: "MY_CUSTOM_REASON",
178
+ },
179
+ gql: {
180
+ // ...
181
+ },
182
+ },
183
+ },
184
+ //...
185
+ });
131
186
  ```
132
187
 
133
188
  ### Properties
134
- - `badWords` - Enabled support for [bad words filtering](https://www.npmjs.com/package/bad-words). Can be turned off or overwritten using [options reference](https://www.npmjs.com/package/bad-words#constructor). Default value: `true`.
189
+
190
+ - `enabledCollections` - list of Collection and Single Types for which plugin should be enabled in format like `'api::<collection name>.<content type name>'`. By default it's empty and none comments are not enabled for any of type in Strapi.
191
+ - `badWords` - Enabled support for [bad words filtering](https://www.npmjs.com/package/bad-words). Can be turned off or overwritten using [options reference](https://www.npmjs.com/package/bad-words#constructor). Default value: `true`.
135
192
  - `moderatorRoles` - Optional list of names of roles. Users with those roles will be notified by email when a new abuse report is created. This feature requires a built-in [Strapi email plugin](https://docs.strapi.io/developer-docs/latest/plugins/email.html) configured.
136
- - `approvalFlow` - list of Content Types which are supporting approval flow. Values must be in format like `'api::<collection name>.<content type name>'`. For not included, posted comments are going to be immediately visible.
193
+ - `approvalFlow` - list of Content Types which are supporting approval flow. Values must be in format like `'api::<collection name>.<content type name>'`. For not included, posted comments are going to be immediately visible.
137
194
  - `entryLabel` - ordered list of property names per Content Type to generate related entity label. Keys must be in format like `'api::<collection name>.<content type name>'`. Default formatting set as `*`.
138
195
  - `reportReasons` - set of enums you would like to use for issuing abuse reports. Provided by default `'BAD_LANGUAGE'`, `'DISCRIMINATION'` and `'OTHER'`.
139
196
  - `gql` - specific configuration for GraphQL. See [Additional GQL Configuration](#additional-gql-configuration)
140
197
 
141
198
  ## Additional GQL Configuration
199
+
142
200
  All you need to do is to install and enable `@strapi/plugin-graphql` for you instance based on the **[official Strapi v4 docs](https://docs.strapi.io/developer-docs/latest/plugins/graphql.html#configurations)** and decide if you would like to call it by anyone (open for world) or only by authenticated users (Strapi users).
143
201
 
144
202
  > **Important!**
145
203
  > If you're using `config/plugins.js` to configure your plugins , please put `comments` property before `graphql`. Otherwise types are not going to be properly added to GraphQL Schema. That's because of dynamic types which base on plugin configuration which are added on `boostrap` stage, not `register`. This is not valid if you're using `graphql` plugin without any custom configuration, so most of cases in real.
146
204
 
147
205
  ```json
148
- {
149
- // ...
150
- "gql": {
151
- "auth": true, // Default: false
152
- },
153
- // ...
206
+ {
207
+ // ...
208
+ "gql": {
209
+ "auth": true // Default: false
154
210
  }
211
+ // ...
212
+ }
155
213
  ```
156
214
 
157
215
  ### Properties
216
+
158
217
  - `auth` - does GraphQL Queries should be authenticated or not? Default: `false`
159
218
 
160
219
  ### Queries
161
220
 
162
221
  See [available GQL specification section](#public-graphql-specification).
163
222
 
164
- > If `auth` is set to `true` you must provide relevant authentication headers to all requests like for example:
165
- >
223
+ > If `auth` is set to `true` you must provide relevant authentication headers to all requests like for example:
224
+ >
166
225
  > ```json
167
226
  > {
168
- > "Authorization": "Bearer <your token here>"
227
+ > "Authorization": "Bearer <your token here>"
169
228
  > }
170
229
  > ```
171
230
 
172
231
  ## πŸ‘€ RBAC
232
+
173
233
  Plugin provides granular permissions based on Strapi RBAC functionality.
174
234
 
175
235
  ### Mandatory permissions
236
+
176
237
  For any role different than **Super Admin**, to access the **Comments panel** you must set following permissions:
238
+
177
239
  - _Plugins_ -> _Content-type-builder_ -> _Read_ - gives you ability to fetch Content Type schema
178
240
  - _Plugins_ -> _Comments_ -> _Comments: Read_ - gives you the basic read access to **Comments Panel**
179
241
 
180
242
  ### Optional permissions
243
+
181
244
  Feature / Capability focused permissions:
245
+
182
246
  - _Plugins_ -> _Comments_ -> _Comments: Moderate_ - allows you to block, unblock, approve &amp; reject comments
183
247
  - _Plugins_ -> _Comments_ -> _Reports: Read_ - allows you to see the list of issued abuse reports against comments
184
248
  - _Plugins_ -> _Comments_ -> _Reports: Moderate_ - allows you to review (resolve) issued abuse reports against comments
@@ -187,35 +251,36 @@ Feature / Capability focused permissions:
187
251
 
188
252
  ```json
189
253
  {
190
- "id": 1,
191
- "content": "My comment content",
192
- "blocked": null,
193
- "blockedThread": true,
194
- "blockReason": null,
195
- "authorUser": null,
196
- "removed": null,
197
- "approvalStatus": "APPROVED", // Only in case of enabled approval flow. Default: null
198
- "author": {
199
- "id": "207ccfdc-94ba-45eb-979c-790f6f49c392", // For Strapi users id reflects to the format used by your Strapi
200
- "name": "Joe Doe", // For Strapi users it is equal to 'username' field
201
- "email": "jdoe@sample.com",
202
- "avatar": null,
203
- },
204
- "createdAt": "2020-07-14T20:13:01.649Z",
205
- "updatedAt": "2020-07-14T20:13:01.670Z",
206
- "related": {}, // Related content type entity
207
- "reports": [] // Reports issued against this comment
254
+ "id": 1,
255
+ "content": "My comment content",
256
+ "blocked": null,
257
+ "blockedThread": true,
258
+ "blockReason": null,
259
+ "authorUser": null,
260
+ "removed": null,
261
+ "approvalStatus": "APPROVED", // Only in case of enabled approval flow. Default: null
262
+ "author": {
263
+ "id": "207ccfdc-94ba-45eb-979c-790f6f49c392", // For Strapi users id reflects to the format used by your Strapi
264
+ "name": "Joe Doe", // For Strapi users it is equal to 'username' field
265
+ "email": "jdoe@sample.com",
266
+ "avatar": null
267
+ },
268
+ "createdAt": "2020-07-14T20:13:01.649Z",
269
+ "updatedAt": "2020-07-14T20:13:01.670Z",
270
+ "related": {}, // Related content type entity
271
+ "reports": [] // Reports issued against this comment
208
272
  }
209
273
  ```
210
274
 
211
275
  ## πŸ•ΈοΈ Public REST API specification
212
276
 
213
277
  **Strapi Users vs. Generic authors**
278
+
214
279
  > Keep in mind that if you're using auth / authz your requests to setup proper user contexts it has got higher priority in order to take author data comparing to `author` property provided as part of your payload.
215
280
 
216
281
  ### Get Comments
217
282
 
218
- *GraphQL equivalent: [Public GraphQL API -> Get Comments](#get-comments-1)*
283
+ _GraphQL equivalent: [Public GraphQL API -> Get Comments](#get-comments-1)_
219
284
 
220
285
  `GET <host>/api/comments/api::<collection name>.<content type name>:<entity id>`
221
286
 
@@ -227,27 +292,30 @@ Return a hierarchical tree structure of comments for specified instance of Conte
227
292
 
228
293
  ```json
229
294
  [
230
- {
295
+ {
296
+ // -- Comment Model fields ---,
297
+ "children": [
298
+ {
231
299
  // -- Comment Model fields ---,
232
300
  "children": [
233
- {
234
- // -- Comment Model fields ---,
235
- "children": [
236
- // ...
237
- ]
238
- },
239
- // ...
301
+ // ...
240
302
  ]
241
- },
242
- // ...
303
+ }
304
+ // ...
305
+ ]
306
+ }
307
+ // ...
243
308
  ]
244
309
  ```
310
+
245
311
  #### Strapi REST API properties support:
312
+
313
+ - [field selection](https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/rest/populating-fields.html#field-selection)
246
314
  - [sorting](https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/rest/sort-pagination.html#sorting)
247
315
 
248
316
  ### Get Comments (flat structure)
249
317
 
250
- *GraphQL equivalent: [Public GraphQL API -> Get Comments (flat structure)](#get-comments-flat-structure-1)*
318
+ _GraphQL equivalent: [Public GraphQL API -> Get Comments (flat structure)](#get-comments-flat-structure-1)_
251
319
 
252
320
  `GET <host>/api/comments/api::<collection name>.<content type name>:<entity id>/flat`
253
321
 
@@ -261,11 +329,11 @@ Return a flat structure of comments for specified instance of Content Type like
261
329
  {
262
330
  "data": [
263
331
  {
264
- // -- Comment Model fields ---
332
+ // -- Comment Model fields ---
265
333
  },
266
334
  {
267
- // -- Comment Model fields ---
268
- },
335
+ // -- Comment Model fields ---
336
+ }
269
337
  // ...
270
338
  ],
271
339
  "meta": {
@@ -277,17 +345,20 @@ Return a flat structure of comments for specified instance of Content Type like
277
345
  ```
278
346
 
279
347
  **Possible response codes**
348
+
280
349
  - `200` - Successful. Response with list of comments (can be empty)
281
350
  - `400` - Bad Request. Requested list for not valid / not existing Content Type
282
351
 
283
352
  #### Strapi REST API properties support:
353
+
284
354
  - [filtering](https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/rest/filtering-locale-publication.html#filtering)
355
+ - [field selection](https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/rest/populating-fields.html#field-selection)
285
356
  - [sorting](https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/rest/sort-pagination.html#sorting)
286
357
  - [pagination](https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/rest/sort-pagination.html#pagination)
287
358
 
288
359
  ### Post a Comment
289
360
 
290
- *GraphQL equivalent: [Public GraphQL API -> Post a Comments](#post-a-comment-1)*
361
+ _GraphQL equivalent: [Public GraphQL API -> Post a Comments](#post-a-comment-1)_
291
362
 
292
363
  `POST <host>/api/comments/api::<collection name>.<content type name>:<entity id>`
293
364
 
@@ -297,28 +368,29 @@ Posts a Comment related to specified instance of Content Type like for example `
297
368
 
298
369
  **Example request body**
299
370
 
300
- *Generic (non Strapi User)*
371
+ _Generic (non Strapi User)_
372
+
301
373
  ```json
302
374
  {
303
375
  "author": {
304
- "id": "<any ID like value>",
305
- "name": "Joe Doe",
306
- "email": "jdoe@sample.com",
307
- "avatar": "<any image url>"
376
+ "id": "<any ID like value>",
377
+ "name": "Joe Doe",
378
+ "email": "jdoe@sample.com",
379
+ "avatar": "<any image url>"
308
380
  },
309
- "content": "My sample response",
310
- "threadOf": 2, // id of comment we would like to start / continue the thread (Optional)
381
+ "content": "My sample response",
382
+ "threadOf": 2 // id of comment we would like to start / continue the thread (Optional)
311
383
  }
312
384
  ```
313
385
 
314
- *Strapi user*
386
+ _Strapi user_
315
387
 
316
388
  > Author is taken directly from the request context
317
389
 
318
390
  ```json
319
391
  {
320
- "content": "My sample response",
321
- "threadOf": 2, // id of comment we would like to start / continue the thread (Optional)
392
+ "content": "My sample response",
393
+ "threadOf": 2 // id of comment we would like to start / continue the thread (Optional)
322
394
  }
323
395
  ```
324
396
 
@@ -326,17 +398,18 @@ Posts a Comment related to specified instance of Content Type like for example `
326
398
 
327
399
  ```json
328
400
  {
329
- // -- Comment Model fields ---
401
+ // -- Comment Model fields ---
330
402
  }
331
403
  ```
332
404
 
333
405
  **Possible response codes**
406
+
334
407
  - `200` - Successful. Response with created Comment Model
335
408
  - `400` - Bad Request. Missing field values or bad words check fails. Error message will provide relevant reason.
336
409
 
337
410
  ### Update Comment
338
411
 
339
- *GraphQL equivalent: [Public GraphQL API -> Update Comments](#update-comment-1)*
412
+ _GraphQL equivalent: [Public GraphQL API -> Update Comments](#update-comment-1)_
340
413
 
341
414
  `PUT <host>/api/comments/api::<collection name>.<content type name>:<entity id>/comment/<commentId>`
342
415
 
@@ -346,23 +419,24 @@ Updates a specified Comment content based on it `commentId` and related to speci
346
419
 
347
420
  **Example request body**
348
421
 
349
- *Generic (non Strapi User)*
422
+ _Generic (non Strapi User)_
423
+
350
424
  ```json
351
425
  {
352
426
  "author": {
353
- "id": "<any ID like value>"
427
+ "id": "<any ID like value>"
354
428
  },
355
- "content": "My sample response"
429
+ "content": "My sample response"
356
430
  }
357
431
  ```
358
432
 
359
- *Strapi user*
433
+ _Strapi user_
360
434
 
361
435
  > Author is taken directly from the request context
362
436
 
363
437
  ```json
364
438
  {
365
- "content": "My sample response"
439
+ "content": "My sample response"
366
440
  }
367
441
  ```
368
442
 
@@ -370,18 +444,19 @@ Updates a specified Comment content based on it `commentId` and related to speci
370
444
 
371
445
  ```json
372
446
  {
373
- // -- Comment Model fields ---
447
+ // -- Comment Model fields ---
374
448
  }
375
449
  ```
376
450
 
377
451
  **Possible response codes**
452
+
378
453
  - `200` - Successful. Response with updated Comment Model
379
454
  - `400` - Bad Request. Missing field values or bad words check fails. Error message will provide relevant reason.
380
455
  - `409` - Conflict. Occurs when trying to update a non existing or not own comment. Possible cause might be that `authorId` or `authorUser` mismatch with existing comment.
381
456
 
382
457
  ### Delete Comment
383
458
 
384
- *GraphQL equivalent: [Public GraphQL API -> Delete Comment](#delete-comment-1)*
459
+ _GraphQL equivalent: [Public GraphQL API -> Delete Comment](#delete-comment-1)_
385
460
 
386
461
  `DELETE <host>/api/comments/api::<collection name>.<content type name>:<entity id>/comment/<commentId>?authorId=<authorId>`
387
462
 
@@ -393,18 +468,18 @@ Deletes a specified Comment based on it `commentId` and related to specified ins
393
468
 
394
469
  ```json
395
470
  {
396
- // -- Empty Response ---
471
+ // -- Empty Response ---
397
472
  }
398
473
  ```
399
474
 
400
475
  **Possible response codes**
476
+
401
477
  - `200` - Successful with blank Response.
402
478
  - `409` - Conflict. Occurs when trying to delete a non existing comment.
403
479
 
404
-
405
480
  ### Issue Abuse Report against specified Comment
406
481
 
407
- *GraphQL equivalent: [Public GraphQL API -> Issue Abuse Report against specified Comment](#issue-abuse-report-against-specified-comment-1)*
482
+ _GraphQL equivalent: [Public GraphQL API -> Issue Abuse Report against specified Comment](#issue-abuse-report-against-specified-comment-1)_
408
483
 
409
484
  `POST <host>/api/comments/api::<collection name>.<content type name>:<entity id>/comment/<commentId>/report-abuse`
410
485
 
@@ -416,36 +491,39 @@ Reports abuse in specified Comment content based on it `commentId` and related t
416
491
 
417
492
  ```json
418
493
  {
419
- "reason": "<reason enum>",
420
- "content": "This comment is not relevant"
494
+ "reason": "<reason enum>",
495
+ "content": "This comment is not relevant"
421
496
  }
422
497
  ```
423
498
 
424
- *Available reason enums:* `BAD_WORDS`, `OTHER`, `DISCRIMINATION` (want more? See [configuration section](#configuration).)
499
+ _Available reason enums:_ `BAD_WORDS`, `OTHER`, `DISCRIMINATION` (want more? See [configuration section](#configuration).)
425
500
 
426
501
  **Example response body**
427
502
 
428
503
  ```json
429
504
  {
430
- // -- Comment Abuse Report fields ---
505
+ // -- Comment Abuse Report fields ---
431
506
  }
432
507
  ```
433
508
 
434
509
  **Possible response codes**
510
+
435
511
  - `200` - Successful. Response with reported abuse.
436
512
  - `409` - Conflict. Occurs when trying to report an abuse to a non existing comment.
437
513
 
438
514
  ## πŸ•ΈοΈ Public GraphQL specification
439
515
 
440
516
  **Strapi Users vs. Generic authors**
517
+
441
518
  > Keep in mind that if you're using auth / authz your requests to setup proper user contexts it has got higher priority in order to take author data comparing to `author` property provided as part of your payload.
442
519
 
443
520
  **Testing**
521
+
444
522
  > To test all queries and understand the schemas use GraphQL Playground exposed by `@strapi/plugin-graphql` on `http://localhost:1337/graphql`
445
523
 
446
524
  ### Get Comments
447
525
 
448
- *REST API equivalent: [Public REST API -> Get Comments](#get-comments)*
526
+ _REST API equivalent: [Public REST API -> Get Comments](#get-comments)_
449
527
 
450
528
  **Example request**
451
529
 
@@ -455,17 +533,17 @@ query {
455
533
  relation: "api::page.page:1"
456
534
  filters: { content: { contains: "Test" } }
457
535
  ) {
458
- id
459
- content
460
- blocked
461
- threadOf {
462
- id
463
- }
464
- author {
465
- id
466
- name
467
- }
536
+ id
537
+ content
538
+ blocked
539
+ threadOf {
540
+ id
468
541
  }
542
+ author {
543
+ id
544
+ name
545
+ }
546
+ }
469
547
  }
470
548
  ```
471
549
 
@@ -476,7 +554,7 @@ query {
476
554
  "data": {
477
555
  "findAllFlat": [
478
556
  {
479
- "id": 3,
557
+ "id": 3,
480
558
  "content": "Test",
481
559
  "blocked": false,
482
560
  "threadOf": null,
@@ -491,11 +569,12 @@ query {
491
569
  ```
492
570
 
493
571
  #### Strapi GraphQL API properties support:
572
+
494
573
  - [sorting](https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/graphql-api.html#sorting)
495
574
 
496
575
  ### Get Comments (flat structure)
497
576
 
498
- *REST API equivalent: [Public REST API -> Get Comments (flat structure)](#get-comments-flat-structure)*
577
+ _REST API equivalent: [Public REST API -> Get Comments (flat structure)](#get-comments-flat-structure)_
499
578
 
500
579
  **Example request**
501
580
 
@@ -534,7 +613,7 @@ query {
534
613
  {
535
614
  "id": 6,
536
615
  "content": "Text to search for"
537
- },
616
+ }
538
617
  // ...
539
618
  ],
540
619
  "threadOf": null,
@@ -542,7 +621,7 @@ query {
542
621
  "id": "123456",
543
622
  "name": "Joe Doe"
544
623
  }
545
- },
624
+ }
546
625
  // ...
547
626
  ]
548
627
  }
@@ -550,13 +629,14 @@ query {
550
629
  ```
551
630
 
552
631
  #### Strapi GraphQL API properties support:
632
+
553
633
  - [filtering](https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/graphql-api.html#filters)
554
634
  - [sorting](https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/graphql-api.html#sorting)
555
635
  - [pagination](https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/graphql-api.html#pagination)
556
636
 
557
637
  ### Post a Comment
558
638
 
559
- *REST API equivalent: [Public REST API -> Post a Comment](#post-a-comment)*
639
+ _REST API equivalent: [Public REST API -> Post a Comment](#post-a-comment)_
560
640
 
561
641
  **Example request**
562
642
 
@@ -605,7 +685,7 @@ mutation createComment {
605
685
 
606
686
  ### Update Comment
607
687
 
608
- *REST API equivalent: [Public REST API -> Update Comment](#update-comment)*
688
+ _REST API equivalent: [Public REST API -> Update Comment](#update-comment)_
609
689
 
610
690
  **Example request**
611
691
 
@@ -658,16 +738,16 @@ mutation updateComment {
658
738
 
659
739
  ### Delete Comment
660
740
 
661
- *REST API equivalent: [Public REST API -> Delete Comment](#delete-comment)*
741
+ _REST API equivalent: [Public REST API -> Delete Comment](#delete-comment)_
662
742
 
663
743
  **Example request**
664
744
 
665
745
  ```graphql
666
746
  mutation removeComment {
667
747
  removeComment(
668
- input: {
669
- id: 33,
670
- relation: "api::page.page:1",
748
+ input: {
749
+ id: 33
750
+ relation: "api::page.page:1"
671
751
  author: { id: "12345678" } # Optional if using auth / authz requests
672
752
  }
673
753
  ) {
@@ -692,7 +772,7 @@ mutation removeComment {
692
772
 
693
773
  ### Issue Abuse Report against specified Comment
694
774
 
695
- *REST API equivalent: [Public REST API -> Issue Abuse Report against specified Comment](#issue-abuse-report-against-specified-comment)*
775
+ _REST API equivalent: [Public REST API -> Issue Abuse Report against specified Comment](#issue-abuse-report-against-specified-comment)_
696
776
 
697
777
  **Example request body**
698
778
 
@@ -720,7 +800,7 @@ mutation createAbuseReport {
720
800
  }
721
801
  ```
722
802
 
723
- *Available reason enums:* `BAD_WORDS`, `OTHER`, `DISCRIMINATION` (want more? See [configuration section](#configuration).)
803
+ _Available reason enums:_ `BAD_WORDS`, `OTHER`, `DISCRIMINATION` (want more? See [configuration section](#configuration).)
724
804
 
725
805
  **Example response**
726
806