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.
- package/README.md +204 -124
- package/admin/src/components/ActionButton/styles.d.ts +2 -0
- package/admin/src/components/ActionButton/styles.js +13 -8
- package/admin/src/components/Avatar/index.d.ts +12 -0
- package/admin/src/components/Avatar/index.js +26 -0
- package/admin/src/components/ConfirmationDialog/index.d.ts +26 -0
- package/admin/src/components/ConfirmationDialog/index.js +36 -55
- package/admin/src/components/DiscussionStatus/index.d.ts +9 -0
- package/admin/src/components/DiscussionStatus/index.js +22 -31
- package/admin/src/components/DiscussionThread/index.d.ts +16 -0
- package/admin/src/components/DiscussionThread/index.js +39 -56
- package/admin/src/components/DiscussionThreadItem/index.d.ts +9 -0
- package/admin/src/components/DiscussionThreadItem/index.js +28 -52
- package/admin/src/components/DiscussionThreadItem/styles.d.ts +4 -0
- package/admin/src/components/DiscussionThreadItem/styles.js +16 -11
- package/admin/src/components/DiscussionThreadItemActions/index.d.ts +19 -0
- package/admin/src/components/DiscussionThreadItemActions/index.js +121 -158
- package/admin/src/components/DiscussionThreadItemActions/styles.d.ts +2 -0
- package/admin/src/components/DiscussionThreadItemActions/styles.js +13 -7
- package/admin/src/components/DiscussionThreadItemApprovalFlowActions/index.d.ts +17 -0
- package/admin/src/components/DiscussionThreadItemApprovalFlowActions/index.js +38 -48
- package/admin/src/components/DiscussionThreadItemApprovalFlowActions/styles.d.ts +2 -0
- package/admin/src/components/DiscussionThreadItemApprovalFlowActions/styles.js +12 -6
- package/admin/src/components/DiscussionThreadItemFooter/index.d.ts +16 -0
- package/admin/src/components/DiscussionThreadItemFooter/index.js +34 -42
- package/admin/src/components/DiscussionThreadItemFooter/styles.d.ts +3 -0
- package/admin/src/components/DiscussionThreadItemFooter/styles.js +17 -12
- package/admin/src/components/DiscussionThreadItemReviewAction/index.d.ts +30 -0
- package/admin/src/components/DiscussionThreadItemReviewAction/index.js +77 -91
- package/admin/src/components/FormSwitch/index.d.ts +7 -0
- package/admin/src/components/FormSwitch/index.js +15 -18
- package/admin/src/components/FormSwitch/styles.d.ts +2 -0
- package/admin/src/components/FormSwitch/styles.js +14 -8
- package/admin/src/components/IconButton/styles.d.ts +2 -0
- package/admin/src/components/IconButton/styles.js +16 -9
- package/admin/src/components/Initializer/index.d.ts +5 -0
- package/admin/src/components/Initializer/index.js +12 -24
- package/admin/src/components/LoadingIndicatorOverlay/index.d.ts +3 -0
- package/admin/src/components/LoadingIndicatorOverlay/index.js +12 -15
- package/admin/src/components/LoadingIndicatorOverlay/styles.d.ts +3 -0
- package/admin/src/components/LoadingIndicatorOverlay/styles.js +22 -17
- package/admin/src/components/Nav/index.d.ts +7 -0
- package/admin/src/components/Nav/index.js +25 -48
- package/admin/src/components/PluginIcon/index.d.ts +3 -0
- package/admin/src/components/PluginIcon/index.js +10 -12
- package/admin/src/components/ReportsReviewModal/index.d.ts +21 -0
- package/admin/src/components/ReportsReviewModal/index.js +31 -46
- package/admin/src/components/ReportsReviewTable/index.d.ts +21 -0
- package/admin/src/components/ReportsReviewTable/index.js +120 -140
- package/admin/src/components/StatusBadge/index.d.ts +7 -0
- package/admin/src/components/StatusBadge/index.js +12 -17
- package/admin/src/components/StatusBadge/styles.d.ts +2 -0
- package/admin/src/components/StatusBadge/styles.js +19 -13
- package/admin/src/components/TableFilters/index.d.ts +10 -0
- package/admin/src/components/TableFilters/index.js +52 -49
- package/admin/src/components/TablePagination/index.d.ts +17 -0
- package/admin/src/components/TablePagination/index.js +27 -29
- package/admin/src/components/icons/comments.d.ts +6 -0
- package/admin/src/components/icons/comments.js +11 -8
- package/admin/src/components/icons/index.d.ts +6 -0
- package/admin/src/components/icons/index.js +15 -6
- package/admin/src/components/icons/lock.d.ts +7 -0
- package/admin/src/components/icons/lock.js +11 -21
- package/admin/src/components/icons/review.d.ts +7 -0
- package/admin/src/components/icons/review.js +11 -17
- package/admin/src/components/icons/unlock.d.ts +7 -0
- package/admin/src/components/icons/unlock.js +11 -19
- package/admin/src/hooks/useConfig.d.ts +8 -0
- package/admin/src/hooks/useConfig.js +40 -45
- package/admin/src/index.d.ts +7 -0
- package/admin/src/index.js +98 -92
- package/admin/src/pages/App/index.d.ts +4 -0
- package/admin/src/pages/App/index.js +43 -67
- package/admin/src/pages/App/reducer/actions.d.ts +8 -0
- package/admin/src/pages/App/reducer/actions.js +11 -7
- package/admin/src/pages/App/reducer/constants.d.ts +4 -0
- package/admin/src/pages/App/reducer/constants.js +7 -4
- package/admin/src/pages/App/reducer/index.d.ts +9 -0
- package/admin/src/pages/App/reducer/index.js +24 -22
- package/admin/src/pages/App/reducer/init.d.ts +3 -0
- package/admin/src/pages/App/reducer/init.js +6 -4
- package/admin/src/pages/App/reducer/selectors.d.ts +6 -0
- package/admin/src/pages/App/reducer/selectors.js +17 -34
- package/admin/src/pages/App/utils/api.d.ts +2 -0
- package/admin/src/pages/App/utils/api.js +14 -11
- package/admin/src/pages/ComingSoonPage/index.d.ts +3 -0
- package/admin/src/pages/ComingSoonPage/index.js +42 -24
- package/admin/src/pages/Details/components/DetailsEntity/index.d.ts +18 -0
- package/admin/src/pages/Details/components/DetailsEntity/index.js +49 -77
- package/admin/src/pages/Details/components/DetailsFilters/index.d.ts +12 -0
- package/admin/src/pages/Details/components/DetailsFilters/index.js +19 -26
- package/admin/src/pages/Details/components/DetailsFilters/styles.d.ts +2 -0
- package/admin/src/pages/Details/components/DetailsFilters/styles.js +14 -8
- package/admin/src/pages/Details/index.d.ts +4 -0
- package/admin/src/pages/Details/index.js +94 -133
- package/admin/src/pages/Discover/components/DiscoverTableRow/index.d.ts +20 -0
- package/admin/src/pages/Discover/components/DiscoverTableRow/index.js +128 -139
- package/admin/src/pages/Discover/components/DiscoverTableRow/styles.d.ts +2 -0
- package/admin/src/pages/Discover/components/DiscoverTableRow/styles.js +14 -8
- package/admin/src/pages/Discover/index.d.ts +4 -0
- package/admin/src/pages/Discover/index.js +129 -170
- package/admin/src/pages/Discover/utils/api.d.ts +2 -0
- package/admin/src/pages/Discover/utils/api.js +15 -13
- package/admin/src/pages/Discover/utils/filtersSchema.d.ts +11 -0
- package/admin/src/pages/Discover/utils/filtersSchema.js +8 -6
- package/admin/src/pages/Settings/components/RestartAlert/styles.d.ts +2 -0
- package/admin/src/pages/Settings/components/RestartAlert/styles.js +14 -8
- package/admin/src/pages/Settings/index.d.ts +3 -0
- package/admin/src/pages/Settings/index.js +225 -391
- package/admin/src/pages/Settings/utils/api.d.ts +7 -0
- package/admin/src/pages/Settings/utils/api.js +60 -55
- package/admin/src/pages/utils/api.d.ts +12 -0
- package/admin/src/pages/utils/api.js +58 -53
- package/admin/src/permissions.d.ts +28 -0
- package/admin/src/permissions.js +31 -17
- package/admin/src/pluginId.d.ts +2 -0
- package/admin/src/pluginId.js +29 -5
- package/admin/src/reducers.d.ts +7 -0
- package/admin/src/reducers.js +10 -6
- package/admin/src/translations/en.json +131 -131
- package/admin/src/translations/fr.json +132 -1
- package/admin/src/translations/pt-BR.json +130 -130
- package/admin/src/utils/axiosInstance.d.ts +3 -0
- package/admin/src/utils/axiosInstance.js +21 -27
- package/admin/src/utils/constants.d.ts +25 -0
- package/admin/src/utils/constants.js +23 -22
- package/admin/src/utils/getApiUrl.d.ts +3 -0
- package/admin/src/utils/getApiUrl.js +6 -5
- package/admin/src/utils/getMessage.d.ts +4 -0
- package/admin/src/utils/getMessage.js +15 -15
- package/admin/src/utils/getRelatedGroups.d.ts +4 -0
- package/admin/src/utils/getRelatedGroups.js +5 -3
- package/admin/src/utils/getUrl.d.ts +3 -0
- package/admin/src/utils/getUrl.js +6 -5
- package/admin/src/utils/handleAPIError.d.ts +4 -0
- package/admin/src/utils/handleAPIError.js +12 -11
- package/admin/src/utils/index.d.ts +12 -0
- package/admin/src/utils/index.js +29 -11
- package/admin/src/utils/parseRegExp.d.ts +6 -0
- package/admin/src/utils/parseRegExp.js +6 -5
- package/admin/src/utils/renderEntryTitle.d.ts +4 -0
- package/admin/src/utils/renderEntryTitle.js +11 -12
- package/admin/src/utils/renderInitials.d.ts +3 -0
- package/admin/src/utils/renderInitials.js +10 -5
- package/admin/src/utils/resolveCommentStatus.d.ts +4 -0
- package/admin/src/utils/resolveCommentStatus.js +17 -21
- package/admin/src/utils/resolveCommentStatusColor.d.ts +4 -0
- package/admin/src/utils/resolveCommentStatusColor.js +19 -19
- package/content-types/comment.d.ts +91 -0
- package/content-types/comment.js +87 -88
- package/content-types/index.d.ts +143 -0
- package/content-types/index.js +15 -10
- package/content-types/report.d.ts +48 -0
- package/content-types/report.js +44 -49
- package/package.json +24 -19
- package/permissions.d.ts +18 -0
- package/permissions.js +12 -13
- package/server/bootstrap.d.ts +4 -0
- package/server/bootstrap.js +56 -62
- package/server/config/index.d.ts +4 -0
- package/server/config/index.js +17 -15
- package/server/controllers/admin.d.ts +4 -0
- package/server/controllers/admin.js +134 -167
- package/server/controllers/client.d.ts +4 -0
- package/server/controllers/client.js +120 -112
- package/server/controllers/index.d.ts +6 -0
- package/server/controllers/index.js +12 -8
- package/server/controllers/utils/functions.d.ts +7 -0
- package/server/controllers/utils/functions.js +22 -17
- package/server/controllers/utils/parsers.d.ts +10 -0
- package/server/controllers/utils/parsers.js +47 -19
- package/server/destroy.d.ts +3 -0
- package/server/destroy.js +3 -4
- package/server/graphql/index.d.ts +4 -0
- package/server/graphql/index.js +27 -25
- package/server/graphql/mutations/createAbuseReport.d.ts +11 -0
- package/server/graphql/mutations/createAbuseReport.js +22 -24
- package/server/graphql/mutations/createComment.d.ts +14 -0
- package/server/graphql/mutations/createComment.js +22 -24
- package/server/graphql/mutations/index.d.ts +4 -0
- package/server/graphql/mutations/index.js +24 -19
- package/server/graphql/mutations/removeComment.d.ts +11 -0
- package/server/graphql/mutations/removeComment.js +22 -24
- package/server/graphql/mutations/updateComment.d.ts +11 -0
- package/server/graphql/mutations/updateComment.js +22 -24
- package/server/graphql/queries/findAllFlat.d.ts +19 -0
- package/server/graphql/queries/findAllFlat.js +36 -34
- package/server/graphql/queries/findAllInHierarchy.d.ts +17 -0
- package/server/graphql/queries/findAllInHierarchy.js +30 -30
- package/server/graphql/queries/index.d.ts +4 -0
- package/server/graphql/queries/index.js +20 -17
- package/server/graphql/resolvers-config.d.ts +23 -0
- package/server/graphql/resolvers-config.js +11 -11
- package/server/graphql/types/comment-author.d.ts +4 -0
- package/server/graphql/types/comment-author.js +10 -8
- package/server/graphql/types/comment-nested.d.ts +4 -0
- package/server/graphql/types/comment-nested.js +17 -15
- package/server/graphql/types/comment.d.ts +4 -0
- package/server/graphql/types/comment.js +16 -14
- package/server/graphql/types/create-comment-author.d.ts +4 -0
- package/server/graphql/types/create-comment-author.js +10 -8
- package/server/graphql/types/create-comment.d.ts +4 -0
- package/server/graphql/types/create-comment.js +10 -8
- package/server/graphql/types/create-report.d.ts +4 -0
- package/server/graphql/types/create-report.js +10 -8
- package/server/graphql/types/id.d.ts +4 -0
- package/server/graphql/types/id.js +24 -23
- package/server/graphql/types/identify-comment-author.d.ts +4 -0
- package/server/graphql/types/identify-comment-author.js +7 -5
- package/server/graphql/types/index.d.ts +4 -0
- package/server/graphql/types/index.js +36 -17
- package/server/graphql/types/remove-comment.d.ts +4 -0
- package/server/graphql/types/remove-comment.js +9 -7
- package/server/graphql/types/report-reason.d.ts +4 -0
- package/server/graphql/types/report-reason.js +10 -8
- package/server/graphql/types/report.d.ts +4 -0
- package/server/graphql/types/report.js +12 -10
- package/server/graphql/types/response-find-all.d.ts +4 -0
- package/server/graphql/types/response-find-all.js +8 -6
- package/server/graphql/types/response-meta.d.ts +4 -0
- package/server/graphql/types/response-meta.js +7 -5
- package/server/graphql/types/response-pagination.d.ts +4 -0
- package/server/graphql/types/response-pagination.js +12 -10
- package/server/graphql/types/update-comment.d.ts +4 -0
- package/server/graphql/types/update-comment.js +10 -8
- package/server/index.d.ts +26 -0
- package/server/index.js +24 -21
- package/server/register.d.ts +3 -0
- package/server/register.js +3 -4
- package/server/routes/admin.d.ts +4 -0
- package/server/routes/admin.js +103 -109
- package/server/routes/client.d.ts +4 -0
- package/server/routes/client.js +84 -46
- package/server/routes/index.d.ts +11 -0
- package/server/routes/index.js +18 -14
- package/server/services/admin.d.ts +5 -0
- package/server/services/admin.js +134 -161
- package/server/services/client.d.ts +5 -0
- package/server/services/client.js +164 -168
- package/server/services/common.d.ts +5 -0
- package/server/services/common.js +192 -202
- package/server/services/graphql.d.ts +5 -0
- package/server/services/graphql.js +117 -182
- package/server/services/index.d.ts +8 -0
- package/server/services/index.js +15 -12
- package/server/services/utils/functions.d.ts +13 -0
- package/server/services/utils/functions.js +105 -109
- package/server/utils/constants.d.ts +9 -0
- package/server/utils/constants.js +19 -23
- package/server/utils/error.d.ts +19 -0
- package/server/utils/error.js +23 -18
- package/server/utils/functions.d.ts +6 -0
- package/server/utils/functions.js +35 -18
- package/strapi-admin.d.ts +3 -0
- package/strapi-admin.js +8 -3
- package/strapi-server.d.ts +177 -0
- package/strapi-server.js +43 -46
- package/tsconfig.tsbuildinfo +1 -0
- package/types/contentTypes.d.ts +48 -0
- package/types/contentTypes.js +3 -0
- package/.husky/pre-commit +0 -4
- package/LICENSE.md +0 -7
- package/__mocks__/initSetup.js +0 -108
- package/jest.config.js +0 -7
- package/server/controllers/utils/__tests__/functions.test.js +0 -43
- package/server/controllers/utils/__tests__/parsers.test.js +0 -94
- package/server/services/__tests__/common.test.js +0 -399
- package/server/services/utils/__tests__/functions.test.js +0 -53
- package/server/utils/__tests__/functions.test.js +0 -17
|
@@ -1,190 +1,125 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
const virtualScalarAttributes = ['id'];
|
|
7
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
const fp_1 = require("lodash/fp");
|
|
3
|
+
const nexus_1 = require("nexus");
|
|
4
|
+
const virtualScalarAttributes = ["id"];
|
|
8
5
|
module.exports = ({ strapi }) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
6
|
+
const { service: getService } = strapi.plugin("graphql");
|
|
7
|
+
const rootLevelOperators = () => {
|
|
8
|
+
const { operators } = strapi.plugin("graphql").service("builders").filters;
|
|
9
|
+
return [operators.and, operators.or, operators.not];
|
|
10
|
+
};
|
|
11
|
+
const buildContentTypeFilters = (contentType) => {
|
|
12
|
+
const utils = strapi.plugin("graphql").service("utils");
|
|
13
|
+
const extension = strapi.plugin("graphql").service("extension");
|
|
14
|
+
const { getFiltersInputTypeName, getScalarFilterInputTypeName } = utils.naming;
|
|
15
|
+
const { isStrapiScalar, isRelation } = utils.attributes;
|
|
16
|
+
const { attributes } = contentType;
|
|
17
|
+
const filtersTypeName = getFiltersInputTypeName(contentType);
|
|
18
|
+
return (0, nexus_1.inputObjectType)({
|
|
19
|
+
name: filtersTypeName,
|
|
20
|
+
definition(t) {
|
|
21
|
+
const validAttributes = Object.entries(attributes).filter(([attributeName]) => extension
|
|
22
|
+
.shadowCRUD(contentType.uid)
|
|
23
|
+
.field(attributeName)
|
|
24
|
+
.hasFiltersEnabeld());
|
|
25
|
+
const isIDFilterEnabled = extension
|
|
26
|
+
.shadowCRUD(contentType.uid)
|
|
27
|
+
.field("id")
|
|
28
|
+
.hasFiltersEnabeld();
|
|
29
|
+
if (contentType.kind === "collectionType" && isIDFilterEnabled) {
|
|
30
|
+
t.field("id", { type: getScalarFilterInputTypeName("ID") });
|
|
31
|
+
}
|
|
32
|
+
for (const [attributeName, attribute] of validAttributes) {
|
|
33
|
+
if (isStrapiScalar(attribute)) {
|
|
34
|
+
addScalarAttribute(t, attributeName, attribute);
|
|
35
|
+
}
|
|
36
|
+
else if (isRelation(attribute)) {
|
|
37
|
+
addRelationalAttribute(t, attributeName, attribute);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
for (const operator of rootLevelOperators()) {
|
|
41
|
+
operator.add(t, filtersTypeName);
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
const addScalarAttribute = (builder, attributeName, attribute) => {
|
|
47
|
+
const { naming, mappers } = strapi.plugin("graphql").service("utils");
|
|
48
|
+
const gqlType = mappers.strapiScalarToGraphQLScalar(attribute.type);
|
|
49
|
+
builder.field(attributeName, {
|
|
50
|
+
type: naming.getScalarFilterInputTypeName(gqlType),
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
const addRelationalAttribute = (builder, attributeName, attribute) => {
|
|
54
|
+
const utils = strapi.plugin("graphql").service("utils");
|
|
55
|
+
const extension = strapi.plugin("graphql").service("extension");
|
|
56
|
+
const { getFiltersInputTypeName } = utils.naming;
|
|
57
|
+
const { isMorphRelation } = utils.attributes;
|
|
58
|
+
const model = strapi.getModel(attribute.target);
|
|
59
|
+
if (!model || isMorphRelation(attribute))
|
|
60
|
+
return;
|
|
61
|
+
if (extension.shadowCRUD(model.uid).isDisabled())
|
|
62
|
+
return;
|
|
63
|
+
builder.field(attributeName, { type: getFiltersInputTypeName(model) });
|
|
64
|
+
};
|
|
65
|
+
const recursivelyReplaceScalarOperators = (data) => {
|
|
66
|
+
const { operators } = getService("builders").filters;
|
|
67
|
+
if (Array.isArray(data)) {
|
|
68
|
+
return data.map(recursivelyReplaceScalarOperators);
|
|
46
69
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
for (const [attributeName, attribute] of validAttributes) {
|
|
50
|
-
// Handle scalars
|
|
51
|
-
if (isStrapiScalar(attribute)) {
|
|
52
|
-
addScalarAttribute(t, attributeName, attribute);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// Handle relations
|
|
56
|
-
else if (isRelation(attribute)) {
|
|
57
|
-
addRelationalAttribute(t, attributeName, attribute);
|
|
58
|
-
}
|
|
70
|
+
if ((0, fp_1.isDate)(data) || !(0, fp_1.isObject)(data)) {
|
|
71
|
+
return data;
|
|
59
72
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
73
|
+
const result = {};
|
|
74
|
+
for (const [key, value] of Object.entries(data)) {
|
|
75
|
+
const isOperator = !!operators[key];
|
|
76
|
+
const newKey = isOperator ? operators[key].strapiOperator : key;
|
|
77
|
+
result[newKey] = recursivelyReplaceScalarOperators(value);
|
|
64
78
|
}
|
|
65
|
-
|
|
66
|
-
});
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
const addScalarAttribute = (builder, attributeName, attribute) => {
|
|
70
|
-
const { naming, mappers } = strapi.plugin('graphql').service('utils');
|
|
71
|
-
|
|
72
|
-
const gqlType = mappers.strapiScalarToGraphQLScalar(attribute.type);
|
|
73
|
-
|
|
74
|
-
builder.field(attributeName, { type: naming.getScalarFilterInputTypeName(gqlType) });
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
const addRelationalAttribute = (builder, attributeName, attribute) => {
|
|
78
|
-
const utils = strapi.plugin('graphql').service('utils');
|
|
79
|
-
const extension = strapi.plugin('graphql').service('extension');
|
|
80
|
-
const { getFiltersInputTypeName } = utils.naming;
|
|
81
|
-
const { isMorphRelation } = utils.attributes;
|
|
82
|
-
|
|
83
|
-
const model = strapi.getModel(attribute.target);
|
|
84
|
-
|
|
85
|
-
// If there is no model corresponding to the attribute configuration
|
|
86
|
-
// or if the attribute is a polymorphic relation, then ignore it
|
|
87
|
-
if (!model || isMorphRelation(attribute)) return;
|
|
88
|
-
|
|
89
|
-
// If the target model is disabled, then ignore it too
|
|
90
|
-
if (extension.shadowCRUD(model.uid).isDisabled()) return;
|
|
91
|
-
|
|
92
|
-
builder.field(attributeName, { type: getFiltersInputTypeName(model) });
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
const recursivelyReplaceScalarOperators = data => {
|
|
96
|
-
const { operators } = getService('builders').filters;
|
|
97
|
-
|
|
98
|
-
if (Array.isArray(data)) {
|
|
99
|
-
return data.map(recursivelyReplaceScalarOperators);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Note: We need to make an exception for date since GraphQL
|
|
103
|
-
// automatically cast date strings to date instances in args
|
|
104
|
-
if (isDate(data) || !isObject(data)) {
|
|
105
|
-
return data;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const result = {};
|
|
109
|
-
|
|
110
|
-
for (const [key, value] of Object.entries(data)) {
|
|
111
|
-
const isOperator = !!operators[key];
|
|
112
|
-
|
|
113
|
-
const newKey = isOperator ? operators[key].strapiOperator : key;
|
|
114
|
-
|
|
115
|
-
result[newKey] = recursivelyReplaceScalarOperators(value);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return result;
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
const graphQLFiltersToStrapiQuery = (filters, contentType = {}) => {
|
|
122
|
-
const { isStrapiScalar, isMedia, isRelation } = getService('utils').attributes;
|
|
123
|
-
const { operators } = getService('builders').filters;
|
|
124
|
-
|
|
125
|
-
const ROOT_LEVEL_OPERATORS = [operators.and, operators.or, operators.not];
|
|
126
|
-
|
|
127
|
-
// Handle unwanted scenario where there is no filters defined
|
|
128
|
-
if (isNil(filters)) {
|
|
129
|
-
return {};
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// If filters is a collection, then apply the transformation to every item of the list
|
|
133
|
-
if (Array.isArray(filters)) {
|
|
134
|
-
return filters.map(filtersItem =>
|
|
135
|
-
graphQLFiltersToStrapiQuery(filtersItem, contentType)
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const resultMap = {};
|
|
140
|
-
const { attributes } = contentType;
|
|
141
|
-
|
|
142
|
-
const isAttribute = attributeName => {
|
|
143
|
-
return virtualScalarAttributes.includes(attributeName) || has(attributeName, attributes);
|
|
79
|
+
return result;
|
|
144
80
|
};
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
// If it's a scalar attribute
|
|
152
|
-
if (virtualScalarAttributes.includes(key) || isStrapiScalar(attribute)) {
|
|
153
|
-
// Replace (recursively) every GraphQL scalar operator with the associated Strapi operator
|
|
154
|
-
resultMap[key] = recursivelyReplaceScalarOperators(value);
|
|
81
|
+
const graphQLFiltersToStrapiQuery = (filters, contentType = {}) => {
|
|
82
|
+
const { isStrapiScalar, isMedia, isRelation } = getService("utils").attributes;
|
|
83
|
+
const { operators } = getService("builders").filters;
|
|
84
|
+
const ROOT_LEVEL_OPERATORS = [operators.and, operators.or, operators.not];
|
|
85
|
+
if ((0, fp_1.isNil)(filters)) {
|
|
86
|
+
return {};
|
|
155
87
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
else if (isRelation(attribute) || isMedia(attribute)) {
|
|
159
|
-
// Fetch the model from the relation
|
|
160
|
-
const relModel = strapi.getModel(attribute.target);
|
|
161
|
-
|
|
162
|
-
// Recursively apply the mapping to the value using the fetched model,
|
|
163
|
-
// and update the value within `resultMap`
|
|
164
|
-
resultMap[key] = graphQLFiltersToStrapiQuery(value, relModel);
|
|
88
|
+
if (Array.isArray(filters)) {
|
|
89
|
+
return filters.map((filtersItem) => graphQLFiltersToStrapiQuery(filtersItem, contentType));
|
|
165
90
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
91
|
+
const resultMap = {};
|
|
92
|
+
const { attributes } = contentType;
|
|
93
|
+
const isAttribute = (attributeName) => {
|
|
94
|
+
return (virtualScalarAttributes.includes(attributeName) ||
|
|
95
|
+
(0, fp_1.has)(attributeName, attributes));
|
|
96
|
+
};
|
|
97
|
+
for (const [key, value] of Object.entries(filters)) {
|
|
98
|
+
if (isAttribute(key)) {
|
|
99
|
+
const attribute = attributes[key];
|
|
100
|
+
if (virtualScalarAttributes.includes(key) ||
|
|
101
|
+
isStrapiScalar(attribute)) {
|
|
102
|
+
resultMap[key] = recursivelyReplaceScalarOperators(value);
|
|
103
|
+
}
|
|
104
|
+
else if (isRelation(attribute) || isMedia(attribute)) {
|
|
105
|
+
const relModel = strapi.getModel(attribute.target);
|
|
106
|
+
resultMap[key] = graphQLFiltersToStrapiQuery(value, relModel);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
const rootLevelOperator = ROOT_LEVEL_OPERATORS.find((0, fp_1.propEq)("fieldName", key));
|
|
111
|
+
if (rootLevelOperator) {
|
|
112
|
+
const { strapiOperator } = rootLevelOperator;
|
|
113
|
+
resultMap[strapiOperator] = graphQLFiltersToStrapiQuery(value, contentType);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
179
116
|
}
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
};
|
|
190
|
-
};
|
|
117
|
+
return resultMap;
|
|
118
|
+
};
|
|
119
|
+
const serviceMethods = {
|
|
120
|
+
buildContentTypeFilters,
|
|
121
|
+
graphQLFiltersToStrapiQuery,
|
|
122
|
+
};
|
|
123
|
+
return serviceMethods;
|
|
124
|
+
};
|
|
125
|
+
//# sourceMappingURL=graphql.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
admin: ({ strapi }: import("strapi-typed").StrapiContext) => import("../../types").IServiceAdmin;
|
|
3
|
+
client: ({ strapi }: import("strapi-typed").StrapiContext) => import("../../types").IServiceClient;
|
|
4
|
+
common: ({ strapi }: import("strapi-typed").StrapiContext) => import("../../types").IServiceCommon;
|
|
5
|
+
gql: ({ strapi }: import("strapi-typed").StrapiContext) => import("../../types").IServiceGraphQL;
|
|
6
|
+
};
|
|
7
|
+
export default _default;
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
package/server/services/index.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const clientServices = require('./client');
|
|
5
|
-
const commonServices = require('./common');
|
|
6
|
-
const graphQLService = require('./graphql');
|
|
7
|
-
|
|
8
|
-
module.exports = {
|
|
9
|
-
admin: adminServices,
|
|
10
|
-
client: clientServices,
|
|
11
|
-
common: commonServices,
|
|
12
|
-
gql: graphQLService,
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const admin_1 = __importDefault(require("./admin"));
|
|
7
|
+
const client_1 = __importDefault(require("./client"));
|
|
8
|
+
const common_1 = __importDefault(require("./common"));
|
|
9
|
+
const graphql_1 = __importDefault(require("./graphql"));
|
|
10
|
+
exports.default = {
|
|
11
|
+
admin: admin_1.default,
|
|
12
|
+
client: client_1.default,
|
|
13
|
+
common: common_1.default,
|
|
14
|
+
gql: graphql_1.default,
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Id, StrapiUser } from "strapi-typed";
|
|
2
|
+
import { Comment, ToBeFixed } from "../../../types";
|
|
3
|
+
import PluginError from "./../../utils/error";
|
|
4
|
+
export declare const buildNestedStructure: (entities: Array<Comment>, id?: Id | null, field?: string, dropBlockedThreads?: boolean, blockNestedThreads?: boolean) => Array<Comment>;
|
|
5
|
+
export declare const isEqualEntity: (existing: Comment, data: ToBeFixed, user: StrapiUser) => boolean;
|
|
6
|
+
export declare const getRelatedGroups: (related: string) => Array<string>;
|
|
7
|
+
export declare const getModelUid: (name: string) => string;
|
|
8
|
+
export declare const filterOurResolvedReports: (item: Comment) => Comment;
|
|
9
|
+
export declare const convertContentTypeNameToSlug: (str: string) => string;
|
|
10
|
+
export declare const buildAuthorModel: (item: Comment, fieldsToPopulate?: Array<string>) => Comment;
|
|
11
|
+
export declare const buildConfigQueryProp: (prop?: undefined | string | Array<string>) => string;
|
|
12
|
+
export declare const resolveUserContextError: (user: StrapiUser) => PluginError;
|
|
13
|
+
//# sourceMappingURL=functions.d.ts.map
|
|
@@ -1,112 +1,108 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
) =>
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
dropBlockedThreads, entity.blockedThread),
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return strapi
|
|
56
|
-
.plugin('comments')
|
|
57
|
-
.contentTypes[name]?.uid;
|
|
58
|
-
},
|
|
59
|
-
|
|
60
|
-
filterOurResolvedReports: item => (item ? {
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.resolveUserContextError = exports.buildConfigQueryProp = exports.buildAuthorModel = exports.convertContentTypeNameToSlug = exports.filterOurResolvedReports = exports.getModelUid = exports.getRelatedGroups = exports.isEqualEntity = exports.buildNestedStructure = void 0;
|
|
7
|
+
const error_1 = __importDefault(require("./../../utils/error"));
|
|
8
|
+
const constants_1 = require("./../../utils/constants");
|
|
9
|
+
const lodash_1 = require("lodash");
|
|
10
|
+
const buildNestedStructure = (entities, id = null, field = "threadOf", dropBlockedThreads = false, blockNestedThreads = false) => entities
|
|
11
|
+
.filter((entity) => {
|
|
12
|
+
const entityField = (0, lodash_1.get)(entity, field);
|
|
13
|
+
if (entityField === null && id === null) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
let data = entityField;
|
|
17
|
+
if (data && typeof id === "string") {
|
|
18
|
+
data = data.toString();
|
|
19
|
+
}
|
|
20
|
+
return ((data && data === id) ||
|
|
21
|
+
((0, lodash_1.isObject)(entityField) && entityField.id === id));
|
|
22
|
+
})
|
|
23
|
+
.map((entity) => ({
|
|
24
|
+
...entity,
|
|
25
|
+
[field]: undefined,
|
|
26
|
+
related: undefined,
|
|
27
|
+
blockedThread: blockNestedThreads || entity.blockedThread,
|
|
28
|
+
children: entity.blockedThread && dropBlockedThreads
|
|
29
|
+
? []
|
|
30
|
+
: (0, exports.buildNestedStructure)(entities, entity.id, field, dropBlockedThreads, entity.blockedThread),
|
|
31
|
+
}));
|
|
32
|
+
exports.buildNestedStructure = buildNestedStructure;
|
|
33
|
+
const isEqualEntity = (existing, data, user) => {
|
|
34
|
+
const { author: existingAuthor = {} } = existing;
|
|
35
|
+
const { author } = data;
|
|
36
|
+
if (data.approvalStatus && existing.approvalStatus !== data.approvalStatus) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
if (user) {
|
|
40
|
+
const existingUserId = existingAuthor?.id || existingAuthor;
|
|
41
|
+
const receivedUserId = user?.id || author?.id;
|
|
42
|
+
return receivedUserId && existingUserId === receivedUserId;
|
|
43
|
+
}
|
|
44
|
+
return existingAuthor.id === author?.id;
|
|
45
|
+
};
|
|
46
|
+
exports.isEqualEntity = isEqualEntity;
|
|
47
|
+
const getRelatedGroups = (related) => related.split(constants_1.REGEX.relatedUid).filter((s) => s && s.length > 0);
|
|
48
|
+
exports.getRelatedGroups = getRelatedGroups;
|
|
49
|
+
const getModelUid = (name) => {
|
|
50
|
+
return strapi.plugin("comments").contentTypes[name]?.uid;
|
|
51
|
+
};
|
|
52
|
+
exports.getModelUid = getModelUid;
|
|
53
|
+
const filterOurResolvedReports = (item) => item
|
|
54
|
+
? {
|
|
61
55
|
...item,
|
|
62
|
-
reports: (item.reports || []).filter(report => !report.resolved),
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
56
|
+
reports: (item.reports || []).filter((report) => !report.resolved),
|
|
57
|
+
}
|
|
58
|
+
: item;
|
|
59
|
+
exports.filterOurResolvedReports = filterOurResolvedReports;
|
|
60
|
+
const convertContentTypeNameToSlug = (str) => {
|
|
61
|
+
const plainConversion = str.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
|
|
62
|
+
return (0, lodash_1.first)(plainConversion) === "-"
|
|
63
|
+
? plainConversion.slice(1, plainConversion.length)
|
|
64
|
+
: plainConversion;
|
|
65
|
+
};
|
|
66
|
+
exports.convertContentTypeNameToSlug = convertContentTypeNameToSlug;
|
|
67
|
+
const buildAuthorModel = (item, fieldsToPopulate = []) => {
|
|
68
|
+
const { authorUser, authorId, authorName, authorEmail, authorAvatar, ...rest } = item;
|
|
69
|
+
let author = {};
|
|
70
|
+
if (authorUser) {
|
|
71
|
+
author = fieldsToPopulate.reduce((prev, curr) => ({
|
|
72
|
+
...prev,
|
|
73
|
+
[curr]: authorUser[curr],
|
|
74
|
+
}), {
|
|
75
|
+
id: authorUser.id,
|
|
76
|
+
name: authorUser.username,
|
|
77
|
+
email: authorUser.email,
|
|
78
|
+
avatar: (0, lodash_1.isString)(authorUser.avatar) || (0, lodash_1.isObject)(authorUser.avatar)
|
|
79
|
+
? authorUser.avatar
|
|
80
|
+
: undefined,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
else if (authorId) {
|
|
84
|
+
author = {
|
|
85
|
+
id: authorId,
|
|
86
|
+
name: authorName,
|
|
87
|
+
email: authorEmail,
|
|
88
|
+
avatar: authorAvatar,
|
|
93
89
|
};
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
},
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
...rest,
|
|
93
|
+
author: (0, lodash_1.isEmpty)(author) ? undefined : author,
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
exports.buildAuthorModel = buildAuthorModel;
|
|
97
|
+
const buildConfigQueryProp = (prop = "") => ((0, lodash_1.isArray)(prop) ? prop.join(".") : prop ?? "");
|
|
98
|
+
exports.buildConfigQueryProp = buildConfigQueryProp;
|
|
99
|
+
const resolveUserContextError = (user) => {
|
|
100
|
+
if (user) {
|
|
101
|
+
throw new error_1.default(401, "Not authenticated");
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
throw new error_1.default(403, "Not authorized");
|
|
105
|
+
}
|
|
111
106
|
};
|
|
112
|
-
|
|
107
|
+
exports.resolveUserContextError = resolveUserContextError;
|
|
108
|
+
//# sourceMappingURL=functions.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ConfigParamKeys, RegExpCollection } from "../../types";
|
|
2
|
+
export declare const CONFIG_PARAMS: ConfigParamKeys;
|
|
3
|
+
export declare const APPROVAL_STATUS: {
|
|
4
|
+
PENDING: string;
|
|
5
|
+
APPROVED: string;
|
|
6
|
+
REJECTED: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const REGEX: RegExpCollection;
|
|
9
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1,26 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.REGEX = exports.APPROVAL_STATUS = exports.CONFIG_PARAMS = void 0;
|
|
4
|
+
exports.CONFIG_PARAMS = {
|
|
5
|
+
ENABLED_COLLECTIONS: "enabledCollections",
|
|
6
|
+
APPROVAL_FLOW: "approvalFlow",
|
|
7
|
+
ENTRY_LABEL: "entryLabel",
|
|
8
|
+
MODERATOR_ROLES: "moderatorRoles",
|
|
9
|
+
BAD_WORDS: "badWords",
|
|
7
10
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
REJECTED: "REJECTED",
|
|
11
|
+
exports.APPROVAL_STATUS = {
|
|
12
|
+
PENDING: "PENDING",
|
|
13
|
+
APPROVED: "APPROVED",
|
|
14
|
+
REJECTED: "REJECTED",
|
|
13
15
|
};
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
sorting: /^(?<path>[a-z0-9-_\:\.]+)\:+(asc|desc)$/i
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
module.exports = {
|
|
23
|
-
CONFIG_PARAMS,
|
|
24
|
-
APPROVAL_STATUS,
|
|
25
|
-
REGEX,
|
|
16
|
+
exports.REGEX = {
|
|
17
|
+
uid: /^(?<type>[a-z0-9-]+)\:{2}(?<api>[a-z0-9-]+)\.{1}(?<contentType>[a-z0-9-]+)$/i,
|
|
18
|
+
relatedUid: /^(?<uid>[a-z0-9-]+\:{2}[a-z0-9-]+\.[a-z0-9-]+)\:{1}(?<id>[a-z0-9-]+)$/i,
|
|
19
|
+
email: /\S+@\S+\.\S+/,
|
|
20
|
+
sorting: /^(?<path>[a-z0-9-_\:\.]+)\:+(asc|desc)$/i,
|
|
26
21
|
};
|
|
22
|
+
//# sourceMappingURL=constants.js.map
|