strapi-plugin-comments 2.2.10 → 2.2.12
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 +116 -23
- package/admin/src/custom-fields/comments/components/input/input.js +5 -5
- package/admin/src/custom-fields/comments/components/input/utils.d.ts +6 -15
- package/admin/src/custom-fields/comments/components/input/utils.js +8 -20
- package/admin/src/index.js +1 -1
- package/admin/src/translations/index.d.ts +1 -1
- package/admin/src/translations/index.js +2 -0
- package/admin/src/translations/pl.json +192 -0
- package/package.json +3 -3
- package/server/controllers/client.js +18 -0
- package/server/graphql/queries/findAllPerAuthor.d.ts +21 -0
- package/server/graphql/queries/findAllPerAuthor.js +40 -0
- package/server/graphql/queries/index.js +2 -0
- package/server/graphql/types/comment-author-type.d.ts +4 -0
- package/server/graphql/types/comment-author-type.js +8 -0
- package/server/graphql/types/index.js +4 -0
- package/server/graphql/types/response-find-all-per-author.d.ts +4 -0
- package/server/graphql/types/response-find-all-per-author.js +9 -0
- package/server/routes/client.js +28 -0
- package/server/services/admin.js +1 -1
- package/server/services/client.js +2 -1
- package/server/services/common.js +31 -49
- package/server/services/utils/parsers.d.ts +6 -0
- package/server/services/utils/parsers.js +63 -0
- package/server/utils/constants.d.ts +4 -0
- package/server/utils/constants.js +5 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
const lodash_1 = require("lodash");
|
|
6
|
+
const comment_1 = __importDefault(require("../../../content-types/comment"));
|
|
7
|
+
const parsers_1 = require("../../controllers/utils/parsers");
|
|
8
|
+
const functions_1 = require("../../utils/functions");
|
|
9
|
+
const constants_1 = require("../../utils/constants");
|
|
10
|
+
module.exports = ({ strapi, nexus }) => {
|
|
11
|
+
const { nonNull, intArg, arg } = nexus;
|
|
12
|
+
const { service: getService } = strapi.plugin("graphql");
|
|
13
|
+
const { args } = getService("internals");
|
|
14
|
+
const { naming: { getFiltersInputTypeName }, } = getService("utils");
|
|
15
|
+
return {
|
|
16
|
+
type: "ResponseFindAllPerAuthor",
|
|
17
|
+
args: {
|
|
18
|
+
authorId: nonNull(intArg()),
|
|
19
|
+
authorType: arg({ type: 'AuthorType' }),
|
|
20
|
+
filters: getFiltersInputTypeName(comment_1.default),
|
|
21
|
+
pagination: args.PaginationArg,
|
|
22
|
+
sort: args.SortArg,
|
|
23
|
+
},
|
|
24
|
+
async resolve(obj, args) {
|
|
25
|
+
const { authorId, authorType, filters, sort, pagination } = args;
|
|
26
|
+
const isStrapiUser = authorType !== constants_1.AUTHOR_TYPE.GENERIC;
|
|
27
|
+
return await (0, functions_1.getPluginService)("common").findAllPerAuthor((0, parsers_1.flatInput)({
|
|
28
|
+
query: (0, functions_1.getPluginService)("gql").graphQLFiltersToStrapiQuery(filters, comment_1.default),
|
|
29
|
+
sort,
|
|
30
|
+
pagination: pagination
|
|
31
|
+
? {
|
|
32
|
+
...pagination,
|
|
33
|
+
withCount: !(0, lodash_1.isEmpty)(pagination),
|
|
34
|
+
}
|
|
35
|
+
: undefined,
|
|
36
|
+
}), authorId, isStrapiUser);
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=findAllPerAuthor.js.map
|
|
@@ -4,10 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
const findAllFlat_1 = __importDefault(require("./findAllFlat"));
|
|
6
6
|
const findAllInHierarchy_1 = __importDefault(require("./findAllInHierarchy"));
|
|
7
|
+
const findAllPerAuthor_1 = __importDefault(require("./findAllPerAuthor"));
|
|
7
8
|
module.exports = (context) => {
|
|
8
9
|
const queries = {
|
|
9
10
|
findAllFlat: findAllFlat_1.default,
|
|
10
11
|
findAllInHierarchy: findAllInHierarchy_1.default,
|
|
12
|
+
findAllPerAuthor: findAllPerAuthor_1.default,
|
|
11
13
|
};
|
|
12
14
|
return context.nexus.extendType({
|
|
13
15
|
type: "Query",
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const constants_1 = require("../../utils/constants");
|
|
3
|
+
module.exports = ({ nexus }) => nexus.enumType({
|
|
4
|
+
name: 'AuthorType',
|
|
5
|
+
description: "User type which was the author of comment - Strapi built-in or generic",
|
|
6
|
+
members: Object.values(constants_1.AUTHOR_TYPE),
|
|
7
|
+
});
|
|
8
|
+
//# sourceMappingURL=comment-author-type.js.map
|
|
@@ -6,6 +6,7 @@ const id_1 = __importDefault(require("./id"));
|
|
|
6
6
|
const comment_1 = __importDefault(require("./comment"));
|
|
7
7
|
const comment_nested_1 = __importDefault(require("./comment-nested"));
|
|
8
8
|
const comment_author_1 = __importDefault(require("./comment-author"));
|
|
9
|
+
const comment_author_type_1 = __importDefault(require("./comment-author-type"));
|
|
9
10
|
const create_comment_1 = __importDefault(require("./create-comment"));
|
|
10
11
|
const create_comment_author_1 = __importDefault(require("./create-comment-author"));
|
|
11
12
|
const update_comment_1 = __importDefault(require("./update-comment"));
|
|
@@ -17,11 +18,13 @@ const create_report_1 = __importDefault(require("./create-report"));
|
|
|
17
18
|
const response_pagination_1 = __importDefault(require("./response-pagination"));
|
|
18
19
|
const response_meta_1 = __importDefault(require("./response-meta"));
|
|
19
20
|
const response_find_all_1 = __importDefault(require("./response-find-all"));
|
|
21
|
+
const response_find_all_per_author_1 = __importDefault(require("./response-find-all-per-author"));
|
|
20
22
|
const typesFactories = [
|
|
21
23
|
id_1.default,
|
|
22
24
|
comment_1.default,
|
|
23
25
|
comment_nested_1.default,
|
|
24
26
|
comment_author_1.default,
|
|
27
|
+
comment_author_type_1.default,
|
|
25
28
|
create_comment_1.default,
|
|
26
29
|
create_comment_author_1.default,
|
|
27
30
|
update_comment_1.default,
|
|
@@ -33,6 +36,7 @@ const typesFactories = [
|
|
|
33
36
|
response_pagination_1.default,
|
|
34
37
|
response_meta_1.default,
|
|
35
38
|
response_find_all_1.default,
|
|
39
|
+
response_find_all_per_author_1.default,
|
|
36
40
|
];
|
|
37
41
|
module.exports = (context) => typesFactories.map((factory) => factory(context));
|
|
38
42
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
module.exports = ({ nexus }) => nexus.objectType({
|
|
3
|
+
name: "ResponseFindAllPerAuthor",
|
|
4
|
+
definition(t) {
|
|
5
|
+
t.list.field("data", { type: "CommentSingle" });
|
|
6
|
+
t.field("meta", { type: "ResponseMeta" });
|
|
7
|
+
},
|
|
8
|
+
});
|
|
9
|
+
//# sourceMappingURL=response-find-all-per-author.js.map
|
package/server/routes/client.js
CHANGED
|
@@ -85,6 +85,34 @@ const routes = [
|
|
|
85
85
|
},
|
|
86
86
|
},
|
|
87
87
|
},
|
|
88
|
+
{
|
|
89
|
+
method: "GET",
|
|
90
|
+
path: "/author/:id",
|
|
91
|
+
handler: "client.findAllPerAuthor",
|
|
92
|
+
config: {
|
|
93
|
+
policies: [],
|
|
94
|
+
description: "Find all comments created by Strapi user",
|
|
95
|
+
tag: {
|
|
96
|
+
plugin: "comments",
|
|
97
|
+
name: "Comments",
|
|
98
|
+
actionType: "find",
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
method: "GET",
|
|
104
|
+
path: "/author/:id/:type",
|
|
105
|
+
handler: "client.findAllPerAuthor",
|
|
106
|
+
config: {
|
|
107
|
+
policies: [],
|
|
108
|
+
description: "Find all comments created by specified type of user",
|
|
109
|
+
tag: {
|
|
110
|
+
plugin: "comments",
|
|
111
|
+
name: "Comments",
|
|
112
|
+
actionType: "find",
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
},
|
|
88
116
|
];
|
|
89
117
|
exports.default = routes;
|
|
90
118
|
//# sourceMappingURL=client.js.map
|
package/server/services/admin.js
CHANGED
|
@@ -18,8 +18,9 @@ module.exports = ({ strapi }) => ({
|
|
|
18
18
|
throw new error_1.default(400, `Field "related" got incorrect format, use format like "api::<collection name>.<content type name>:<entity id>"`);
|
|
19
19
|
}
|
|
20
20
|
const [uid, relatedId] = await this.getCommonService().parseRelationString(relation);
|
|
21
|
+
const enabledCollections = await this.getCommonService().getConfig(constants_1.CONFIG_PARAMS.ENABLED_COLLECTIONS, []);
|
|
21
22
|
const isEnabledCollection = await this.getCommonService().isEnabledCollection(uid);
|
|
22
|
-
if (!isEnabledCollection) {
|
|
23
|
+
if (enabledCollections.length > 0 && !isEnabledCollection) {
|
|
23
24
|
throw new error_1.default(400, `Field "related" refer to not enabled collection. Please amend the plugin settings and try again`);
|
|
24
25
|
}
|
|
25
26
|
const relatedEntity = await strapi.db
|
|
@@ -7,6 +7,7 @@ const lodash_1 = require("lodash");
|
|
|
7
7
|
const constants_1 = require("../utils/constants");
|
|
8
8
|
const error_1 = __importDefault(require("./../utils/error"));
|
|
9
9
|
const functions_1 = require("./utils/functions");
|
|
10
|
+
const parsers_1 = require("./utils/parsers");
|
|
10
11
|
const PAGE_SIZE = 10;
|
|
11
12
|
module.exports = ({ strapi }) => ({
|
|
12
13
|
async getConfig(prop, defaultValue, useLocal = false) {
|
|
@@ -41,54 +42,9 @@ module.exports = ({ strapi }) => ({
|
|
|
41
42
|
const doNotPopulateAuthor = isAdmin
|
|
42
43
|
? []
|
|
43
44
|
: await this.getConfig(constants_1.CONFIG_PARAMS.AUTHOR_BLOCKED_PROPS, []);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
...queryExtension,
|
|
48
|
-
orderBy: ((0, lodash_1.isString)(sort) ? [sort] : sort)
|
|
49
|
-
.map((_) => (constants_1.REGEX.sorting.test(_) ? _ : `${_}:asc`))
|
|
50
|
-
.reduce((prev, curr) => {
|
|
51
|
-
const [type = "asc", ...parts] = curr.split(":").reverse();
|
|
52
|
-
return { ...(0, lodash_1.set)(prev, parts.reverse().join("."), type) };
|
|
53
|
-
}, {}),
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
if (!(0, lodash_1.isNil)(fields)) {
|
|
57
|
-
queryExtension = {
|
|
58
|
-
...queryExtension,
|
|
59
|
-
select: (0, lodash_1.isArray)(fields) ? (0, lodash_1.uniq)([...fields, ...defaultSelect]) : fields,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
let meta = {};
|
|
63
|
-
if (pagination && (0, lodash_1.isObject)(pagination)) {
|
|
64
|
-
const parsedpagination = Object.keys(pagination).reduce((prev, curr) => ({
|
|
65
|
-
...prev,
|
|
66
|
-
[curr]: (0, lodash_1.parseInt)((0, lodash_1.get)(pagination, curr)),
|
|
67
|
-
}), {});
|
|
68
|
-
const { page = 1, pageSize = PAGE_SIZE, start = 0, limit = PAGE_SIZE, } = parsedpagination;
|
|
69
|
-
const paginationByPage = !(0, lodash_1.isNil)(parsedpagination?.page) || !(0, lodash_1.isNil)(parsedpagination?.pageSize);
|
|
70
|
-
queryExtension = {
|
|
71
|
-
...queryExtension,
|
|
72
|
-
offset: paginationByPage ? (page - 1) * pageSize : start,
|
|
73
|
-
limit: paginationByPage ? pageSize : limit,
|
|
74
|
-
};
|
|
75
|
-
const metapagination = paginationByPage
|
|
76
|
-
? {
|
|
77
|
-
pagination: {
|
|
78
|
-
page,
|
|
79
|
-
pageSize,
|
|
80
|
-
},
|
|
81
|
-
}
|
|
82
|
-
: {
|
|
83
|
-
pagination: {
|
|
84
|
-
start,
|
|
85
|
-
limit,
|
|
86
|
-
},
|
|
87
|
-
};
|
|
88
|
-
meta = {
|
|
89
|
-
...metapagination,
|
|
90
|
-
};
|
|
91
|
-
}
|
|
45
|
+
const sortQuery = (0, parsers_1.parseSortQuery)(sort);
|
|
46
|
+
const fieldsQuery = (0, parsers_1.parseFieldsQuery)(fields, sortQuery, defaultSelect);
|
|
47
|
+
let [meta, queryExtension = {}] = (0, parsers_1.parsePaginationsQuery)(pagination, fieldsQuery, { PAGE_SIZE });
|
|
92
48
|
const entries = await strapi.db
|
|
93
49
|
.query((0, functions_1.getModelUid)("comment"))
|
|
94
50
|
.findMany({
|
|
@@ -191,6 +147,32 @@ module.exports = ({ strapi }) => ({
|
|
|
191
147
|
const doNotPopulateAuthor = await this.getConfig(constants_1.CONFIG_PARAMS.AUTHOR_BLOCKED_PROPS, []);
|
|
192
148
|
return (0, functions_1.filterOurResolvedReports)(this.sanitizeCommentEntity(entity, doNotPopulateAuthor));
|
|
193
149
|
},
|
|
150
|
+
async findAllPerAuthor({ query = {}, populate = {}, pagination, sort, fields, isAdmin = false, }, authorId, isStrapiAuthor = false) {
|
|
151
|
+
if ((0, lodash_1.isNil)(authorId)) {
|
|
152
|
+
return {
|
|
153
|
+
data: [],
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
const { related, ...restQuery } = query;
|
|
157
|
+
const authorQuery = isStrapiAuthor ? {
|
|
158
|
+
authorUser: {
|
|
159
|
+
id: authorId
|
|
160
|
+
},
|
|
161
|
+
} : {
|
|
162
|
+
authorId,
|
|
163
|
+
};
|
|
164
|
+
const response = await this.findAllFlat({
|
|
165
|
+
query: {
|
|
166
|
+
...restQuery,
|
|
167
|
+
...authorQuery,
|
|
168
|
+
},
|
|
169
|
+
pagination, populate, sort, fields, isAdmin
|
|
170
|
+
});
|
|
171
|
+
return {
|
|
172
|
+
...response,
|
|
173
|
+
data: response.data.map(({ author, ...rest }) => rest),
|
|
174
|
+
};
|
|
175
|
+
},
|
|
194
176
|
async findRelatedEntitiesFor(entities = []) {
|
|
195
177
|
const data = entities.reduce((acc, curr) => {
|
|
196
178
|
const [relatedUid, relatedStringId] = (0, functions_1.getRelatedGroups)(curr.related);
|
|
@@ -267,7 +249,7 @@ module.exports = ({ strapi }) => ({
|
|
|
267
249
|
: relatedStringId;
|
|
268
250
|
const isEnabledCollection = await this.isEnabledCollection(uid);
|
|
269
251
|
const enabledCollections = await this.getConfig(constants_1.CONFIG_PARAMS.ENABLED_COLLECTIONS, []);
|
|
270
|
-
if (!isEnabledCollection) {
|
|
252
|
+
if (enabledCollections.length > 0 && !isEnabledCollection) {
|
|
271
253
|
throw new error_1.default(403, `Action not allowed for collection '${uid}'. Use one of: ${enabledCollections.join(", ")}`);
|
|
272
254
|
}
|
|
273
255
|
return [uid, relatedId];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { StrapiDBQueryArgs, StrapiPagination, StrapiResponseMeta, StringMap } from "strapi-typed";
|
|
2
|
+
import { CommentModelKeys, ToBeFixed } from "../../../types";
|
|
3
|
+
export declare const parseSortQuery: (sort: StringMap<unknown> | undefined, query?: StrapiDBQueryArgs<CommentModelKeys>) => StrapiDBQueryArgs<CommentModelKeys>;
|
|
4
|
+
export declare const parseFieldsQuery: (fields: ToBeFixed, query?: StrapiDBQueryArgs<CommentModelKeys>, defaultSelect?: Array<CommentModelKeys>) => StrapiDBQueryArgs<CommentModelKeys>;
|
|
5
|
+
export declare const parsePaginationsQuery: (pagination: StrapiPagination | undefined, query?: StrapiDBQueryArgs<CommentModelKeys>, defaults?: any) => [StrapiResponseMeta, StrapiDBQueryArgs<CommentModelKeys>];
|
|
6
|
+
//# sourceMappingURL=parsers.d.ts.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parsePaginationsQuery = exports.parseFieldsQuery = exports.parseSortQuery = void 0;
|
|
4
|
+
const constants_1 = require("./../../utils/constants");
|
|
5
|
+
const lodash_1 = require("lodash");
|
|
6
|
+
const parseSortQuery = (sort, query = {}) => {
|
|
7
|
+
if (sort && ((0, lodash_1.isString)(sort) || (0, lodash_1.isArray)(sort))) {
|
|
8
|
+
return {
|
|
9
|
+
...query,
|
|
10
|
+
orderBy: ((0, lodash_1.isString)(sort) ? [sort] : sort)
|
|
11
|
+
.map((_) => (constants_1.REGEX.sorting.test(_) ? _ : `${_}:asc`))
|
|
12
|
+
.reduce((prev, curr) => {
|
|
13
|
+
const [type = "asc", ...parts] = curr.split(":").reverse();
|
|
14
|
+
return { ...(0, lodash_1.set)(prev, parts.reverse().join("."), type) };
|
|
15
|
+
}, {}),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
return query;
|
|
19
|
+
};
|
|
20
|
+
exports.parseSortQuery = parseSortQuery;
|
|
21
|
+
const parseFieldsQuery = (fields, query = {}, defaultSelect = []) => {
|
|
22
|
+
if (!(0, lodash_1.isNil)(fields)) {
|
|
23
|
+
return {
|
|
24
|
+
...query,
|
|
25
|
+
select: (0, lodash_1.isArray)(fields) ? (0, lodash_1.uniq)([...fields, ...defaultSelect]) : fields,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
return query;
|
|
29
|
+
};
|
|
30
|
+
exports.parseFieldsQuery = parseFieldsQuery;
|
|
31
|
+
const parsePaginationsQuery = (pagination, query = {}, defaults = []) => {
|
|
32
|
+
if (pagination && (0, lodash_1.isObject)(pagination)) {
|
|
33
|
+
const parsedpagination = Object.keys(pagination).reduce((prev, curr) => ({
|
|
34
|
+
...prev,
|
|
35
|
+
[curr]: parseInt((0, lodash_1.get)(pagination, curr)),
|
|
36
|
+
}), {});
|
|
37
|
+
const { page = 1, pageSize = defaults.PAGE_SIZE, start = 0, limit = defaults.PAGE_SIZE, } = parsedpagination;
|
|
38
|
+
const paginationByPage = !(0, lodash_1.isNil)(parsedpagination?.page) || !(0, lodash_1.isNil)(parsedpagination?.pageSize);
|
|
39
|
+
const metapagination = paginationByPage
|
|
40
|
+
? {
|
|
41
|
+
pagination: {
|
|
42
|
+
page,
|
|
43
|
+
pageSize,
|
|
44
|
+
},
|
|
45
|
+
}
|
|
46
|
+
: {
|
|
47
|
+
pagination: {
|
|
48
|
+
start,
|
|
49
|
+
limit,
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
return [{
|
|
53
|
+
...metapagination,
|
|
54
|
+
}, {
|
|
55
|
+
...query,
|
|
56
|
+
offset: paginationByPage ? (page - 1) * pageSize : start,
|
|
57
|
+
limit: paginationByPage ? pageSize : limit,
|
|
58
|
+
}];
|
|
59
|
+
}
|
|
60
|
+
return [{}, query];
|
|
61
|
+
};
|
|
62
|
+
exports.parsePaginationsQuery = parsePaginationsQuery;
|
|
63
|
+
//# sourceMappingURL=parsers.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.REGEX = exports.APPROVAL_STATUS = exports.CONFIG_PARAMS = void 0;
|
|
3
|
+
exports.REGEX = exports.AUTHOR_TYPE = exports.APPROVAL_STATUS = exports.CONFIG_PARAMS = void 0;
|
|
4
4
|
exports.CONFIG_PARAMS = {
|
|
5
5
|
ENABLED_COLLECTIONS: "enabledCollections",
|
|
6
6
|
APPROVAL_FLOW: "approvalFlow",
|
|
@@ -14,6 +14,10 @@ exports.APPROVAL_STATUS = {
|
|
|
14
14
|
APPROVED: "APPROVED",
|
|
15
15
|
REJECTED: "REJECTED",
|
|
16
16
|
};
|
|
17
|
+
exports.AUTHOR_TYPE = {
|
|
18
|
+
GENERIC: 'GENERIC',
|
|
19
|
+
STRAPI: 'STRAPI',
|
|
20
|
+
};
|
|
17
21
|
exports.REGEX = {
|
|
18
22
|
uid: /^(?<type>[a-z0-9-]+)\:{2}(?<api>[a-z0-9-]+)\.{1}(?<contentType>[a-z0-9-]+)$/i,
|
|
19
23
|
relatedUid: /^(?<uid>[a-z0-9-]+\:{2}[a-z0-9-]+\.[a-z0-9-]+)\:{1}(?<id>[a-z0-9-]+)$/i,
|