strapi-plugin-comments 3.0.0-beta.1 → 3.0.1
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 +81 -122
- package/dist/_chunks/{index-D3iNqWZT.mjs → index-BC5Odn17.mjs} +5 -5
- package/dist/_chunks/{index-BBcsmSTs.mjs → index-BIorFYba.mjs} +448 -256
- package/dist/_chunks/{index-Bcck91A8.js → index-COoWcAcA.js} +1290 -1144
- package/dist/_chunks/{index-CY_AVWS-.js → index-Ccb93U47.js} +445 -253
- package/dist/_chunks/{index-D9MOkoQ2.mjs → index-D1DAMkhj.mjs} +20 -26
- package/dist/_chunks/{index-BFPteXuP.js → index-R1krliyC.js} +5 -5
- package/dist/_chunks/{index-DJ32APz-.mjs → index-_exHAK6u.mjs} +1290 -1144
- package/dist/_chunks/{index-BXEk5PWx.js → index-k7z0V0lj.js} +20 -26
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/admin/src/api/client.d.ts +30 -50
- package/dist/admin/src/api/schemas.d.ts +432 -756
- package/dist/admin/src/components/UserAvatar/index.d.ts +1 -1
- package/dist/admin/src/hooks/useAPI.d.ts +30 -50
- package/dist/admin/src/hooks/useCommentsAll.d.ts +6 -10
- package/dist/admin/src/hooks/useReports.d.ts +6 -10
- package/dist/server/index.js +212 -157
- package/dist/server/index.mjs +212 -157
- package/dist/server/src/{@types-v5 → @types}/utils.d.ts +4 -0
- package/dist/server/src/bootstrap.d.ts +1 -1
- package/dist/server/src/config/index.d.ts +30 -0
- package/dist/server/src/content-types/index.d.ts +1 -1
- package/dist/server/src/controllers/admin.controller.d.ts +108 -29
- package/dist/server/src/controllers/client.controller.d.ts +121 -24
- package/dist/server/src/controllers/index.d.ts +300 -88
- package/dist/server/src/controllers/settings.controller.d.ts +33 -1
- package/dist/server/src/graphql/index.d.ts +1 -1
- package/dist/server/src/graphql/mutations/getCreateAbuseReport.d.ts +10 -4
- package/dist/server/src/graphql/mutations/getCreateComment.d.ts +10 -4
- package/dist/server/src/graphql/mutations/getRemoveComment.d.ts +10 -4
- package/dist/server/src/graphql/mutations/getUpdateComment.d.ts +10 -4
- package/dist/server/src/graphql/mutations/index.d.ts +2 -2
- package/dist/server/src/graphql/queries/findAllFlat.d.ts +18 -6
- package/dist/server/src/graphql/queries/findAllInHierarchy.d.ts +10 -4
- package/dist/server/src/graphql/queries/findAllPerAuthor.d.ts +18 -6
- package/dist/server/src/graphql/queries/index.d.ts +2 -2
- package/dist/server/src/graphql/types/getComment.d.ts +1 -1
- package/dist/server/src/graphql/types/getCommentAuthor.d.ts +1 -1
- package/dist/server/src/graphql/types/getCommentAuthorType.d.ts +1 -1
- package/dist/server/src/graphql/types/getCommentNested.d.ts +1 -1
- package/dist/server/src/graphql/types/getCreateComment.d.ts +1 -1
- package/dist/server/src/graphql/types/getCreateCommentAuthor.d.ts +1 -1
- package/dist/server/src/graphql/types/getCreateReport.d.ts +1 -1
- package/dist/server/src/graphql/types/getId.d.ts +1 -1
- package/dist/server/src/graphql/types/getIdentityAuthor.d.ts +1 -1
- package/dist/server/src/graphql/types/getRemoveComment.d.ts +1 -1
- package/dist/server/src/graphql/types/getReport.d.ts +1 -1
- package/dist/server/src/graphql/types/getReportReason.d.ts +1 -1
- package/dist/server/src/graphql/types/getResponseFindAll.d.ts +1 -1
- package/dist/server/src/graphql/types/getResponseFindAllPerAuthor.d.ts +1 -1
- package/dist/server/src/graphql/types/getResponseMeta.d.ts +1 -1
- package/dist/server/src/graphql/types/getResponsePagination.d.ts +1 -1
- package/dist/server/src/graphql/types/getUpdateComment.d.ts +1 -1
- package/dist/server/src/graphql/types/index.d.ts +1 -1
- package/dist/server/src/index.d.ts +931 -315
- package/dist/server/src/register/custom-fields/index.d.ts +1 -1
- package/dist/server/src/register/index.d.ts +1 -1
- package/dist/server/src/repositories/comment.repository.d.ts +10 -1
- package/dist/server/src/repositories/index.d.ts +0 -2
- package/dist/server/src/repositories/report.comment.repository.d.ts +38 -1
- package/dist/server/src/repositories/store.repository.d.ts +159 -3
- package/dist/server/src/repositories/utils.d.ts +1 -3
- package/dist/server/src/routes/admin.routes.d.ts +1 -1
- package/dist/server/src/routes/client.routes.d.ts +1 -1
- package/dist/server/src/routes/index.d.ts +2 -2
- package/dist/server/src/services/admin/admin.service.d.ts +232 -78
- package/dist/server/src/services/admin/utils.d.ts +1 -1
- package/dist/server/src/services/client.service.d.ts +178 -67
- package/dist/server/src/services/common.service.d.ts +60 -19
- package/dist/server/src/services/gql.service.d.ts +1 -1
- package/dist/server/src/services/index.d.ts +615 -223
- package/dist/server/src/services/settings.service.d.ts +25 -1
- package/dist/server/src/services/utils/functions.d.ts +1 -3
- package/dist/server/src/test/utils.d.ts +1 -0
- package/dist/server/src/utils/constants.d.ts +1 -1
- package/dist/server/src/utils/getConfig.d.ts +2 -2
- package/dist/server/src/utils/getPluginService.d.ts +2 -2
- package/dist/server/src/utils/throwError.d.ts +1 -1
- package/dist/server/src/validators/api/controllers/client.controller.validator.d.ts +16 -9
- package/dist/server/src/validators/api/controllers/settings.controller.validator.d.ts +4 -0
- package/dist/server/src/validators/repositories/comment.schema.d.ts +18 -3
- package/dist/server/src/validators/repositories/comment.validator.d.ts +384 -72
- package/dist/server/src/validators/repositories/reports.validator.d.ts +60 -18
- package/dist/server/src/validators/utils.d.ts +1 -1
- package/package.json +18 -12
- /package/dist/server/src/{@types-v5 → @types}/controllers.d.ts +0 -0
- /package/dist/server/src/{@types-v5 → @types}/index.d.ts +0 -0
- /package/dist/server/src/{@types-v5 → @types}/repositories.d.ts +0 -0
- /package/dist/server/src/{@types-v5 → @types}/routes.d.ts +0 -0
package/dist/server/index.js
CHANGED
|
@@ -206,7 +206,7 @@ const getModelUid = (strapi2, name) => {
|
|
|
206
206
|
const getDefaultAuthorPopulate = (strapi2) => {
|
|
207
207
|
const strapiUserTypeUid = "plugin::users-permissions.user";
|
|
208
208
|
const allowedTypes = ["media", "relation"];
|
|
209
|
-
const { attributes } = strapi2.
|
|
209
|
+
const { attributes } = strapi2.contentType(strapiUserTypeUid) ?? { attributes: {} };
|
|
210
210
|
const relationTypes = Object.keys(attributes)?.filter(
|
|
211
211
|
(key) => allowedTypes.includes(attributes[key]?.type)
|
|
212
212
|
);
|
|
@@ -1039,7 +1039,7 @@ lodash.exports;
|
|
|
1039
1039
|
}
|
|
1040
1040
|
var runInContext = function runInContext2(context) {
|
|
1041
1041
|
context = context == null ? root : _2.defaults(root.Object(), context, _2.pick(root, contextProps));
|
|
1042
|
-
var Array2 = context.Array,
|
|
1042
|
+
var Array2 = context.Array, Date = context.Date, Error2 = context.Error, Function2 = context.Function, Math2 = context.Math, Object2 = context.Object, RegExp2 = context.RegExp, String2 = context.String, TypeError2 = context.TypeError;
|
|
1043
1043
|
var arrayProto = Array2.prototype, funcProto = Function2.prototype, objectProto = Object2.prototype;
|
|
1044
1044
|
var coreJsData = context["__core-js_shared__"];
|
|
1045
1045
|
var funcToString = funcProto.toString;
|
|
@@ -1064,8 +1064,8 @@ lodash.exports;
|
|
|
1064
1064
|
} catch (e) {
|
|
1065
1065
|
}
|
|
1066
1066
|
}();
|
|
1067
|
-
var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout, ctxNow =
|
|
1068
|
-
var nativeCeil = Math2.ceil, nativeFloor = Math2.floor, nativeGetSymbols = Object2.getOwnPropertySymbols, nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined$1, nativeIsFinite = context.isFinite, nativeJoin = arrayProto.join, nativeKeys = overArg(Object2.keys, Object2), nativeMax = Math2.max, nativeMin = Math2.min, nativeNow =
|
|
1067
|
+
var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout, ctxNow = Date && Date.now !== root.Date.now && Date.now, ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout;
|
|
1068
|
+
var nativeCeil = Math2.ceil, nativeFloor = Math2.floor, nativeGetSymbols = Object2.getOwnPropertySymbols, nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined$1, nativeIsFinite = context.isFinite, nativeJoin = arrayProto.join, nativeKeys = overArg(Object2.keys, Object2), nativeMax = Math2.max, nativeMin = Math2.min, nativeNow = Date.now, nativeParseInt = context.parseInt, nativeRandom = Math2.random, nativeReverse = arrayProto.reverse;
|
|
1069
1069
|
var DataView = getNative(context, "DataView"), Map2 = getNative(context, "Map"), Promise2 = getNative(context, "Promise"), Set2 = getNative(context, "Set"), WeakMap = getNative(context, "WeakMap"), nativeCreate = getNative(Object2, "create");
|
|
1070
1070
|
var metaMap = WeakMap && new WeakMap();
|
|
1071
1071
|
var realNames = {};
|
|
@@ -2237,7 +2237,7 @@ lodash.exports;
|
|
|
2237
2237
|
return symbolToString ? symbolToString.call(value) : "";
|
|
2238
2238
|
}
|
|
2239
2239
|
var result2 = value + "";
|
|
2240
|
-
return result2 == "0" && 1 / value == -
|
|
2240
|
+
return result2 == "0" && 1 / value == -Infinity ? "-0" : result2;
|
|
2241
2241
|
}
|
|
2242
2242
|
function baseUniq(array, iteratee2, comparator) {
|
|
2243
2243
|
var index2 = -1, includes2 = arrayIncludes, length = array.length, isCommon = true, result2 = [], seen = result2;
|
|
@@ -2789,7 +2789,7 @@ lodash.exports;
|
|
|
2789
2789
|
bitmask |= isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG;
|
|
2790
2790
|
bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG);
|
|
2791
2791
|
if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) {
|
|
2792
|
-
bitmask &=
|
|
2792
|
+
bitmask &= -4;
|
|
2793
2793
|
}
|
|
2794
2794
|
var newData = [
|
|
2795
2795
|
func,
|
|
@@ -2845,7 +2845,7 @@ lodash.exports;
|
|
|
2845
2845
|
}
|
|
2846
2846
|
var length = partials ? partials.length : 0;
|
|
2847
2847
|
if (!length) {
|
|
2848
|
-
bitmask &=
|
|
2848
|
+
bitmask &= -97;
|
|
2849
2849
|
partials = holders = undefined$1;
|
|
2850
2850
|
}
|
|
2851
2851
|
ary2 = ary2 === undefined$1 ? ary2 : nativeMax(toInteger(ary2), 0);
|
|
@@ -2878,7 +2878,7 @@ lodash.exports;
|
|
|
2878
2878
|
holders = newData[4];
|
|
2879
2879
|
arity = newData[9] = newData[9] === undefined$1 ? isBindKey ? 0 : func.length : nativeMax(newData[9] - length, 0);
|
|
2880
2880
|
if (!arity && bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG)) {
|
|
2881
|
-
bitmask &=
|
|
2881
|
+
bitmask &= -25;
|
|
2882
2882
|
}
|
|
2883
2883
|
if (!bitmask || bitmask == WRAP_BIND_FLAG) {
|
|
2884
2884
|
var result2 = createBind(func, bitmask, thisArg);
|
|
@@ -3444,7 +3444,7 @@ lodash.exports;
|
|
|
3444
3444
|
return value;
|
|
3445
3445
|
}
|
|
3446
3446
|
var result2 = value + "";
|
|
3447
|
-
return result2 == "0" && 1 / value == -
|
|
3447
|
+
return result2 == "0" && 1 / value == -Infinity ? "-0" : result2;
|
|
3448
3448
|
}
|
|
3449
3449
|
function toSource(func) {
|
|
3450
3450
|
if (func != null) {
|
|
@@ -4508,7 +4508,7 @@ lodash.exports;
|
|
|
4508
4508
|
}
|
|
4509
4509
|
var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp;
|
|
4510
4510
|
function isSafeInteger(value) {
|
|
4511
|
-
return isInteger(value) && value >= -
|
|
4511
|
+
return isInteger(value) && value >= -9007199254740991 && value <= MAX_SAFE_INTEGER;
|
|
4512
4512
|
}
|
|
4513
4513
|
var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet;
|
|
4514
4514
|
function isString(value) {
|
|
@@ -4549,7 +4549,7 @@ lodash.exports;
|
|
|
4549
4549
|
return value === 0 ? value : 0;
|
|
4550
4550
|
}
|
|
4551
4551
|
value = toNumber(value);
|
|
4552
|
-
if (value === INFINITY || value === -
|
|
4552
|
+
if (value === INFINITY || value === -Infinity) {
|
|
4553
4553
|
var sign = value < 0 ? -1 : 1;
|
|
4554
4554
|
return sign * MAX_INTEGER;
|
|
4555
4555
|
}
|
|
@@ -4584,7 +4584,7 @@ lodash.exports;
|
|
|
4584
4584
|
return copyObject(value, keysIn(value));
|
|
4585
4585
|
}
|
|
4586
4586
|
function toSafeInteger(value) {
|
|
4587
|
-
return value ? baseClamp(toInteger(value), -
|
|
4587
|
+
return value ? baseClamp(toInteger(value), -9007199254740991, MAX_SAFE_INTEGER) : value === 0 ? value : 0;
|
|
4588
4588
|
}
|
|
4589
4589
|
function toString(value) {
|
|
4590
4590
|
return value == null ? "" : baseToString(value);
|
|
@@ -5822,29 +5822,6 @@ lodash.exports;
|
|
|
5822
5822
|
}).call(commonjsGlobal);
|
|
5823
5823
|
})(lodash, lodash.exports);
|
|
5824
5824
|
var lodashExports = lodash.exports;
|
|
5825
|
-
let PluginError$1 = class PluginError extends Error {
|
|
5826
|
-
constructor(status, message, payload = void 0) {
|
|
5827
|
-
super();
|
|
5828
|
-
this.name = "Strapi:Plugin:Comments";
|
|
5829
|
-
this.status = status || 500;
|
|
5830
|
-
this.message = message || "Internal error";
|
|
5831
|
-
this.payload = payload;
|
|
5832
|
-
Object.setPrototypeOf(this, PluginError.prototype);
|
|
5833
|
-
}
|
|
5834
|
-
toString(e = this) {
|
|
5835
|
-
return `${e.name} - ${e.message}`;
|
|
5836
|
-
}
|
|
5837
|
-
toJSON() {
|
|
5838
|
-
if (this.payload) {
|
|
5839
|
-
return {
|
|
5840
|
-
...this.payload,
|
|
5841
|
-
name: this.name,
|
|
5842
|
-
message: this.message
|
|
5843
|
-
};
|
|
5844
|
-
}
|
|
5845
|
-
return this;
|
|
5846
|
-
}
|
|
5847
|
-
};
|
|
5848
5825
|
const flatInput = (payload) => {
|
|
5849
5826
|
const {
|
|
5850
5827
|
sort,
|
|
@@ -5884,7 +5861,6 @@ const flatInput = (payload) => {
|
|
|
5884
5861
|
}
|
|
5885
5862
|
};
|
|
5886
5863
|
}
|
|
5887
|
-
({ ...filters });
|
|
5888
5864
|
return {
|
|
5889
5865
|
...payload,
|
|
5890
5866
|
filters: {
|
|
@@ -6025,6 +6001,7 @@ const getComment = (nexus) => {
|
|
|
6025
6001
|
name: "CommentSingle",
|
|
6026
6002
|
definition(t) {
|
|
6027
6003
|
t.id("id");
|
|
6004
|
+
t.string("documentId");
|
|
6028
6005
|
t.nonNull.string("content");
|
|
6029
6006
|
t.boolean("blocked");
|
|
6030
6007
|
t.boolean("blockedThread");
|
|
@@ -6060,6 +6037,7 @@ const getCommentNested = (nexus) => {
|
|
|
6060
6037
|
name: "CommentNested",
|
|
6061
6038
|
definition(t) {
|
|
6062
6039
|
t.id("id");
|
|
6040
|
+
t.string("documentId");
|
|
6063
6041
|
t.nonNull.string("content");
|
|
6064
6042
|
t.boolean("blocked");
|
|
6065
6043
|
t.boolean("blockedThread");
|
|
@@ -8111,8 +8089,19 @@ const typesFactories = [
|
|
|
8111
8089
|
getReport
|
|
8112
8090
|
];
|
|
8113
8091
|
const getTypes = (config2, nexus) => typesFactories.map((factory) => factory(nexus, config2));
|
|
8092
|
+
const getExtensionService = (strapi2) => strapi2.plugin("graphql").service("extension");
|
|
8093
|
+
const disableDefaultGQL = (strapi2) => {
|
|
8094
|
+
const extensionService = getExtensionService(strapi2);
|
|
8095
|
+
extensionService.shadowCRUD(getModelUid(strapi2, "comment")).disable();
|
|
8096
|
+
extensionService.shadowCRUD(getModelUid(strapi2, "comment")).disableQueries();
|
|
8097
|
+
extensionService.shadowCRUD(getModelUid(strapi2, "comment")).disableMutations();
|
|
8098
|
+
extensionService.shadowCRUD(getModelUid(strapi2, "comment-report")).disable();
|
|
8099
|
+
extensionService.shadowCRUD(getModelUid(strapi2, "comment-report")).disableQueries();
|
|
8100
|
+
extensionService.shadowCRUD(getModelUid(strapi2, "comment-report")).disableMutations();
|
|
8101
|
+
};
|
|
8114
8102
|
const setupGQL = async ({ strapi: strapi2 }) => {
|
|
8115
8103
|
if (strapi2.plugin("graphql")) {
|
|
8104
|
+
disableDefaultGQL(strapi2);
|
|
8116
8105
|
const enableCollections = await getPluginService(strapi2, "common").getConfig(CONFIG_PARAMS$1.ENABLED_COLLECTIONS, []);
|
|
8117
8106
|
if (enableCollections.length) {
|
|
8118
8107
|
await handleConfig(strapi2);
|
|
@@ -8120,13 +8109,7 @@ const setupGQL = async ({ strapi: strapi2 }) => {
|
|
|
8120
8109
|
}
|
|
8121
8110
|
};
|
|
8122
8111
|
const handleConfig = async (strapi2) => {
|
|
8123
|
-
const extensionService = strapi2
|
|
8124
|
-
extensionService.shadowCRUD(getModelUid(strapi2, "comment")).disable();
|
|
8125
|
-
extensionService.shadowCRUD(getModelUid(strapi2, "comment")).disableQueries();
|
|
8126
|
-
extensionService.shadowCRUD(getModelUid(strapi2, "comment")).disableMutations();
|
|
8127
|
-
extensionService.shadowCRUD(getModelUid(strapi2, "comment-report")).disable();
|
|
8128
|
-
extensionService.shadowCRUD(getModelUid(strapi2, "comment-report")).disableQueries();
|
|
8129
|
-
extensionService.shadowCRUD(getModelUid(strapi2, "comment-report")).disableMutations();
|
|
8112
|
+
const extensionService = getExtensionService(strapi2);
|
|
8130
8113
|
const config2 = await getPluginService(strapi2, "common").getConfig();
|
|
8131
8114
|
extensionService.use(({ strapi: strapi22, nexus }) => {
|
|
8132
8115
|
const types = getTypes(config2, nexus);
|
|
@@ -8235,7 +8218,11 @@ const schemaConfig = zod.z.object({
|
|
|
8235
8218
|
[CONFIG_PARAMS.AUTHOR_BLOCKED_PROPS]: zod.z.array(zod.z.string()),
|
|
8236
8219
|
gql: zod.z.object({
|
|
8237
8220
|
auth: zod.z.boolean().optional()
|
|
8238
|
-
}).optional()
|
|
8221
|
+
}).optional(),
|
|
8222
|
+
client: zod.z.object({
|
|
8223
|
+
url: zod.z.string().nullable(),
|
|
8224
|
+
contactEmail: zod.z.string().nullable()
|
|
8225
|
+
}).default({ url: null, contactEmail: null })
|
|
8239
8226
|
});
|
|
8240
8227
|
const config = {
|
|
8241
8228
|
default: schemaConfig.parse(defaultPluginConfig),
|
|
@@ -8272,14 +8259,14 @@ const isRight = (e) => {
|
|
|
8272
8259
|
};
|
|
8273
8260
|
const makeLeft = (value) => ({ left: value });
|
|
8274
8261
|
const makeRight = (value) => ({ right: value });
|
|
8275
|
-
class
|
|
8262
|
+
let PluginError$1 = class PluginError extends Error {
|
|
8276
8263
|
constructor(status, message, payload = void 0) {
|
|
8277
8264
|
super();
|
|
8278
8265
|
this.name = "Strapi:Plugin:Comments";
|
|
8279
8266
|
this.status = status || 500;
|
|
8280
8267
|
this.message = message || "Internal error";
|
|
8281
8268
|
this.payload = payload;
|
|
8282
|
-
Object.setPrototypeOf(this,
|
|
8269
|
+
Object.setPrototypeOf(this, PluginError.prototype);
|
|
8283
8270
|
}
|
|
8284
8271
|
toString(e = this) {
|
|
8285
8272
|
return `${e.name} - ${e.message}`;
|
|
@@ -8294,9 +8281,9 @@ class PluginError2 extends Error {
|
|
|
8294
8281
|
}
|
|
8295
8282
|
return this;
|
|
8296
8283
|
}
|
|
8297
|
-
}
|
|
8284
|
+
};
|
|
8298
8285
|
const throwError = (ctx, e) => {
|
|
8299
|
-
if (e instanceof
|
|
8286
|
+
if (e instanceof PluginError$1) {
|
|
8300
8287
|
return ctx.throw(e.status, JSON.stringify(e));
|
|
8301
8288
|
}
|
|
8302
8289
|
return e;
|
|
@@ -8383,7 +8370,7 @@ const queryPaginationSchema = zod.z.object({ pageSize: stringToNumberValidator.d
|
|
|
8383
8370
|
const validate = (result) => {
|
|
8384
8371
|
if (!result.success) {
|
|
8385
8372
|
const message = result.error.issues.map((i) => `Path: ${i.path.join(".")} Code: ${i.code} Message: ${i.message}`).join("\n");
|
|
8386
|
-
return makeLeft(new
|
|
8373
|
+
return makeLeft(new PluginError$1(400, message));
|
|
8387
8374
|
}
|
|
8388
8375
|
return makeRight(result.data);
|
|
8389
8376
|
};
|
|
@@ -8451,7 +8438,7 @@ const getCommentSchema = (enabledCollections) => {
|
|
|
8451
8438
|
relation: getRelationValidator(enabledCollections),
|
|
8452
8439
|
content: zod.z.string().min(1),
|
|
8453
8440
|
author: externalAuthorSchema.optional(),
|
|
8454
|
-
threadOf: zod.z.
|
|
8441
|
+
threadOf: zod.z.string().optional(),
|
|
8455
8442
|
approvalStatus: zod.z.nativeEnum(APPROVAL_STATUS).optional(),
|
|
8456
8443
|
locale: zod.z.string().optional()
|
|
8457
8444
|
});
|
|
@@ -8464,7 +8451,7 @@ const newCommentValidator = (enabledCollections, relation, payload) => {
|
|
|
8464
8451
|
};
|
|
8465
8452
|
const updateCommentValidator = (enabledCollections, payload) => {
|
|
8466
8453
|
return validate(
|
|
8467
|
-
getCommentSchema(enabledCollections).pick({ content: true, relation: true }).merge(getStringToNumberValidator({ commentId: AVAILABLE_OPERATORS.single })).safeParse(payload)
|
|
8454
|
+
getCommentSchema(enabledCollections).pick({ content: true, relation: true, author: true }).merge(getStringToNumberValidator({ commentId: AVAILABLE_OPERATORS.single })).safeParse(payload)
|
|
8468
8455
|
);
|
|
8469
8456
|
};
|
|
8470
8457
|
const getRelationSchema = (enabledCollections) => zod.z.object({
|
|
@@ -8538,16 +8525,16 @@ const findAllPerAuthorValidator = (params, payload) => {
|
|
|
8538
8525
|
...params
|
|
8539
8526
|
}));
|
|
8540
8527
|
};
|
|
8541
|
-
const getReportAbuseSchema = (
|
|
8528
|
+
const getReportAbuseSchema = (config2) => {
|
|
8542
8529
|
return zod.z.object({
|
|
8543
|
-
relation: getRelationValidator(
|
|
8544
|
-
commentId:
|
|
8530
|
+
relation: getRelationValidator(config2[CONFIG_PARAMS.ENABLED_COLLECTIONS]),
|
|
8531
|
+
commentId: stringToNumberValidator,
|
|
8545
8532
|
content: zod.z.string().min(1),
|
|
8546
|
-
reason: zod.z.
|
|
8533
|
+
reason: zod.z.nativeEnum(config2.reportReasons)
|
|
8547
8534
|
});
|
|
8548
8535
|
};
|
|
8549
|
-
const reportAbuseValidator = (
|
|
8550
|
-
return validate(getReportAbuseSchema(
|
|
8536
|
+
const reportAbuseValidator = (config2, payload) => {
|
|
8537
|
+
return validate(getReportAbuseSchema(config2).safeParse(payload));
|
|
8551
8538
|
};
|
|
8552
8539
|
const getRemoveCommentSchema = (enabledCollections) => {
|
|
8553
8540
|
return zod.z.object({
|
|
@@ -8714,7 +8701,7 @@ const dbBaseCommentSchema = zod.z.object({
|
|
|
8714
8701
|
authorName: zod.z.string().nullable(),
|
|
8715
8702
|
authorEmail: zod.z.string().email().nullable(),
|
|
8716
8703
|
authorAvatar: zod.z.string().nullable(),
|
|
8717
|
-
authorUser: zod.z.string().optional().nullable(),
|
|
8704
|
+
authorUser: zod.z.union([zod.z.string(), zod.z.object({ id: zod.z.number(), email: zod.z.string().email() })]).optional().nullable(),
|
|
8718
8705
|
locale: zod.z.string().nullable()
|
|
8719
8706
|
});
|
|
8720
8707
|
const paginationSchema = zod.z.object({
|
|
@@ -8804,7 +8791,7 @@ const reportSchema = zod.z.object({
|
|
|
8804
8791
|
updatedAt: zod.z.string(),
|
|
8805
8792
|
publishedAt: zod.z.string().nullable(),
|
|
8806
8793
|
locale: zod.z.string().nullable(),
|
|
8807
|
-
related: relatedSchema.nullable()
|
|
8794
|
+
related: relatedSchema.nullable().optional()
|
|
8808
8795
|
});
|
|
8809
8796
|
const findPageSchema = zod.z.object({
|
|
8810
8797
|
results: zod.z.array(reportSchema),
|
|
@@ -8839,7 +8826,7 @@ const reportResultValidator = {
|
|
|
8839
8826
|
update: updateResultSchema,
|
|
8840
8827
|
create: reportSchema
|
|
8841
8828
|
};
|
|
8842
|
-
const
|
|
8829
|
+
const getReportCommentRepositorySource = (strapi2) => {
|
|
8843
8830
|
const modelUid = getModelUid(strapi2, "comment-report");
|
|
8844
8831
|
const repository = strapi2.query(modelUid);
|
|
8845
8832
|
return {
|
|
@@ -8863,8 +8850,9 @@ const getReportCommentRepository = lodashExports.once((strapi2) => {
|
|
|
8863
8850
|
return repository.create(params).then(shouldValidateObject(isValidationEnabled, reportResultValidator.create));
|
|
8864
8851
|
}
|
|
8865
8852
|
};
|
|
8866
|
-
}
|
|
8867
|
-
const
|
|
8853
|
+
};
|
|
8854
|
+
const getReportCommentRepository = lodashExports.once(getReportCommentRepositorySource);
|
|
8855
|
+
const getCommentRepositorySource = (strapi2) => {
|
|
8868
8856
|
const modelUid = getModelUid(strapi2, "comment");
|
|
8869
8857
|
return {
|
|
8870
8858
|
async findMany(params) {
|
|
@@ -8895,8 +8883,9 @@ const getCommentRepository = lodashExports.once((strapi2) => {
|
|
|
8895
8883
|
return strapi2.query(modelUid).create(params).then(shouldValidateObject(isValidationEnabled, commentResultValidator.create));
|
|
8896
8884
|
}
|
|
8897
8885
|
};
|
|
8898
|
-
}
|
|
8899
|
-
const
|
|
8886
|
+
};
|
|
8887
|
+
const getCommentRepository = lodashExports.once(getCommentRepositorySource);
|
|
8888
|
+
const getStoreRepositorySource = (strapi2) => {
|
|
8900
8889
|
return {
|
|
8901
8890
|
getLocalConfig(prop, defaultValue) {
|
|
8902
8891
|
return strapi2.config.get([PLUGIN_SELECTOR, prop].filter(Boolean).join("."), defaultValue);
|
|
@@ -8973,7 +8962,8 @@ const getStoreRepository = lodashExports.once((strapi2) => {
|
|
|
8973
8962
|
return this.get();
|
|
8974
8963
|
}
|
|
8975
8964
|
};
|
|
8976
|
-
}
|
|
8965
|
+
};
|
|
8966
|
+
const getStoreRepository = lodashExports.once(getStoreRepositorySource);
|
|
8977
8967
|
const controllers$1 = ({ strapi: strapi2 }) => ({
|
|
8978
8968
|
getService(name) {
|
|
8979
8969
|
return getPluginService(strapi2, name);
|
|
@@ -8985,7 +8975,6 @@ const controllers$1 = ({ strapi: strapi2 }) => ({
|
|
|
8985
8975
|
const configResult = await this.getStoreRepository().get(true);
|
|
8986
8976
|
if (isRight(configResult)) {
|
|
8987
8977
|
const config2 = unwrapEither(configResult);
|
|
8988
|
-
console.log("config.enabledCollections", config2.enabledCollections);
|
|
8989
8978
|
const result = newCommentValidator(config2.enabledCollections, ctx.params.relation, ctx.request.body);
|
|
8990
8979
|
if (isRight(result)) {
|
|
8991
8980
|
return this.getService("client").create(result.right, ctx.state.user);
|
|
@@ -9038,8 +9027,9 @@ const controllers$1 = ({ strapi: strapi2 }) => ({
|
|
|
9038
9027
|
if (isRight(configResult)) {
|
|
9039
9028
|
const config2 = unwrapEither(configResult);
|
|
9040
9029
|
const result = updateCommentValidator(config2.enabledCollections, {
|
|
9041
|
-
...ctx.
|
|
9042
|
-
|
|
9030
|
+
...ctx.params,
|
|
9031
|
+
content: ctx.request.body.content,
|
|
9032
|
+
author: ctx.request.body.author
|
|
9043
9033
|
});
|
|
9044
9034
|
if (isRight(result)) {
|
|
9045
9035
|
return await this.getService("client").update(
|
|
@@ -9057,7 +9047,7 @@ const controllers$1 = ({ strapi: strapi2 }) => ({
|
|
|
9057
9047
|
const configResult = await this.getStoreRepository().get(true);
|
|
9058
9048
|
if (isRight(configResult)) {
|
|
9059
9049
|
const config2 = unwrapEither(configResult);
|
|
9060
|
-
const result = reportAbuseValidator(config2
|
|
9050
|
+
const result = reportAbuseValidator(config2, {
|
|
9061
9051
|
...ctx.request.body,
|
|
9062
9052
|
...ctx.params
|
|
9063
9053
|
});
|
|
@@ -9328,7 +9318,6 @@ const routes$1 = [
|
|
|
9328
9318
|
path: "/:relation",
|
|
9329
9319
|
handler: "client.findAllInHierarchy",
|
|
9330
9320
|
config: {
|
|
9331
|
-
auth: false,
|
|
9332
9321
|
policies: [],
|
|
9333
9322
|
description: "Find all comments related to configured Collection / Single Type and return them in a nested structure",
|
|
9334
9323
|
tag: {
|
|
@@ -9343,7 +9332,6 @@ const routes$1 = [
|
|
|
9343
9332
|
path: "/:relation",
|
|
9344
9333
|
handler: "client.post",
|
|
9345
9334
|
config: {
|
|
9346
|
-
auth: false,
|
|
9347
9335
|
policies: [],
|
|
9348
9336
|
description: "Post a comment against configured Collection / Single Type",
|
|
9349
9337
|
tag: {
|
|
@@ -9358,7 +9346,6 @@ const routes$1 = [
|
|
|
9358
9346
|
path: "/:relation/flat",
|
|
9359
9347
|
handler: "client.findAllFlat",
|
|
9360
9348
|
config: {
|
|
9361
|
-
auth: false,
|
|
9362
9349
|
policies: [],
|
|
9363
9350
|
description: "Find all comments related to configured Collection / Single Type and return them in a flat structure for further processing",
|
|
9364
9351
|
tag: {
|
|
@@ -9373,7 +9360,6 @@ const routes$1 = [
|
|
|
9373
9360
|
path: "/:relation/comment/:commentId",
|
|
9374
9361
|
handler: "client.put",
|
|
9375
9362
|
config: {
|
|
9376
|
-
auth: false,
|
|
9377
9363
|
policies: [],
|
|
9378
9364
|
description: "Update comment related to configured Collection / Single Type if user is the author",
|
|
9379
9365
|
tag: {
|
|
@@ -9388,7 +9374,6 @@ const routes$1 = [
|
|
|
9388
9374
|
path: "/:relation/comment/:commentId/report-abuse",
|
|
9389
9375
|
handler: "client.reportAbuse",
|
|
9390
9376
|
config: {
|
|
9391
|
-
auth: false,
|
|
9392
9377
|
policies: [],
|
|
9393
9378
|
description: "Report an abuse against comment for configured Collection / Single Type",
|
|
9394
9379
|
tag: {
|
|
@@ -9403,7 +9388,6 @@ const routes$1 = [
|
|
|
9403
9388
|
path: "/:relation/comment/:commentId",
|
|
9404
9389
|
handler: "client.removeComment",
|
|
9405
9390
|
config: {
|
|
9406
|
-
auth: false,
|
|
9407
9391
|
policies: [],
|
|
9408
9392
|
description: "Remove comment related to configured Collection / Single Type if user is the author",
|
|
9409
9393
|
tag: {
|
|
@@ -9418,7 +9402,6 @@ const routes$1 = [
|
|
|
9418
9402
|
path: "/author/:authorId",
|
|
9419
9403
|
handler: "client.findAllPerAuthor",
|
|
9420
9404
|
config: {
|
|
9421
|
-
auth: false,
|
|
9422
9405
|
policies: [],
|
|
9423
9406
|
description: "Find all comments created by Strapi user",
|
|
9424
9407
|
tag: {
|
|
@@ -9433,7 +9416,6 @@ const routes$1 = [
|
|
|
9433
9416
|
path: "/author/:authorId/:type",
|
|
9434
9417
|
handler: "client.findAllPerAuthor",
|
|
9435
9418
|
config: {
|
|
9436
|
-
auth: false,
|
|
9437
9419
|
policies: [],
|
|
9438
9420
|
description: "Find all comments created by specified type of user",
|
|
9439
9421
|
tag: {
|
|
@@ -9454,6 +9436,29 @@ const routes = {
|
|
|
9454
9436
|
routes: adminRoutes$1
|
|
9455
9437
|
}
|
|
9456
9438
|
};
|
|
9439
|
+
class PluginError2 extends Error {
|
|
9440
|
+
constructor(status, message, payload = void 0) {
|
|
9441
|
+
super();
|
|
9442
|
+
this.name = "Strapi:Plugin:Comments";
|
|
9443
|
+
this.status = status || 500;
|
|
9444
|
+
this.message = message || "Internal error";
|
|
9445
|
+
this.payload = payload;
|
|
9446
|
+
Object.setPrototypeOf(this, PluginError2.prototype);
|
|
9447
|
+
}
|
|
9448
|
+
toString(e = this) {
|
|
9449
|
+
return `${e.name} - ${e.message}`;
|
|
9450
|
+
}
|
|
9451
|
+
toJSON() {
|
|
9452
|
+
if (this.payload) {
|
|
9453
|
+
return {
|
|
9454
|
+
...this.payload,
|
|
9455
|
+
name: this.name,
|
|
9456
|
+
message: this.message
|
|
9457
|
+
};
|
|
9458
|
+
}
|
|
9459
|
+
return this;
|
|
9460
|
+
}
|
|
9461
|
+
}
|
|
9457
9462
|
const buildNestedStructure = (entities, id = null, field = "threadOf", dropBlockedThreads = false, blockNestedThreads = false) => entities.filter((entity) => {
|
|
9458
9463
|
const entityField = lodashExports.get(entity, field);
|
|
9459
9464
|
if (entityField === null && id === null) {
|
|
@@ -9519,14 +9524,14 @@ const buildAuthorModel = (item, blockedAuthorProps, fieldsToPopulate = []) => {
|
|
|
9519
9524
|
);
|
|
9520
9525
|
return {
|
|
9521
9526
|
...rest,
|
|
9522
|
-
author
|
|
9527
|
+
author: lodashExports.isEmpty(author) ? item.author || {} : author
|
|
9523
9528
|
};
|
|
9524
9529
|
};
|
|
9525
9530
|
const resolveUserContextError = (user) => {
|
|
9526
9531
|
if (user) {
|
|
9527
|
-
throw new
|
|
9532
|
+
throw new PluginError2(401, "Not authenticated");
|
|
9528
9533
|
} else {
|
|
9529
|
-
throw new
|
|
9534
|
+
throw new PluginError2(403, "Not authorized");
|
|
9530
9535
|
}
|
|
9531
9536
|
};
|
|
9532
9537
|
const getAuthorName = (author) => {
|
|
@@ -9717,16 +9722,16 @@ const adminServices = ({ strapi: strapi2 }) => {
|
|
|
9717
9722
|
where: { id }
|
|
9718
9723
|
});
|
|
9719
9724
|
if (!entity) {
|
|
9720
|
-
throw new
|
|
9725
|
+
throw new PluginError$1(404, "Not found");
|
|
9721
9726
|
}
|
|
9722
9727
|
const { relatedId, uid } = this.getCommonService().parseRelationString(entity.related);
|
|
9723
|
-
const relatedEntity = await strapi2.
|
|
9728
|
+
const relatedEntity = await strapi2.documents(uid).findOne({ documentId: relatedId }).then((_2) => {
|
|
9724
9729
|
if (!_2) {
|
|
9725
|
-
throw new
|
|
9730
|
+
throw new PluginError$1(404, "Relation not found");
|
|
9726
9731
|
}
|
|
9727
9732
|
return { ..._2, uid };
|
|
9728
9733
|
});
|
|
9729
|
-
const levelThreadId = entity.threadOf && typeof entity.threadOf === "object" ? entity.threadOf.
|
|
9734
|
+
const levelThreadId = entity.threadOf && typeof entity.threadOf === "object" ? entity.threadOf.documentId : null;
|
|
9730
9735
|
const entitiesOnSameLevel = await this.getCommonService().findAllInHierarchy(
|
|
9731
9736
|
{
|
|
9732
9737
|
query: {
|
|
@@ -9783,7 +9788,7 @@ const adminServices = ({ strapi: strapi2 }) => {
|
|
|
9783
9788
|
data: { approvalStatus: APPROVAL_STATUS.APPROVED }
|
|
9784
9789
|
});
|
|
9785
9790
|
if (!entity) {
|
|
9786
|
-
throw new
|
|
9791
|
+
throw new PluginError$1(404, "Not found");
|
|
9787
9792
|
}
|
|
9788
9793
|
return this.getCommonService().sanitizeCommentEntity(entity, []);
|
|
9789
9794
|
},
|
|
@@ -9793,7 +9798,7 @@ const adminServices = ({ strapi: strapi2 }) => {
|
|
|
9793
9798
|
data: { approvalStatus: APPROVAL_STATUS.REJECTED }
|
|
9794
9799
|
});
|
|
9795
9800
|
if (!entity) {
|
|
9796
|
-
throw new
|
|
9801
|
+
throw new PluginError$1(404, "Not found");
|
|
9797
9802
|
}
|
|
9798
9803
|
return this.getCommonService().sanitizeCommentEntity(entity, []);
|
|
9799
9804
|
},
|
|
@@ -9839,14 +9844,14 @@ const adminServices = ({ strapi: strapi2 }) => {
|
|
|
9839
9844
|
}
|
|
9840
9845
|
});
|
|
9841
9846
|
}
|
|
9842
|
-
throw new
|
|
9847
|
+
throw new PluginError$1(
|
|
9843
9848
|
400,
|
|
9844
9849
|
"At least one of selected reports got invalid comment entity relation. Try again."
|
|
9845
9850
|
);
|
|
9846
9851
|
},
|
|
9847
9852
|
async resolveAllAbuseReportsForComment(id) {
|
|
9848
9853
|
if (!id) {
|
|
9849
|
-
throw new
|
|
9854
|
+
throw new PluginError$1(
|
|
9850
9855
|
400,
|
|
9851
9856
|
"There is something wrong with comment Id. Try again."
|
|
9852
9857
|
);
|
|
@@ -9863,7 +9868,7 @@ const adminServices = ({ strapi: strapi2 }) => {
|
|
|
9863
9868
|
},
|
|
9864
9869
|
async resolveAllAbuseReportsForThread(commentId) {
|
|
9865
9870
|
if (!commentId) {
|
|
9866
|
-
throw new
|
|
9871
|
+
throw new PluginError$1(
|
|
9867
9872
|
400,
|
|
9868
9873
|
"There is something wrong with comment Id. Try again."
|
|
9869
9874
|
);
|
|
@@ -9901,7 +9906,7 @@ const adminServices = ({ strapi: strapi2 }) => {
|
|
|
9901
9906
|
where: { id }
|
|
9902
9907
|
});
|
|
9903
9908
|
if (!entity) {
|
|
9904
|
-
throw new
|
|
9909
|
+
throw new PluginError$1(404, "Not found");
|
|
9905
9910
|
}
|
|
9906
9911
|
return getCommentRepository(strapi2).create({
|
|
9907
9912
|
data: {
|
|
@@ -9921,7 +9926,7 @@ const adminServices = ({ strapi: strapi2 }) => {
|
|
|
9921
9926
|
data: { content }
|
|
9922
9927
|
});
|
|
9923
9928
|
if (!entity) {
|
|
9924
|
-
throw new
|
|
9929
|
+
throw new PluginError$1(404, "Not found");
|
|
9925
9930
|
}
|
|
9926
9931
|
return this.getCommonService().sanitizeCommentEntity(entity, []);
|
|
9927
9932
|
}
|
|
@@ -9935,8 +9940,8 @@ const tryCatch = async (callback, throwError2) => {
|
|
|
9935
9940
|
}
|
|
9936
9941
|
};
|
|
9937
9942
|
const clientService = ({ strapi: strapi2 }) => {
|
|
9938
|
-
const createAuthor = (
|
|
9939
|
-
if (
|
|
9943
|
+
const createAuthor = (author, user) => {
|
|
9944
|
+
if (user) {
|
|
9940
9945
|
return {
|
|
9941
9946
|
authorUser: user.id
|
|
9942
9947
|
};
|
|
@@ -9958,7 +9963,7 @@ const clientService = ({ strapi: strapi2 }) => {
|
|
|
9958
9963
|
const { uid, relatedId } = this.getCommonService().parseRelationString(relation);
|
|
9959
9964
|
const relatedEntity = await strapi2.documents(uid).findOne({ documentId: relatedId, locale });
|
|
9960
9965
|
if (!relatedEntity) {
|
|
9961
|
-
throw new
|
|
9966
|
+
throw new PluginError2(
|
|
9962
9967
|
400,
|
|
9963
9968
|
`Relation for field "related" does not exist. Check your payload please.`
|
|
9964
9969
|
);
|
|
@@ -9973,21 +9978,23 @@ const clientService = ({ strapi: strapi2 }) => {
|
|
|
9973
9978
|
async () => {
|
|
9974
9979
|
return threadOf ? await this.getCommonService().findOne({ id: threadOf, related: relation, locale }) : null;
|
|
9975
9980
|
},
|
|
9976
|
-
new
|
|
9981
|
+
new PluginError2(400, "Thread does not exist")
|
|
9977
9982
|
);
|
|
9978
9983
|
if (isLeft(threadData)) {
|
|
9979
9984
|
throw unwrapEither(threadData);
|
|
9980
9985
|
}
|
|
9981
9986
|
const linkToThread = unwrapEither(threadData);
|
|
9982
|
-
this.getCommonService().isValidUserContext(user)
|
|
9987
|
+
if (!author && !this.getCommonService().isValidUserContext(user)) {
|
|
9988
|
+
throw resolveUserContextError(user);
|
|
9989
|
+
}
|
|
9983
9990
|
const clearContent = await this.getCommonService().checkBadWords(content);
|
|
9984
|
-
const authorData = createAuthor(
|
|
9991
|
+
const authorData = createAuthor(author, user);
|
|
9985
9992
|
const authorNotProperlyProvided = !lodashExports.isEmpty(authorData) && !(authorData.authorId || authorData.authorUser);
|
|
9986
9993
|
if (lodashExports.isEmpty(authorData) || authorNotProperlyProvided) {
|
|
9987
|
-
throw new
|
|
9994
|
+
throw new PluginError2(400, `Not able to recognise author of a comment. Make sure you've provided "author" property in a payload or authenticated your request properly.`);
|
|
9988
9995
|
}
|
|
9989
9996
|
if (isApprovalFlowEnabled && approvalStatus && approvalStatus !== APPROVAL_STATUS.PENDING) {
|
|
9990
|
-
throw new
|
|
9997
|
+
throw new PluginError2(400, "Invalid approval status");
|
|
9991
9998
|
}
|
|
9992
9999
|
const comment2 = await getCommentRepository(strapi2).create({
|
|
9993
10000
|
data: {
|
|
@@ -10014,19 +10021,22 @@ const clientService = ({ strapi: strapi2 }) => {
|
|
|
10014
10021
|
return sanitizedEntity;
|
|
10015
10022
|
},
|
|
10016
10023
|
// Update a comment
|
|
10017
|
-
async update({ commentId, content }, user) {
|
|
10018
|
-
|
|
10019
|
-
if (!validContext) {
|
|
10024
|
+
async update({ commentId, content, author, relation }, user) {
|
|
10025
|
+
if (!author && !this.getCommonService().isValidUserContext(user)) {
|
|
10020
10026
|
throw resolveUserContextError(user);
|
|
10021
10027
|
}
|
|
10028
|
+
const authorId = user?.id || author?.id;
|
|
10022
10029
|
if (await this.getCommonService().checkBadWords(content)) {
|
|
10023
10030
|
const blockedAuthorProps = await this.getCommonService().getConfig(CONFIG_PARAMS$1.AUTHOR_BLOCKED_PROPS, []);
|
|
10024
|
-
const
|
|
10025
|
-
|
|
10026
|
-
|
|
10027
|
-
|
|
10028
|
-
|
|
10029
|
-
|
|
10031
|
+
const existingComment = await this.getCommonService().findOne({ id: commentId, related: relation });
|
|
10032
|
+
if (existingComment && existingComment.author?.id?.toString() === authorId?.toString()) {
|
|
10033
|
+
const entity = await getCommentRepository(strapi2).update({
|
|
10034
|
+
where: { id: commentId },
|
|
10035
|
+
data: { content },
|
|
10036
|
+
populate: { threadOf: true, authorUser: true }
|
|
10037
|
+
});
|
|
10038
|
+
return this.getCommonService().sanitizeCommentEntity(entity, blockedAuthorProps);
|
|
10039
|
+
}
|
|
10030
10040
|
}
|
|
10031
10041
|
},
|
|
10032
10042
|
// Report abuse in comment
|
|
@@ -10040,7 +10050,7 @@ const clientService = ({ strapi: strapi2 }) => {
|
|
|
10040
10050
|
related: relation
|
|
10041
10051
|
});
|
|
10042
10052
|
if (reportAgainstEntity.isAdminComment) {
|
|
10043
|
-
throw new
|
|
10053
|
+
throw new PluginError2(
|
|
10044
10054
|
403,
|
|
10045
10055
|
`You're not allowed to take an action on that entity. This in a admin comment.`
|
|
10046
10056
|
);
|
|
@@ -10065,10 +10075,10 @@ const clientService = ({ strapi: strapi2 }) => {
|
|
|
10065
10075
|
return response;
|
|
10066
10076
|
}
|
|
10067
10077
|
} else {
|
|
10068
|
-
throw new
|
|
10078
|
+
throw new PluginError2(500, "Report cannot be created");
|
|
10069
10079
|
}
|
|
10070
10080
|
}
|
|
10071
|
-
throw new
|
|
10081
|
+
throw new PluginError2(
|
|
10072
10082
|
403,
|
|
10073
10083
|
`You're not allowed to take an action on that entity. Make sure that comment exist or you've authenticated your request properly.`
|
|
10074
10084
|
);
|
|
@@ -10077,12 +10087,12 @@ const clientService = ({ strapi: strapi2 }) => {
|
|
|
10077
10087
|
}
|
|
10078
10088
|
},
|
|
10079
10089
|
async markAsRemoved({ commentId, relation, authorId }, user) {
|
|
10080
|
-
if (!this.getCommonService().isValidUserContext(user)) {
|
|
10090
|
+
if (!authorId && !this.getCommonService().isValidUserContext(user)) {
|
|
10081
10091
|
throw resolveUserContextError(user);
|
|
10082
10092
|
}
|
|
10083
10093
|
const author = user?.id || authorId;
|
|
10084
10094
|
if (!author) {
|
|
10085
|
-
throw new
|
|
10095
|
+
throw new PluginError2(
|
|
10086
10096
|
403,
|
|
10087
10097
|
`You're not allowed to take an action on that entity. Make sure that you've provided proper "authorId" or authenticated your request properly.`
|
|
10088
10098
|
);
|
|
@@ -10111,23 +10121,88 @@ const clientService = ({ strapi: strapi2 }) => {
|
|
|
10111
10121
|
const doNotPopulateAuthor = await this.getCommonService().getConfig(CONFIG_PARAMS$1.AUTHOR_BLOCKED_PROPS, []);
|
|
10112
10122
|
return this.getCommonService().sanitizeCommentEntity(removedEntity, doNotPopulateAuthor);
|
|
10113
10123
|
} else {
|
|
10114
|
-
throw new
|
|
10124
|
+
throw new PluginError2(
|
|
10115
10125
|
404,
|
|
10116
10126
|
`Entity does not exist or you're not allowed to take an action on it`
|
|
10117
10127
|
);
|
|
10118
10128
|
}
|
|
10119
10129
|
} catch (e) {
|
|
10120
|
-
throw new
|
|
10130
|
+
throw new PluginError2(
|
|
10121
10131
|
404,
|
|
10122
10132
|
`Entity does not exist or you're not allowed to take an action on it`
|
|
10123
10133
|
);
|
|
10124
10134
|
}
|
|
10125
10135
|
},
|
|
10126
10136
|
async sendAbuseReportEmail(reason, content) {
|
|
10137
|
+
const SUPER_ADMIN_ROLE = "strapi-super-admin";
|
|
10138
|
+
const rolesToNotify = await this.getCommonService().getConfig(CONFIG_PARAMS$1.MODERATOR_ROLES, [SUPER_ADMIN_ROLE]);
|
|
10139
|
+
if (rolesToNotify.length > 0) {
|
|
10140
|
+
const emails = await strapi2.query("admin::user").findMany({ where: { roles: { code: rolesToNotify } } }).then((users) => users.map((user) => user.email));
|
|
10141
|
+
if (emails.length > 0) {
|
|
10142
|
+
const from = await strapi2.query("admin::user").findOne({ where: { roles: { code: SUPER_ADMIN_ROLE } } });
|
|
10143
|
+
if (strapi2.plugin("email")) {
|
|
10144
|
+
await strapi2.plugin("email").service("email").send({
|
|
10145
|
+
to: emails,
|
|
10146
|
+
from: from.email,
|
|
10147
|
+
subject: "New abuse report on comment",
|
|
10148
|
+
text: `
|
|
10149
|
+
There was a new abuse report on your app.
|
|
10150
|
+
Reason: ${reason}
|
|
10151
|
+
Message: ${content}
|
|
10152
|
+
`
|
|
10153
|
+
});
|
|
10154
|
+
}
|
|
10155
|
+
}
|
|
10156
|
+
}
|
|
10127
10157
|
},
|
|
10128
10158
|
async markAsRemovedNested(commentId, status) {
|
|
10159
|
+
return this.getCommonService().modifiedNestedNestedComments(
|
|
10160
|
+
commentId,
|
|
10161
|
+
"removed",
|
|
10162
|
+
status
|
|
10163
|
+
);
|
|
10129
10164
|
},
|
|
10130
|
-
async sendResponseNotification(
|
|
10165
|
+
async sendResponseNotification(entity) {
|
|
10166
|
+
if (entity.threadOf) {
|
|
10167
|
+
const thread = typeof entity.threadOf === "object" ? entity.threadOf : await this.getCommonService().findOne({ id: entity.threadOf });
|
|
10168
|
+
let emailRecipient = thread?.author?.email;
|
|
10169
|
+
if (thread.authorUser && !emailRecipient) {
|
|
10170
|
+
const strapiUser = typeof thread.authorUser === "object" ? thread.authorUser : await strapi2.query("plugin::users-permissions.user").findOne({
|
|
10171
|
+
where: { id: thread.authorUser }
|
|
10172
|
+
});
|
|
10173
|
+
emailRecipient = strapiUser?.email;
|
|
10174
|
+
}
|
|
10175
|
+
if (emailRecipient) {
|
|
10176
|
+
const superAdmin = await strapi2.query("admin::user").findOne({
|
|
10177
|
+
where: {
|
|
10178
|
+
roles: { code: "strapi-super-admin" }
|
|
10179
|
+
}
|
|
10180
|
+
});
|
|
10181
|
+
const emailSender = await this.getCommonService().getConfig("client.contactEmail", superAdmin.email);
|
|
10182
|
+
const clientAppUrl = await this.getCommonService().getConfig("client.url", "our site");
|
|
10183
|
+
try {
|
|
10184
|
+
await strapi2.plugin("email").service("email").send({
|
|
10185
|
+
to: [emailRecipient],
|
|
10186
|
+
from: emailSender,
|
|
10187
|
+
subject: "You've got a new response to your comment",
|
|
10188
|
+
text: `Hello ${thread?.author?.name || emailRecipient}!
|
|
10189
|
+
You've got a new response to your comment by ${entity?.author?.name || entity?.author?.email}.
|
|
10190
|
+
|
|
10191
|
+
------
|
|
10192
|
+
|
|
10193
|
+
"${entity.content}"
|
|
10194
|
+
|
|
10195
|
+
------
|
|
10196
|
+
|
|
10197
|
+
Visit ${clientAppUrl} and continue the discussion.
|
|
10198
|
+
`
|
|
10199
|
+
});
|
|
10200
|
+
} catch (err) {
|
|
10201
|
+
strapi2.log.error(err);
|
|
10202
|
+
throw err;
|
|
10203
|
+
}
|
|
10204
|
+
}
|
|
10205
|
+
}
|
|
10131
10206
|
}
|
|
10132
10207
|
};
|
|
10133
10208
|
};
|
|
@@ -10137,7 +10212,7 @@ const commonService = ({ strapi: strapi2 }) => ({
|
|
|
10137
10212
|
async getConfig(prop, defaultValue, useLocal = false) {
|
|
10138
10213
|
const storeRepository = getStoreRepository(strapi2);
|
|
10139
10214
|
const config2 = await storeRepository.getConfig();
|
|
10140
|
-
if (prop &&
|
|
10215
|
+
if (prop && !useLocal) {
|
|
10141
10216
|
return lodashExports.get(config2, prop, defaultValue);
|
|
10142
10217
|
}
|
|
10143
10218
|
if (useLocal) {
|
|
@@ -10188,7 +10263,7 @@ const commonService = ({ strapi: strapi2 }) => ({
|
|
|
10188
10263
|
const [operator, direction] = getOrderBy(sort);
|
|
10189
10264
|
const fieldsQuery = {
|
|
10190
10265
|
sort: { [operator]: direction },
|
|
10191
|
-
select: Array.isArray(fields) ? lodashExports.uniq([...fields, defaultSelect]) : fields
|
|
10266
|
+
select: Array.isArray(fields) ? lodashExports.uniq([...fields, defaultSelect].flat()) : fields
|
|
10192
10267
|
};
|
|
10193
10268
|
const entries = await getCommentRepository(strapi2).findMany({
|
|
10194
10269
|
where: {
|
|
@@ -10276,7 +10351,7 @@ const commonService = ({ strapi: strapi2 }) => ({
|
|
|
10276
10351
|
}
|
|
10277
10352
|
});
|
|
10278
10353
|
if (!entity) {
|
|
10279
|
-
throw new
|
|
10354
|
+
throw new PluginError$1(400, "Comment does not exist. Check your payload please.");
|
|
10280
10355
|
}
|
|
10281
10356
|
const doNotPopulateAuthor = await this.getConfig(CONFIG_PARAMS.AUTHOR_BLOCKED_PROPS, []);
|
|
10282
10357
|
const item = this.sanitizeCommentEntity(entity, doNotPopulateAuthor);
|
|
@@ -10380,7 +10455,11 @@ const commonService = ({ strapi: strapi2 }) => ({
|
|
|
10380
10455
|
)
|
|
10381
10456
|
};
|
|
10382
10457
|
},
|
|
10383
|
-
|
|
10458
|
+
// TODO: we need to add deepLimit to the function to prevent infinite loops
|
|
10459
|
+
async modifiedNestedNestedComments(id, fieldName, value, deepLimit = 10) {
|
|
10460
|
+
if (deepLimit === 0) {
|
|
10461
|
+
return true;
|
|
10462
|
+
}
|
|
10384
10463
|
try {
|
|
10385
10464
|
const entities = await this.findMany({ where: { threadOf: id } });
|
|
10386
10465
|
const changedEntries = await getCommentRepository(strapi2).updateMany({
|
|
@@ -10389,7 +10468,7 @@ const commonService = ({ strapi: strapi2 }) => ({
|
|
|
10389
10468
|
});
|
|
10390
10469
|
if (entities.length === changedEntries.count && changedEntries.count > 0) {
|
|
10391
10470
|
const nestedTransactions = await Promise.all(
|
|
10392
|
-
entities.map((item) => this.modifiedNestedNestedComments(item.id, fieldName, value))
|
|
10471
|
+
entities.map((item) => this.modifiedNestedNestedComments(item.id, fieldName, value, deepLimit - 1))
|
|
10393
10472
|
);
|
|
10394
10473
|
return nestedTransactions.length === changedEntries.count;
|
|
10395
10474
|
}
|
|
@@ -10402,7 +10481,7 @@ const commonService = ({ strapi: strapi2 }) => ({
|
|
|
10402
10481
|
const config2 = await this.getConfig(CONFIG_PARAMS.BAD_WORDS, true);
|
|
10403
10482
|
if (config2) {
|
|
10404
10483
|
if (content && noProfanity.isProfane({ testString: content })) {
|
|
10405
|
-
throw new
|
|
10484
|
+
throw new PluginError$1(
|
|
10406
10485
|
400,
|
|
10407
10486
|
"Bad language used! Please polite your comment...",
|
|
10408
10487
|
{
|
|
@@ -11502,7 +11581,7 @@ lodash_min.exports;
|
|
|
11502
11581
|
if (bh(n2)) return c(n2, vu) + "";
|
|
11503
11582
|
if (bc(n2)) return vs ? vs.call(n2) : "";
|
|
11504
11583
|
var t2 = n2 + "";
|
|
11505
|
-
return "0" == t2 && 1 / n2 == -
|
|
11584
|
+
return "0" == t2 && 1 / n2 == -Infinity ? "-0" : t2;
|
|
11506
11585
|
}
|
|
11507
11586
|
function gu(n2, t2, r2) {
|
|
11508
11587
|
var e2 = -1, u2 = o, i2 = n2.length, c2 = true, a2 = [], l2 = a2;
|
|
@@ -11821,7 +11900,7 @@ lodash_min.exports;
|
|
|
11821
11900
|
}
|
|
11822
11901
|
function oi(n2, t2, r2, e2, u2, i2, o2, f2, c2, a2) {
|
|
11823
11902
|
var l2 = t2 & yn, s2 = l2 ? o2 : X, h2 = l2 ? X : o2, p3 = l2 ? i2 : X, _3 = l2 ? X : i2;
|
|
11824
|
-
t2 |= l2 ? bn : wn, t2 &= ~(l2 ? wn : bn), t2 & gn || (t2 &=
|
|
11903
|
+
t2 |= l2 ? bn : wn, t2 &= ~(l2 ? wn : bn), t2 & gn || (t2 &= -4);
|
|
11825
11904
|
var v2 = [n2, t2, u2, p3, s2, _3, h2, f2, c2, a2], g2 = r2.apply(X, v2);
|
|
11826
11905
|
return $i(n2) && Ss(g2, v2), g2.placeholder = e2, Yi(g2, n2, t2);
|
|
11827
11906
|
}
|
|
@@ -11845,12 +11924,12 @@ lodash_min.exports;
|
|
|
11845
11924
|
var c2 = t2 & vn;
|
|
11846
11925
|
if (!c2 && "function" != typeof n2) throw new pl(en);
|
|
11847
11926
|
var a2 = e2 ? e2.length : 0;
|
|
11848
|
-
if (a2 || (t2 &=
|
|
11927
|
+
if (a2 || (t2 &= -97, e2 = u2 = X), o2 = o2 === X ? o2 : Gl(kc(o2), 0), f2 = f2 === X ? f2 : kc(f2), a2 -= u2 ? u2.length : 0, t2 & wn) {
|
|
11849
11928
|
var l2 = e2, s2 = u2;
|
|
11850
11929
|
e2 = u2 = X;
|
|
11851
11930
|
}
|
|
11852
11931
|
var h2 = c2 ? X : Os(n2), p3 = [n2, t2, r2, e2, u2, l2, s2, i2, o2, f2];
|
|
11853
|
-
if (h2 && qi(p3, h2), n2 = p3[0], t2 = p3[1], r2 = p3[2], e2 = p3[3], u2 = p3[4], f2 = p3[9] = p3[9] === X ? c2 ? 0 : n2.length : Gl(p3[9] - a2, 0), !f2 && t2 & (yn | dn) && (t2 &=
|
|
11932
|
+
if (h2 && qi(p3, h2), n2 = p3[0], t2 = p3[1], r2 = p3[2], e2 = p3[3], u2 = p3[4], f2 = p3[9] = p3[9] === X ? c2 ? 0 : n2.length : Gl(p3[9] - a2, 0), !f2 && t2 & (yn | dn) && (t2 &= -25), t2 && t2 != _n) _3 = t2 == yn || t2 == dn ? Hu(n2, t2, f2) : t2 != bn && t2 != (_n | bn) || u2.length ? Qu.apply(X, p3) : ei(n2, t2, r2, e2);
|
|
11854
11933
|
else var _3 = Zu(n2, t2, r2);
|
|
11855
11934
|
return Yi((h2 ? ms : Ss)(_3, p3), n2, t2);
|
|
11856
11935
|
}
|
|
@@ -12189,7 +12268,7 @@ lodash_min.exports;
|
|
|
12189
12268
|
function no(n2) {
|
|
12190
12269
|
if ("string" == typeof n2 || bc(n2)) return n2;
|
|
12191
12270
|
var t2 = n2 + "";
|
|
12192
|
-
return "0" == t2 && 1 / n2 == -
|
|
12271
|
+
return "0" == t2 && 1 / n2 == -Infinity ? "-0" : t2;
|
|
12193
12272
|
}
|
|
12194
12273
|
function to(n2) {
|
|
12195
12274
|
if (null != n2) {
|
|
@@ -12753,7 +12832,7 @@ lodash_min.exports;
|
|
|
12753
12832
|
return "function" == typeof r2 && r2 instanceof r2 && dl.call(r2) == jl;
|
|
12754
12833
|
}
|
|
12755
12834
|
function yc(n2) {
|
|
12756
|
-
return ic(n2) && n2 >= -
|
|
12835
|
+
return ic(n2) && n2 >= -9007199254740991 && n2 <= Wn;
|
|
12757
12836
|
}
|
|
12758
12837
|
function dc(n2) {
|
|
12759
12838
|
return "string" == typeof n2 || !bh(n2) && cc(n2) && we(n2) == rt;
|
|
@@ -12779,7 +12858,7 @@ lodash_min.exports;
|
|
|
12779
12858
|
}
|
|
12780
12859
|
function Ac(n2) {
|
|
12781
12860
|
if (!n2) return 0 === n2 ? n2 : 0;
|
|
12782
|
-
if (n2 = Ic(n2), n2 === Sn || n2 === -
|
|
12861
|
+
if (n2 = Ic(n2), n2 === Sn || n2 === -Infinity) {
|
|
12783
12862
|
return (n2 < 0 ? -1 : 1) * Ln;
|
|
12784
12863
|
}
|
|
12785
12864
|
return n2 === n2 ? n2 : 0;
|
|
@@ -12807,7 +12886,7 @@ lodash_min.exports;
|
|
|
12807
12886
|
return $u(n2, qc(n2));
|
|
12808
12887
|
}
|
|
12809
12888
|
function zc(n2) {
|
|
12810
|
-
return n2 ? Mr2(kc(n2), -
|
|
12889
|
+
return n2 ? Mr2(kc(n2), -9007199254740991, Wn) : 0 === n2 ? n2 : 0;
|
|
12811
12890
|
}
|
|
12812
12891
|
function Ec(n2) {
|
|
12813
12892
|
return null == n2 ? "" : vu(n2);
|
|
@@ -14720,7 +14799,6 @@ class DynamicOutputPropertyDef {
|
|
|
14720
14799
|
}
|
|
14721
14800
|
withNexusSymbol(DynamicOutputPropertyDef, NexusTypes.DynamicOutputProperty);
|
|
14722
14801
|
const virtualScalarAttributes = ["id"];
|
|
14723
|
-
const customFields = ["filterBy", "filterByValue"];
|
|
14724
14802
|
const addScalarAttribute = (builder, attributeName, attribute) => {
|
|
14725
14803
|
const { naming, mappers } = strapi.plugin("graphql").service("utils");
|
|
14726
14804
|
const gqlType = mappers.strapiScalarToGraphQLScalar(attribute.type);
|
|
@@ -14769,19 +14847,16 @@ const gqlService = ({ strapi: strapi2 }) => {
|
|
|
14769
14847
|
}
|
|
14770
14848
|
if (Array.isArray(queryFilters)) {
|
|
14771
14849
|
return queryFilters.reduce((acc, filtersItem) => {
|
|
14772
|
-
|
|
14773
|
-
acc.push(graphQLFiltersToStrapiQuery(filtersItem, contentType));
|
|
14774
|
-
}
|
|
14850
|
+
acc.push(graphQLFiltersToStrapiQuery(filtersItem, contentType));
|
|
14775
14851
|
return acc;
|
|
14776
|
-
});
|
|
14852
|
+
}, []);
|
|
14777
14853
|
}
|
|
14778
14854
|
const resultMap = {};
|
|
14779
|
-
const { filterBy, filterByValue, ...filters } = queryFilters;
|
|
14780
14855
|
const { attributes } = contentType;
|
|
14781
14856
|
const isAttribute = (attributeName) => {
|
|
14782
14857
|
return virtualScalarAttributes.includes(attributeName) || fp.has(attributeName, attributes);
|
|
14783
14858
|
};
|
|
14784
|
-
for (const [key, value] of Object.entries(
|
|
14859
|
+
for (const [key, value] of Object.entries(queryFilters)) {
|
|
14785
14860
|
if (isAttribute(key)) {
|
|
14786
14861
|
const attribute = attributes[key];
|
|
14787
14862
|
if (virtualScalarAttributes.includes(key) || isStrapiScalar(attribute)) {
|
|
@@ -14803,23 +14878,6 @@ const gqlService = ({ strapi: strapi2 }) => {
|
|
|
14803
14878
|
}
|
|
14804
14879
|
}
|
|
14805
14880
|
}
|
|
14806
|
-
if (filterBy === "DATE_CREATED") {
|
|
14807
|
-
const date = new Date(filterByValue);
|
|
14808
|
-
if (!filterByValue || Number.isNaN(+date)) {
|
|
14809
|
-
throw new Error('Invalid date specified in "filterByValue"');
|
|
14810
|
-
}
|
|
14811
|
-
const start = date.setHours(0, 0, 0, 0);
|
|
14812
|
-
const end = date.setHours(23, 59, 59, 999);
|
|
14813
|
-
resultMap.createdAt = {
|
|
14814
|
-
$between: [start, end]
|
|
14815
|
-
};
|
|
14816
|
-
}
|
|
14817
|
-
if (filterBy === "APPROVAL_STATUS") {
|
|
14818
|
-
if (!filterByValue) {
|
|
14819
|
-
throw new Error('Empty "filterByValue" parameter');
|
|
14820
|
-
}
|
|
14821
|
-
resultMap.approvalStatus = filterByValue;
|
|
14822
|
-
}
|
|
14823
14881
|
return resultMap;
|
|
14824
14882
|
};
|
|
14825
14883
|
return {
|
|
@@ -14851,9 +14909,6 @@ const gqlService = ({ strapi: strapi2 }) => {
|
|
|
14851
14909
|
for (const operator of rootLevelOperators()) {
|
|
14852
14910
|
operator.add(t, filtersTypeName);
|
|
14853
14911
|
}
|
|
14854
|
-
customFields.forEach((field) => {
|
|
14855
|
-
t.field(field, { type: "String" });
|
|
14856
|
-
});
|
|
14857
14912
|
}
|
|
14858
14913
|
});
|
|
14859
14914
|
}
|