strapi-plugin-comments 2.0.10 → 2.0.11

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 (261) hide show
  1. package/README.md +39 -5
  2. package/admin/src/translations/fr.json +132 -1
  3. package/build/README.md +818 -0
  4. package/build/admin/src/components/ActionButton/styles.d.ts +2 -0
  5. package/build/admin/src/components/ActionButton/styles.js +17 -0
  6. package/build/admin/src/components/ConfirmationDialog/index.d.ts +26 -0
  7. package/build/admin/src/components/ConfirmationDialog/index.js +104 -0
  8. package/build/admin/src/components/DiscussionStatus/index.d.ts +9 -0
  9. package/build/admin/src/components/DiscussionStatus/index.js +38 -0
  10. package/build/admin/src/components/DiscussionThread/index.d.ts +16 -0
  11. package/build/admin/src/components/DiscussionThread/index.js +99 -0
  12. package/build/admin/src/components/DiscussionThreadItem/index.d.ts +9 -0
  13. package/build/admin/src/components/DiscussionThreadItem/index.js +72 -0
  14. package/build/admin/src/components/DiscussionThreadItem/styles.d.ts +4 -0
  15. package/build/admin/src/components/DiscussionThreadItem/styles.js +27 -0
  16. package/build/admin/src/components/DiscussionThreadItemActions/index.d.ts +19 -0
  17. package/build/admin/src/components/DiscussionThreadItemActions/index.js +414 -0
  18. package/build/admin/src/components/DiscussionThreadItemActions/styles.d.ts +2 -0
  19. package/build/admin/src/components/DiscussionThreadItemActions/styles.js +17 -0
  20. package/build/admin/src/components/DiscussionThreadItemApprovalFlowActions/index.d.ts +17 -0
  21. package/build/admin/src/components/DiscussionThreadItemApprovalFlowActions/index.js +103 -0
  22. package/build/admin/src/components/DiscussionThreadItemApprovalFlowActions/styles.d.ts +2 -0
  23. package/build/admin/src/components/DiscussionThreadItemApprovalFlowActions/styles.js +15 -0
  24. package/build/admin/src/components/DiscussionThreadItemFooter/index.d.ts +16 -0
  25. package/build/admin/src/components/DiscussionThreadItemFooter/index.js +73 -0
  26. package/build/admin/src/components/DiscussionThreadItemFooter/styles.d.ts +3 -0
  27. package/build/admin/src/components/DiscussionThreadItemFooter/styles.js +25 -0
  28. package/build/admin/src/components/DiscussionThreadItemReviewAction/index.d.ts +30 -0
  29. package/build/admin/src/components/DiscussionThreadItemReviewAction/index.js +233 -0
  30. package/build/admin/src/components/FormSwitch/index.d.ts +11 -0
  31. package/build/admin/src/components/FormSwitch/index.js +39 -0
  32. package/build/admin/src/components/FormSwitch/styles.d.ts +2 -0
  33. package/build/admin/src/components/FormSwitch/styles.js +16 -0
  34. package/build/admin/src/components/IconButton/styles.d.ts +2 -0
  35. package/build/admin/src/components/IconButton/styles.js +27 -0
  36. package/build/admin/src/components/Initializer/index.d.ts +3 -0
  37. package/build/admin/src/components/Initializer/index.js +14 -0
  38. package/build/admin/src/components/LoadingIndicatorOverlay/index.d.ts +3 -0
  39. package/build/admin/src/components/LoadingIndicatorOverlay/index.js +18 -0
  40. package/build/admin/src/components/LoadingIndicatorOverlay/styles.d.ts +3 -0
  41. package/build/admin/src/components/LoadingIndicatorOverlay/styles.js +32 -0
  42. package/build/admin/src/components/Nav/index.d.ts +7 -0
  43. package/build/admin/src/components/Nav/index.js +72 -0
  44. package/build/admin/src/components/PluginIcon/index.d.ts +3 -0
  45. package/build/admin/src/components/PluginIcon/index.js +13 -0
  46. package/build/admin/src/components/ReportsReviewModal/index.d.ts +21 -0
  47. package/build/admin/src/components/ReportsReviewModal/index.js +72 -0
  48. package/build/admin/src/components/ReportsReviewTable/index.d.ts +21 -0
  49. package/build/admin/src/components/ReportsReviewTable/index.js +321 -0
  50. package/build/admin/src/components/StatusBadge/index.d.ts +11 -0
  51. package/build/admin/src/components/StatusBadge/index.js +22 -0
  52. package/build/admin/src/components/StatusBadge/styles.d.ts +2 -0
  53. package/build/admin/src/components/StatusBadge/styles.js +25 -0
  54. package/build/admin/src/components/TableFilters/index.d.ts +10 -0
  55. package/build/admin/src/components/TableFilters/index.js +109 -0
  56. package/build/admin/src/components/TablePagination/index.d.ts +15 -0
  57. package/build/admin/src/components/TablePagination/index.js +45 -0
  58. package/build/admin/src/components/icons/comments.d.ts +9 -0
  59. package/build/admin/src/components/icons/comments.js +23 -0
  60. package/build/admin/src/components/icons/index.d.ts +6 -0
  61. package/build/admin/src/components/icons/index.js +21 -0
  62. package/build/admin/src/components/icons/lock.d.ts +11 -0
  63. package/build/admin/src/components/icons/lock.js +29 -0
  64. package/build/admin/src/components/icons/review.d.ts +11 -0
  65. package/build/admin/src/components/icons/review.js +31 -0
  66. package/build/admin/src/components/icons/unlock.d.ts +11 -0
  67. package/build/admin/src/components/icons/unlock.js +29 -0
  68. package/build/admin/src/hooks/useConfig.d.ts +8 -0
  69. package/build/admin/src/hooks/useConfig.js +52 -0
  70. package/build/admin/src/index.d.ts +7 -0
  71. package/build/admin/src/index.js +137 -0
  72. package/build/admin/src/pages/App/index.d.ts +4 -0
  73. package/build/admin/src/pages/App/index.js +90 -0
  74. package/build/admin/src/pages/App/reducer/actions.d.ts +8 -0
  75. package/build/admin/src/pages/App/reducer/actions.js +12 -0
  76. package/build/admin/src/pages/App/reducer/constants.d.ts +4 -0
  77. package/build/admin/src/pages/App/reducer/constants.js +7 -0
  78. package/build/admin/src/pages/App/reducer/index.d.ts +14 -0
  79. package/build/admin/src/pages/App/reducer/index.js +31 -0
  80. package/build/admin/src/pages/App/reducer/init.d.ts +3 -0
  81. package/build/admin/src/pages/App/reducer/init.js +9 -0
  82. package/build/admin/src/pages/App/reducer/selectors.d.ts +6 -0
  83. package/build/admin/src/pages/App/reducer/selectors.js +20 -0
  84. package/build/admin/src/pages/App/utils/api.d.ts +2 -0
  85. package/build/admin/src/pages/App/utils/api.js +16 -0
  86. package/build/admin/src/pages/ComingSoonPage/index.d.ts +3 -0
  87. package/build/admin/src/pages/ComingSoonPage/index.js +78 -0
  88. package/build/admin/src/pages/Details/components/DetailsEntity/index.d.ts +18 -0
  89. package/build/admin/src/pages/Details/components/DetailsEntity/index.js +132 -0
  90. package/build/admin/src/pages/Details/components/DetailsFilters/index.d.ts +12 -0
  91. package/build/admin/src/pages/Details/components/DetailsFilters/index.js +48 -0
  92. package/build/admin/src/pages/Details/components/DetailsFilters/styles.d.ts +2 -0
  93. package/build/admin/src/pages/Details/components/DetailsFilters/styles.js +16 -0
  94. package/build/admin/src/pages/Details/index.d.ts +4 -0
  95. package/build/admin/src/pages/Details/index.js +216 -0
  96. package/build/admin/src/pages/Discover/components/DiscoverTableRow/index.d.ts +20 -0
  97. package/build/admin/src/pages/Discover/components/DiscoverTableRow/index.js +344 -0
  98. package/build/admin/src/pages/Discover/components/DiscoverTableRow/styles.d.ts +2 -0
  99. package/build/admin/src/pages/Discover/components/DiscoverTableRow/styles.js +16 -0
  100. package/build/admin/src/pages/Discover/index.d.ts +4 -0
  101. package/build/admin/src/pages/Discover/index.js +332 -0
  102. package/build/admin/src/pages/Discover/utils/api.d.ts +2 -0
  103. package/build/admin/src/pages/Discover/utils/api.js +23 -0
  104. package/build/admin/src/pages/Discover/utils/filtersSchema.d.ts +11 -0
  105. package/build/admin/src/pages/Discover/utils/filtersSchema.js +11 -0
  106. package/build/admin/src/pages/Settings/components/RestartAlert/styles.d.ts +2 -0
  107. package/build/admin/src/pages/Settings/components/RestartAlert/styles.js +16 -0
  108. package/build/admin/src/pages/Settings/index.d.ts +3 -0
  109. package/build/admin/src/pages/Settings/index.js +712 -0
  110. package/build/admin/src/pages/Settings/utils/api.d.ts +7 -0
  111. package/build/admin/src/pages/Settings/utils/api.js +80 -0
  112. package/build/admin/src/pages/utils/api.d.ts +12 -0
  113. package/build/admin/src/pages/utils/api.js +83 -0
  114. package/build/admin/src/permissions.d.ts +28 -0
  115. package/build/admin/src/permissions.js +65 -0
  116. package/build/admin/src/pluginId.d.ts +2 -0
  117. package/build/admin/src/pluginId.js +50 -0
  118. package/build/admin/src/reducers.d.ts +12 -0
  119. package/build/admin/src/reducers.js +14 -0
  120. package/build/admin/src/translations/en.json +132 -0
  121. package/build/admin/src/translations/fr.json +1 -0
  122. package/build/admin/src/translations/pt-BR.json +132 -0
  123. package/build/admin/src/utils/axiosInstance.d.ts +3 -0
  124. package/build/admin/src/utils/axiosInstance.js +37 -0
  125. package/build/admin/src/utils/constants.d.ts +25 -0
  126. package/build/admin/src/utils/constants.js +30 -0
  127. package/build/admin/src/utils/getApiUrl.d.ts +3 -0
  128. package/build/admin/src/utils/getApiUrl.js +6 -0
  129. package/build/admin/src/utils/getMessage.d.ts +4 -0
  130. package/build/admin/src/utils/getMessage.js +25 -0
  131. package/build/admin/src/utils/getRelatedGroups.d.ts +4 -0
  132. package/build/admin/src/utils/getRelatedGroups.js +6 -0
  133. package/build/admin/src/utils/getUrl.d.ts +3 -0
  134. package/build/admin/src/utils/getUrl.js +6 -0
  135. package/build/admin/src/utils/handleAPIError.d.ts +4 -0
  136. package/build/admin/src/utils/handleAPIError.js +20 -0
  137. package/build/admin/src/utils/index.d.ts +12 -0
  138. package/build/admin/src/utils/index.js +97 -0
  139. package/build/admin/src/utils/parseRegExp.d.ts +6 -0
  140. package/build/admin/src/utils/parseRegExp.js +11 -0
  141. package/build/admin/src/utils/renderEntryTitle.d.ts +4 -0
  142. package/build/admin/src/utils/renderEntryTitle.js +16 -0
  143. package/build/admin/src/utils/renderInitials.d.ts +3 -0
  144. package/build/admin/src/utils/renderInitials.js +11 -0
  145. package/build/admin/src/utils/resolveCommentStatus.d.ts +4 -0
  146. package/build/admin/src/utils/resolveCommentStatus.js +32 -0
  147. package/build/admin/src/utils/resolveCommentStatusColor.d.ts +4 -0
  148. package/build/admin/src/utils/resolveCommentStatusColor.js +22 -0
  149. package/build/content-types/comment.d.ts +91 -0
  150. package/build/content-types/comment.js +92 -0
  151. package/build/content-types/index.d.ts +143 -0
  152. package/build/content-types/index.js +18 -0
  153. package/build/content-types/report.d.ts +48 -0
  154. package/build/content-types/report.js +49 -0
  155. package/build/package.json +94 -0
  156. package/build/permissions.d.ts +18 -0
  157. package/build/permissions.js +18 -0
  158. package/build/server/bootstrap.d.ts +4 -0
  159. package/build/server/bootstrap.js +65 -0
  160. package/build/server/config/index.d.ts +4 -0
  161. package/build/server/config/index.js +19 -0
  162. package/build/server/controllers/admin.d.ts +4 -0
  163. package/build/server/controllers/admin.js +124 -0
  164. package/build/server/controllers/client.d.ts +4 -0
  165. package/build/server/controllers/client.js +111 -0
  166. package/build/server/controllers/index.d.ts +6 -0
  167. package/build/server/controllers/index.js +15 -0
  168. package/build/server/controllers/utils/functions.d.ts +7 -0
  169. package/build/server/controllers/utils/functions.js +24 -0
  170. package/build/server/controllers/utils/parsers.d.ts +15 -0
  171. package/build/server/controllers/utils/parsers.js +25 -0
  172. package/build/server/destroy.d.ts +3 -0
  173. package/build/server/destroy.js +3 -0
  174. package/build/server/graphql/index.d.ts +4 -0
  175. package/build/server/graphql/index.js +37 -0
  176. package/build/server/graphql/mutations/createAbuseReport.d.ts +11 -0
  177. package/build/server/graphql/mutations/createAbuseReport.js +27 -0
  178. package/build/server/graphql/mutations/createComment.d.ts +14 -0
  179. package/build/server/graphql/mutations/createComment.js +26 -0
  180. package/build/server/graphql/mutations/index.d.ts +4 -0
  181. package/build/server/graphql/mutations/index.js +28 -0
  182. package/build/server/graphql/mutations/removeComment.d.ts +11 -0
  183. package/build/server/graphql/mutations/removeComment.js +27 -0
  184. package/build/server/graphql/mutations/updateComment.d.ts +11 -0
  185. package/build/server/graphql/mutations/updateComment.js +27 -0
  186. package/build/server/graphql/queries/findAllFlat.d.ts +19 -0
  187. package/build/server/graphql/queries/findAllFlat.js +47 -0
  188. package/build/server/graphql/queries/findAllInHierarchy.d.ts +18 -0
  189. package/build/server/graphql/queries/findAllInHierarchy.js +38 -0
  190. package/build/server/graphql/queries/index.d.ts +4 -0
  191. package/build/server/graphql/queries/index.js +24 -0
  192. package/build/server/graphql/resolvers-config.d.ts +23 -0
  193. package/build/server/graphql/resolvers-config.js +13 -0
  194. package/build/server/graphql/types/comment-author.d.ts +4 -0
  195. package/build/server/graphql/types/comment-author.js +12 -0
  196. package/build/server/graphql/types/comment-nested.d.ts +4 -0
  197. package/build/server/graphql/types/comment-nested.js +19 -0
  198. package/build/server/graphql/types/comment.d.ts +4 -0
  199. package/build/server/graphql/types/comment.js +18 -0
  200. package/build/server/graphql/types/create-comment-author.d.ts +4 -0
  201. package/build/server/graphql/types/create-comment-author.js +12 -0
  202. package/build/server/graphql/types/create-comment.d.ts +4 -0
  203. package/build/server/graphql/types/create-comment.js +12 -0
  204. package/build/server/graphql/types/create-report.d.ts +4 -0
  205. package/build/server/graphql/types/create-report.js +12 -0
  206. package/build/server/graphql/types/id.d.ts +4 -0
  207. package/build/server/graphql/types/id.js +26 -0
  208. package/build/server/graphql/types/identify-comment-author.d.ts +4 -0
  209. package/build/server/graphql/types/identify-comment-author.js +9 -0
  210. package/build/server/graphql/types/index.d.ts +4 -0
  211. package/build/server/graphql/types/index.js +44 -0
  212. package/build/server/graphql/types/remove-comment.d.ts +4 -0
  213. package/build/server/graphql/types/remove-comment.js +11 -0
  214. package/build/server/graphql/types/report-reason.d.ts +4 -0
  215. package/build/server/graphql/types/report-reason.js +12 -0
  216. package/build/server/graphql/types/report.d.ts +4 -0
  217. package/build/server/graphql/types/report.js +14 -0
  218. package/build/server/graphql/types/response-find-all.d.ts +4 -0
  219. package/build/server/graphql/types/response-find-all.js +10 -0
  220. package/build/server/graphql/types/response-meta.d.ts +4 -0
  221. package/build/server/graphql/types/response-meta.js +9 -0
  222. package/build/server/graphql/types/response-pagination.d.ts +4 -0
  223. package/build/server/graphql/types/response-pagination.js +14 -0
  224. package/build/server/graphql/types/update-comment.d.ts +4 -0
  225. package/build/server/graphql/types/update-comment.js +12 -0
  226. package/build/server/index.d.ts +26 -0
  227. package/build/server/index.js +25 -0
  228. package/build/server/register.d.ts +3 -0
  229. package/build/server/register.js +3 -0
  230. package/build/server/routes/admin.d.ts +4 -0
  231. package/build/server/routes/admin.js +118 -0
  232. package/build/server/routes/client.d.ts +4 -0
  233. package/build/server/routes/client.js +54 -0
  234. package/build/server/routes/index.d.ts +11 -0
  235. package/build/server/routes/index.js +21 -0
  236. package/build/server/services/admin.d.ts +5 -0
  237. package/build/server/services/admin.js +296 -0
  238. package/build/server/services/client.d.ts +5 -0
  239. package/build/server/services/client.js +247 -0
  240. package/build/server/services/common.d.ts +5 -0
  241. package/build/server/services/common.js +266 -0
  242. package/build/server/services/graphql.d.ts +5 -0
  243. package/build/server/services/graphql.js +136 -0
  244. package/build/server/services/index.d.ts +8 -0
  245. package/build/server/services/index.js +16 -0
  246. package/build/server/services/utils/functions.d.ts +13 -0
  247. package/build/server/services/utils/functions.js +141 -0
  248. package/build/server/utils/constants.d.ts +9 -0
  249. package/build/server/utils/constants.js +23 -0
  250. package/build/server/utils/error.d.ts +23 -0
  251. package/build/server/utils/error.js +29 -0
  252. package/build/server/utils/functions.d.ts +14 -0
  253. package/build/server/utils/functions.js +50 -0
  254. package/build/strapi-admin.d.ts +3 -0
  255. package/build/strapi-admin.js +10 -0
  256. package/build/strapi-server.d.ts +177 -0
  257. package/build/strapi-server.js +46 -0
  258. package/build/tsconfig.tsbuildinfo +1 -0
  259. package/build/types/contentTypes.d.ts +46 -0
  260. package/build/types/contentTypes.js +3 -0
  261. package/package.json +3 -3
@@ -0,0 +1,296 @@
1
+ "use strict";
2
+ var __importDefault =
3
+ (this && this.__importDefault) ||
4
+ function (mod) {
5
+ return mod && mod.__esModule ? mod : { default: mod };
6
+ };
7
+ const functions_1 = require("./../utils/functions");
8
+ const lodash_1 = require("lodash");
9
+ const error_1 = __importDefault(require("./../utils/error"));
10
+ const functions_2 = require("./utils/functions");
11
+ const constants_1 = require("./../utils/constants");
12
+ module.exports = ({ strapi }) => ({
13
+ getCommonService() {
14
+ return (0, functions_1.getPluginService)("common");
15
+ },
16
+ async config(viaSettingsPage = false) {
17
+ const pluginStore = await this.getCommonService().getPluginStore();
18
+ const config = await pluginStore.get({
19
+ key: "config",
20
+ });
21
+ const additionalConfiguration = {
22
+ regex: Object.keys(constants_1.REGEX).reduce(
23
+ (prev, curr) => ({
24
+ ...prev,
25
+ [curr]: constants_1.REGEX[curr].toString(),
26
+ }),
27
+ {}
28
+ ),
29
+ };
30
+ const getConfigProp = (key) => this.getCommonService().getLocalConfig(key);
31
+ const isGQLPluginEnabled = !(0, lodash_1.isNil)(strapi.plugin("graphql"));
32
+ if (config) {
33
+ return {
34
+ ...config,
35
+ ...additionalConfiguration,
36
+ isGQLPluginEnabled: viaSettingsPage ? isGQLPluginEnabled : undefined,
37
+ };
38
+ }
39
+ const entryLabel = getConfigProp("entryLabel");
40
+ const approvalFlow = getConfigProp("approvalFlow");
41
+ const reportReasons = getConfigProp("reportReasons");
42
+ const result = {
43
+ entryLabel,
44
+ approvalFlow,
45
+ reportReasons,
46
+ ...additionalConfiguration,
47
+ };
48
+ if (viaSettingsPage) {
49
+ const enabledCollections = getConfigProp("enabledCollections");
50
+ const moderatorRoles = getConfigProp("moderatorRoles");
51
+ return {
52
+ ...result,
53
+ enabledCollections,
54
+ moderatorRoles,
55
+ isGQLPluginEnabled,
56
+ };
57
+ }
58
+ return result;
59
+ },
60
+ async updateConfig(body) {
61
+ const pluginStore = await this.getCommonService().getPluginStore();
62
+ await pluginStore.set({ key: "config", value: body });
63
+ return this.config();
64
+ },
65
+ async restoreConfig() {
66
+ const pluginStore = await this.getCommonService().getPluginStore();
67
+ await pluginStore.delete({ key: "config" });
68
+ return this.config();
69
+ },
70
+ async restart() {
71
+ setImmediate(() => strapi.reload());
72
+ },
73
+ async findAll({ related, entity, ...query }) {
74
+ const {
75
+ _q,
76
+ orderBy,
77
+ pageSize = 10,
78
+ page = 1,
79
+ filters,
80
+ } = (0, functions_1.parseParams)(query);
81
+ const defaultWhere = {
82
+ $or: [{ removed: false }, { removed: null }],
83
+ };
84
+ let params = {
85
+ where: !(0, lodash_1.isEmpty)(filters)
86
+ ? {
87
+ ...defaultWhere,
88
+ ...filters,
89
+ }
90
+ : { ...defaultWhere },
91
+ offset: (page - 1) * pageSize,
92
+ limit: pageSize,
93
+ orderBy: orderBy || [{ createdAt: "desc" }],
94
+ };
95
+ if (_q) {
96
+ params = {
97
+ ...params,
98
+ where: {
99
+ ...params.where,
100
+ content: {
101
+ $contains: _q,
102
+ },
103
+ },
104
+ };
105
+ }
106
+ const entities = await strapi.db
107
+ .query((0, functions_2.getModelUid)("comment"))
108
+ .findMany({
109
+ ...params,
110
+ populate: {
111
+ authorUser: true,
112
+ threadOf: true,
113
+ reports: {
114
+ where: {
115
+ resolved: false,
116
+ },
117
+ },
118
+ },
119
+ });
120
+ const total = await strapi.db
121
+ .query((0, functions_2.getModelUid)("comment"))
122
+ .count({
123
+ where: params.where,
124
+ });
125
+ const relatedEntities =
126
+ await this.getCommonService().findRelatedEntitiesFor(entities);
127
+ const result = entities
128
+ .map((_) =>
129
+ (0, functions_2.filterOurResolvedReports)(
130
+ this.getCommonService().sanitizeCommentEntity(_)
131
+ )
132
+ )
133
+ .map((_) =>
134
+ this.getCommonService().mergeRelatedEntityTo(_, relatedEntities)
135
+ );
136
+ const pageCount = Math.floor(total / pageSize);
137
+ return {
138
+ result,
139
+ pagination: {
140
+ page: page,
141
+ pageSize: pageSize,
142
+ pageCount: total % pageSize === 0 ? pageCount : pageCount + 1,
143
+ total,
144
+ },
145
+ };
146
+ },
147
+ async findOneAndThread(id, { removed, ...query }) {
148
+ const defaultWhere = !removed
149
+ ? {
150
+ $or: [{ removed: false }, { removed: null }],
151
+ }
152
+ : {};
153
+ const reportsPopulation = {
154
+ reports: {
155
+ where: {
156
+ resolved: false,
157
+ },
158
+ },
159
+ };
160
+ const defaultPopulate = {
161
+ populate: {
162
+ authorUser: true,
163
+ threadOf: {
164
+ populate: {
165
+ authorUser: true,
166
+ ...reportsPopulation,
167
+ },
168
+ },
169
+ ...reportsPopulation,
170
+ },
171
+ };
172
+ const entity = await strapi.db
173
+ .query((0, functions_2.getModelUid)("comment"))
174
+ .findOne({
175
+ where: {
176
+ id,
177
+ },
178
+ ...defaultPopulate,
179
+ });
180
+ if (!entity) {
181
+ throw new error_1.default(404, "Not found");
182
+ }
183
+ const [relatedUid, relatedStringId] = (0, functions_2.getRelatedGroups)(
184
+ entity.related
185
+ );
186
+ const parsedRelatedId = (0, lodash_1.parseInt)(relatedStringId);
187
+ const relatedId = (0, lodash_1.isNumber)(parsedRelatedId)
188
+ ? parsedRelatedId
189
+ : relatedStringId;
190
+ const relatedEntity = await strapi.db
191
+ .query(relatedUid)
192
+ .findOne({
193
+ where: { id: relatedId },
194
+ })
195
+ .then((_) => ({
196
+ ..._,
197
+ uid: relatedUid,
198
+ }));
199
+ if (!relatedEntity) {
200
+ throw new error_1.default(404, "Relation not found");
201
+ }
202
+ const levelThreadId = entity?.threadOf?.id || null;
203
+ const entitiesOnSameLevel =
204
+ await this.getCommonService().findAllInHierarchy(
205
+ {
206
+ query: {
207
+ ...defaultWhere,
208
+ ...query,
209
+ threadOf: levelThreadId,
210
+ related: entity.related,
211
+ },
212
+ ...defaultPopulate,
213
+ startingFromId: levelThreadId,
214
+ isAdmin: true,
215
+ },
216
+ false
217
+ );
218
+ const selectedEntity = this.getCommonService().sanitizeCommentEntity({
219
+ ...entity,
220
+ threadOf: entity.threadOf || null,
221
+ });
222
+ return {
223
+ entity: relatedEntity,
224
+ selected: selectedEntity,
225
+ level: entitiesOnSameLevel,
226
+ };
227
+ },
228
+ async blockComment(id, forceStatus) {
229
+ const existingEntity = await this.getCommonService().findOne({ id });
230
+ const changedEntity = await strapi.db
231
+ .query((0, functions_2.getModelUid)("comment"))
232
+ .update({
233
+ where: { id },
234
+ data: {
235
+ blocked: !(0, lodash_1.isNil)(forceStatus)
236
+ ? forceStatus
237
+ : !existingEntity.blocked,
238
+ },
239
+ });
240
+ return this.getCommonService().sanitizeCommentEntity(changedEntity);
241
+ },
242
+ async blockCommentThread(id, forceStatus) {
243
+ const existingEntity = await this.getCommonService().findOne({ id });
244
+ const status = !(0, lodash_1.isNil)(forceStatus)
245
+ ? forceStatus
246
+ : !existingEntity.blockedThread;
247
+ const changedEntity = await strapi.db
248
+ .query((0, functions_2.getModelUid)("comment"))
249
+ .update({
250
+ where: { id },
251
+ data: {
252
+ blocked: status,
253
+ blockedThread: status,
254
+ },
255
+ });
256
+ await this.blockNestedThreads(id, changedEntity.blockedThread);
257
+ return this.getCommonService().sanitizeCommentEntity(changedEntity);
258
+ },
259
+ async approveComment(id) {
260
+ const changedEntity = await strapi.db
261
+ .query((0, functions_2.getModelUid)("comment"))
262
+ .update({
263
+ where: { id },
264
+ data: { approvalStatus: constants_1.APPROVAL_STATUS.APPROVED },
265
+ });
266
+ return this.getCommonService().sanitizeCommentEntity(changedEntity);
267
+ },
268
+ async rejectComment(id) {
269
+ const changedEntity = await strapi.db
270
+ .query((0, functions_2.getModelUid)("comment"))
271
+ .update({
272
+ where: { id },
273
+ data: { approvalStatus: constants_1.APPROVAL_STATUS.REJECTED },
274
+ });
275
+ return this.getCommonService().sanitizeCommentEntity(changedEntity);
276
+ },
277
+ async blockNestedThreads(id, blockStatus) {
278
+ return await this.getCommonService().modifiedNestedNestedComments(
279
+ id,
280
+ "blockedThread",
281
+ blockStatus
282
+ );
283
+ },
284
+ async resolveAbuseReport(id, commentId) {
285
+ return strapi.db
286
+ .query((0, functions_2.getModelUid)("comment-report"))
287
+ .update({
288
+ where: {
289
+ id,
290
+ related: commentId,
291
+ },
292
+ data: { resolved: true },
293
+ });
294
+ },
295
+ });
296
+ //# sourceMappingURL=admin.js.map
@@ -0,0 +1,5 @@
1
+ import { StrapiContext } from "strapi-typed";
2
+ import { IServiceClient } from "../../types";
3
+ declare const _default: ({ strapi }: StrapiContext) => IServiceClient;
4
+ export = _default;
5
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1,247 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ const functions_1 = require("./../utils/functions");
6
+ const lodash_1 = require("lodash");
7
+ const error_1 = __importDefault(require("./../utils/error"));
8
+ const functions_2 = require("./utils/functions");
9
+ const constants_1 = require("./../utils/constants");
10
+ module.exports = ({ strapi }) => ({
11
+ getCommonService() {
12
+ return (0, functions_1.getPluginService)("common");
13
+ },
14
+ async create(relation, data, user = undefined) {
15
+ const { content, threadOf } = data;
16
+ const singleRelationFulfilled = relation && constants_1.REGEX.relatedUid.test(relation);
17
+ if (!singleRelationFulfilled) {
18
+ throw new error_1.default(400, `Field "related" got incorrect format, use format like "api::<collection name>.<content type name>:<entity id>"`);
19
+ }
20
+ const [uid, relatedId] = await this.getCommonService().parseRelationString(relation);
21
+ const relatedEntity = await strapi.db
22
+ .query(uid)
23
+ .findOne(relatedId);
24
+ if (!relatedEntity) {
25
+ throw new error_1.default(400, `Relation for field "related" does not exist. Check your payload please.`);
26
+ }
27
+ const approvalFlow = await this.getCommonService().getConfig(constants_1.CONFIG_PARAMS.APPROVAL_FLOW, []);
28
+ const isApprovalFlowEnabled = approvalFlow.includes(uid) || relatedEntity.requireCommentsApproval;
29
+ const linkToThread = !(0, lodash_1.isNil)(threadOf)
30
+ ? await this.getCommonService().findOne({
31
+ id: threadOf,
32
+ related: relation,
33
+ })
34
+ : null;
35
+ const validContext = this.getCommonService().isValidUserContext(user);
36
+ if (linkToThread === null && !(0, lodash_1.isNil)(threadOf)) {
37
+ throw new error_1.default(400, "Thread does not exist");
38
+ }
39
+ if (!validContext) {
40
+ throw (0, functions_2.resolveUserContextError)(user);
41
+ }
42
+ if ((await this.getCommonService().checkBadWords(content)) &&
43
+ singleRelationFulfilled) {
44
+ const { author, ...rest } = data;
45
+ let authorData = {};
46
+ if (validContext && user) {
47
+ authorData = {
48
+ authorUser: user?.id,
49
+ };
50
+ }
51
+ else if (author) {
52
+ if (author.email && !constants_1.REGEX.email.test(author.email)) {
53
+ throw new error_1.default(400, 'Field: "author.email". Author e-mail is not valid value. Check your payload');
54
+ }
55
+ authorData = {
56
+ authorId: author.id,
57
+ authorName: author.name,
58
+ authorEmail: author.email,
59
+ authorAvatar: author.avatar,
60
+ };
61
+ }
62
+ if (!(0, lodash_1.isEmpty)(authorData) &&
63
+ !(authorData.authorId || authorData.authorUser)) {
64
+ throw new error_1.default(400, `Not able to recognise author of a comment. Make sure you've provided "author" property in a payload or authenticated your request properly.`);
65
+ }
66
+ if (isApprovalFlowEnabled &&
67
+ !(0, lodash_1.isNil)(data.approvalStatus) &&
68
+ data.approvalStatus !== constants_1.APPROVAL_STATUS.PENDING) {
69
+ throw new error_1.default(400, "Invalid approval status");
70
+ }
71
+ const entity = await strapi.db
72
+ .query((0, functions_2.getModelUid)("comment"))
73
+ .create({
74
+ data: {
75
+ ...rest,
76
+ ...authorData,
77
+ related: relation,
78
+ approvalStatus: isApprovalFlowEnabled
79
+ ? constants_1.APPROVAL_STATUS.PENDING
80
+ : null,
81
+ },
82
+ populate: {
83
+ authorUser: true,
84
+ },
85
+ });
86
+ return this.getCommonService().sanitizeCommentEntity({
87
+ ...entity,
88
+ threadOf: linkToThread,
89
+ });
90
+ }
91
+ throw new error_1.default(400, "No content received");
92
+ },
93
+ async update(id, relation, data, user = undefined) {
94
+ const { content } = data;
95
+ const singleRelationFulfilled = relation && constants_1.REGEX.relatedUid.test(relation);
96
+ if (!singleRelationFulfilled) {
97
+ throw new error_1.default(400, `Request property "relation" got incorrect format, use format like "api::<collection name>.<content type name>:<entity id>"`);
98
+ }
99
+ await this.getCommonService().parseRelationString(relation);
100
+ const existingEntity = await this.getCommonService().findOne({
101
+ id,
102
+ related: relation,
103
+ });
104
+ const validContext = this.getCommonService().isValidUserContext(user);
105
+ if (!validContext) {
106
+ throw (0, functions_2.resolveUserContextError)(user);
107
+ }
108
+ if ((0, functions_2.isEqualEntity)(existingEntity, data, user) && content) {
109
+ if (await this.getCommonService().checkBadWords(content)) {
110
+ const entity = await strapi.db
111
+ .query((0, functions_2.getModelUid)("comment"))
112
+ .update({
113
+ where: { id },
114
+ data: { content },
115
+ populate: { threadOf: true, authorUser: true },
116
+ });
117
+ return this.getCommonService().sanitizeCommentEntity(entity);
118
+ }
119
+ }
120
+ throw new error_1.default(403, `You're not allowed to take an action on that entity. Make sure you've provided "author" property in a payload or authenticated your request properly.`);
121
+ },
122
+ async reportAbuse(id, relation, payload, user = undefined) {
123
+ if (!this.getCommonService().isValidUserContext(user)) {
124
+ throw (0, functions_2.resolveUserContextError)(user);
125
+ }
126
+ await this.getCommonService().parseRelationString(relation);
127
+ const reportAgainstEntity = await this.getCommonService().findOne({
128
+ id,
129
+ related: relation,
130
+ });
131
+ if (reportAgainstEntity) {
132
+ const entity = await strapi.db
133
+ .query((0, functions_2.getModelUid)("comment-report"))
134
+ .create({
135
+ data: {
136
+ ...payload,
137
+ resolved: false,
138
+ related: id,
139
+ },
140
+ });
141
+ if (entity) {
142
+ const response = {
143
+ ...entity,
144
+ related: reportAgainstEntity,
145
+ };
146
+ try {
147
+ await this.sendAbuseReportEmail(entity.reason, entity.content);
148
+ return response;
149
+ }
150
+ catch (err) {
151
+ return response;
152
+ }
153
+ }
154
+ else {
155
+ throw new error_1.default(500, "Report cannot be created");
156
+ }
157
+ }
158
+ throw new error_1.default(403, `You're not allowed to take an action on that entity. Make sure that comment exist or you've authenticated your request properly.`);
159
+ },
160
+ async markAsRemoved(id, relation, authorId, user = undefined) {
161
+ if (!this.getCommonService().isValidUserContext(user)) {
162
+ throw (0, functions_2.resolveUserContextError)(user);
163
+ }
164
+ const author = user?.id || authorId;
165
+ if (!author) {
166
+ throw new error_1.default(403, `You're not allowed to take an action on that entity. Make sure that you've provided proper "authorId" or authenticated your request properly.`);
167
+ }
168
+ await this.getCommonService().parseRelationString(relation);
169
+ try {
170
+ const byAuthor = user?.id
171
+ ? {
172
+ authorUser: author,
173
+ }
174
+ : {
175
+ authorId: author,
176
+ };
177
+ const entity = await this.getCommonService().findOne({
178
+ id,
179
+ related: relation,
180
+ ...byAuthor,
181
+ });
182
+ if (entity) {
183
+ const removedEntity = await strapi.db
184
+ .query((0, functions_2.getModelUid)("comment"))
185
+ .update({
186
+ where: {
187
+ id,
188
+ related: relation,
189
+ },
190
+ data: { removed: true },
191
+ populate: { threadOf: true, authorUser: true },
192
+ });
193
+ await this.markAsRemovedNested(id, true);
194
+ return this.getCommonService().sanitizeCommentEntity(removedEntity);
195
+ }
196
+ else {
197
+ throw new error_1.default(404, `Entity does not exist or you're not allowed to take an action on it`);
198
+ }
199
+ }
200
+ catch (e) {
201
+ throw new error_1.default(404, `Entity does not exist or you're not allowed to take an action on it`);
202
+ }
203
+ },
204
+ async sendAbuseReportEmail(reason, content) {
205
+ const rolesToBeNotified = (await this.getCommonService().getConfig(constants_1.CONFIG_PARAMS.MODERATOR_ROLES)) || ["strapi-super-admin"];
206
+ const adminUserModel = strapi.db.query("admin::user");
207
+ const emails = await adminUserModel
208
+ .findMany({
209
+ where: {
210
+ roles: { code: rolesToBeNotified },
211
+ },
212
+ })
213
+ .then((items) => items.map((_) => _.email));
214
+ const superAdmin = await strapi.db
215
+ .query("admin::user")
216
+ .findOne({
217
+ where: {
218
+ roles: { code: "strapi-super-admin" },
219
+ },
220
+ });
221
+ if (emails.length > 0) {
222
+ try {
223
+ await strapi
224
+ .plugin("email")
225
+ .service("email")
226
+ .send({
227
+ to: emails,
228
+ from: superAdmin.email,
229
+ subject: "New abuse report on comment",
230
+ text: `
231
+ There was a new abuse report on your app.
232
+ Reason: ${reason}
233
+ Message: ${content}
234
+ `,
235
+ });
236
+ }
237
+ catch (err) {
238
+ strapi.log.error(err);
239
+ throw err;
240
+ }
241
+ }
242
+ },
243
+ async markAsRemovedNested(id, status) {
244
+ return this.getCommonService().modifiedNestedNestedComments(id, "removed", status);
245
+ },
246
+ });
247
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1,5 @@
1
+ import { StrapiContext } from "strapi-typed";
2
+ import { IServiceCommon } from "../../types";
3
+ declare const _default: ({ strapi }: StrapiContext) => IServiceCommon;
4
+ export = _default;
5
+ //# sourceMappingURL=common.d.ts.map