strapi-plugin-comments 3.0.0-beta.1 → 3.0.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 +81 -122
- package/dist/_chunks/{index-CY_AVWS-.js → index-B-ygLKrb.js} +417 -242
- package/dist/_chunks/{index-D3iNqWZT.mjs → index-BgN4aUMA.mjs} +5 -5
- package/dist/_chunks/{index-BBcsmSTs.mjs → index-Bx2boY6h.mjs} +420 -245
- package/dist/_chunks/{index-DJ32APz-.mjs → index-CIqMAf50.mjs} +1277 -1152
- package/dist/_chunks/{index-BXEk5PWx.js → index-CWfr5ejx.js} +20 -26
- package/dist/_chunks/{index-BFPteXuP.js → index-D8uskGzQ.js} +5 -5
- package/dist/_chunks/{index-Bcck91A8.js → index-DFAPx7Bl.js} +1290 -1144
- package/dist/_chunks/{index-D9MOkoQ2.mjs → index-Db2zwbpe.mjs} +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 +198 -144
- package/dist/server/index.mjs +198 -144
- 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 +117 -23
- package/dist/server/src/controllers/index.d.ts +297 -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 +921 -314
- 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 +177 -66
- 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 +608 -222
- 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 +10 -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.mjs
CHANGED
|
@@ -205,7 +205,7 @@ const getModelUid = (strapi2, name) => {
|
|
|
205
205
|
const getDefaultAuthorPopulate = (strapi2) => {
|
|
206
206
|
const strapiUserTypeUid = "plugin::users-permissions.user";
|
|
207
207
|
const allowedTypes = ["media", "relation"];
|
|
208
|
-
const { attributes } = strapi2.
|
|
208
|
+
const { attributes } = strapi2.contentType(strapiUserTypeUid) ?? { attributes: {} };
|
|
209
209
|
const relationTypes = Object.keys(attributes)?.filter(
|
|
210
210
|
(key) => allowedTypes.includes(attributes[key]?.type)
|
|
211
211
|
);
|
|
@@ -1038,7 +1038,7 @@ lodash.exports;
|
|
|
1038
1038
|
}
|
|
1039
1039
|
var runInContext = function runInContext2(context) {
|
|
1040
1040
|
context = context == null ? root : _2.defaults(root.Object(), context, _2.pick(root, contextProps));
|
|
1041
|
-
var Array2 = context.Array,
|
|
1041
|
+
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;
|
|
1042
1042
|
var arrayProto = Array2.prototype, funcProto = Function2.prototype, objectProto = Object2.prototype;
|
|
1043
1043
|
var coreJsData = context["__core-js_shared__"];
|
|
1044
1044
|
var funcToString = funcProto.toString;
|
|
@@ -1063,8 +1063,8 @@ lodash.exports;
|
|
|
1063
1063
|
} catch (e) {
|
|
1064
1064
|
}
|
|
1065
1065
|
}();
|
|
1066
|
-
var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout, ctxNow =
|
|
1067
|
-
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 =
|
|
1066
|
+
var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout, ctxNow = Date && Date.now !== root.Date.now && Date.now, ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout;
|
|
1067
|
+
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;
|
|
1068
1068
|
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");
|
|
1069
1069
|
var metaMap = WeakMap && new WeakMap();
|
|
1070
1070
|
var realNames = {};
|
|
@@ -2236,7 +2236,7 @@ lodash.exports;
|
|
|
2236
2236
|
return symbolToString ? symbolToString.call(value) : "";
|
|
2237
2237
|
}
|
|
2238
2238
|
var result2 = value + "";
|
|
2239
|
-
return result2 == "0" && 1 / value == -
|
|
2239
|
+
return result2 == "0" && 1 / value == -Infinity ? "-0" : result2;
|
|
2240
2240
|
}
|
|
2241
2241
|
function baseUniq(array, iteratee2, comparator) {
|
|
2242
2242
|
var index2 = -1, includes2 = arrayIncludes, length = array.length, isCommon = true, result2 = [], seen = result2;
|
|
@@ -2788,7 +2788,7 @@ lodash.exports;
|
|
|
2788
2788
|
bitmask |= isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG;
|
|
2789
2789
|
bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG);
|
|
2790
2790
|
if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) {
|
|
2791
|
-
bitmask &=
|
|
2791
|
+
bitmask &= -4;
|
|
2792
2792
|
}
|
|
2793
2793
|
var newData = [
|
|
2794
2794
|
func,
|
|
@@ -2844,7 +2844,7 @@ lodash.exports;
|
|
|
2844
2844
|
}
|
|
2845
2845
|
var length = partials ? partials.length : 0;
|
|
2846
2846
|
if (!length) {
|
|
2847
|
-
bitmask &=
|
|
2847
|
+
bitmask &= -97;
|
|
2848
2848
|
partials = holders = undefined$1;
|
|
2849
2849
|
}
|
|
2850
2850
|
ary2 = ary2 === undefined$1 ? ary2 : nativeMax(toInteger(ary2), 0);
|
|
@@ -2877,7 +2877,7 @@ lodash.exports;
|
|
|
2877
2877
|
holders = newData[4];
|
|
2878
2878
|
arity = newData[9] = newData[9] === undefined$1 ? isBindKey ? 0 : func.length : nativeMax(newData[9] - length, 0);
|
|
2879
2879
|
if (!arity && bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG)) {
|
|
2880
|
-
bitmask &=
|
|
2880
|
+
bitmask &= -25;
|
|
2881
2881
|
}
|
|
2882
2882
|
if (!bitmask || bitmask == WRAP_BIND_FLAG) {
|
|
2883
2883
|
var result2 = createBind(func, bitmask, thisArg);
|
|
@@ -3443,7 +3443,7 @@ lodash.exports;
|
|
|
3443
3443
|
return value;
|
|
3444
3444
|
}
|
|
3445
3445
|
var result2 = value + "";
|
|
3446
|
-
return result2 == "0" && 1 / value == -
|
|
3446
|
+
return result2 == "0" && 1 / value == -Infinity ? "-0" : result2;
|
|
3447
3447
|
}
|
|
3448
3448
|
function toSource(func) {
|
|
3449
3449
|
if (func != null) {
|
|
@@ -4507,7 +4507,7 @@ lodash.exports;
|
|
|
4507
4507
|
}
|
|
4508
4508
|
var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp;
|
|
4509
4509
|
function isSafeInteger(value) {
|
|
4510
|
-
return isInteger(value) && value >= -
|
|
4510
|
+
return isInteger(value) && value >= -9007199254740991 && value <= MAX_SAFE_INTEGER;
|
|
4511
4511
|
}
|
|
4512
4512
|
var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet;
|
|
4513
4513
|
function isString(value) {
|
|
@@ -4548,7 +4548,7 @@ lodash.exports;
|
|
|
4548
4548
|
return value === 0 ? value : 0;
|
|
4549
4549
|
}
|
|
4550
4550
|
value = toNumber(value);
|
|
4551
|
-
if (value === INFINITY || value === -
|
|
4551
|
+
if (value === INFINITY || value === -Infinity) {
|
|
4552
4552
|
var sign = value < 0 ? -1 : 1;
|
|
4553
4553
|
return sign * MAX_INTEGER;
|
|
4554
4554
|
}
|
|
@@ -4583,7 +4583,7 @@ lodash.exports;
|
|
|
4583
4583
|
return copyObject(value, keysIn(value));
|
|
4584
4584
|
}
|
|
4585
4585
|
function toSafeInteger(value) {
|
|
4586
|
-
return value ? baseClamp(toInteger(value), -
|
|
4586
|
+
return value ? baseClamp(toInteger(value), -9007199254740991, MAX_SAFE_INTEGER) : value === 0 ? value : 0;
|
|
4587
4587
|
}
|
|
4588
4588
|
function toString(value) {
|
|
4589
4589
|
return value == null ? "" : baseToString(value);
|
|
@@ -5821,29 +5821,6 @@ lodash.exports;
|
|
|
5821
5821
|
}).call(commonjsGlobal);
|
|
5822
5822
|
})(lodash, lodash.exports);
|
|
5823
5823
|
var lodashExports = lodash.exports;
|
|
5824
|
-
let PluginError$1 = class PluginError extends Error {
|
|
5825
|
-
constructor(status, message, payload = void 0) {
|
|
5826
|
-
super();
|
|
5827
|
-
this.name = "Strapi:Plugin:Comments";
|
|
5828
|
-
this.status = status || 500;
|
|
5829
|
-
this.message = message || "Internal error";
|
|
5830
|
-
this.payload = payload;
|
|
5831
|
-
Object.setPrototypeOf(this, PluginError.prototype);
|
|
5832
|
-
}
|
|
5833
|
-
toString(e = this) {
|
|
5834
|
-
return `${e.name} - ${e.message}`;
|
|
5835
|
-
}
|
|
5836
|
-
toJSON() {
|
|
5837
|
-
if (this.payload) {
|
|
5838
|
-
return {
|
|
5839
|
-
...this.payload,
|
|
5840
|
-
name: this.name,
|
|
5841
|
-
message: this.message
|
|
5842
|
-
};
|
|
5843
|
-
}
|
|
5844
|
-
return this;
|
|
5845
|
-
}
|
|
5846
|
-
};
|
|
5847
5824
|
const flatInput = (payload) => {
|
|
5848
5825
|
const {
|
|
5849
5826
|
sort,
|
|
@@ -5883,7 +5860,6 @@ const flatInput = (payload) => {
|
|
|
5883
5860
|
}
|
|
5884
5861
|
};
|
|
5885
5862
|
}
|
|
5886
|
-
({ ...filters });
|
|
5887
5863
|
return {
|
|
5888
5864
|
...payload,
|
|
5889
5865
|
filters: {
|
|
@@ -6024,6 +6000,7 @@ const getComment = (nexus) => {
|
|
|
6024
6000
|
name: "CommentSingle",
|
|
6025
6001
|
definition(t) {
|
|
6026
6002
|
t.id("id");
|
|
6003
|
+
t.string("documentId");
|
|
6027
6004
|
t.nonNull.string("content");
|
|
6028
6005
|
t.boolean("blocked");
|
|
6029
6006
|
t.boolean("blockedThread");
|
|
@@ -6059,6 +6036,7 @@ const getCommentNested = (nexus) => {
|
|
|
6059
6036
|
name: "CommentNested",
|
|
6060
6037
|
definition(t) {
|
|
6061
6038
|
t.id("id");
|
|
6039
|
+
t.string("documentId");
|
|
6062
6040
|
t.nonNull.string("content");
|
|
6063
6041
|
t.boolean("blocked");
|
|
6064
6042
|
t.boolean("blockedThread");
|
|
@@ -8110,8 +8088,19 @@ const typesFactories = [
|
|
|
8110
8088
|
getReport
|
|
8111
8089
|
];
|
|
8112
8090
|
const getTypes = (config2, nexus) => typesFactories.map((factory) => factory(nexus, config2));
|
|
8091
|
+
const getExtensionService = (strapi2) => strapi2.plugin("graphql").service("extension");
|
|
8092
|
+
const disableDefaultGQL = (strapi2) => {
|
|
8093
|
+
const extensionService = getExtensionService(strapi2);
|
|
8094
|
+
extensionService.shadowCRUD(getModelUid(strapi2, "comment")).disable();
|
|
8095
|
+
extensionService.shadowCRUD(getModelUid(strapi2, "comment")).disableQueries();
|
|
8096
|
+
extensionService.shadowCRUD(getModelUid(strapi2, "comment")).disableMutations();
|
|
8097
|
+
extensionService.shadowCRUD(getModelUid(strapi2, "comment-report")).disable();
|
|
8098
|
+
extensionService.shadowCRUD(getModelUid(strapi2, "comment-report")).disableQueries();
|
|
8099
|
+
extensionService.shadowCRUD(getModelUid(strapi2, "comment-report")).disableMutations();
|
|
8100
|
+
};
|
|
8113
8101
|
const setupGQL = async ({ strapi: strapi2 }) => {
|
|
8114
8102
|
if (strapi2.plugin("graphql")) {
|
|
8103
|
+
disableDefaultGQL(strapi2);
|
|
8115
8104
|
const enableCollections = await getPluginService(strapi2, "common").getConfig(CONFIG_PARAMS$1.ENABLED_COLLECTIONS, []);
|
|
8116
8105
|
if (enableCollections.length) {
|
|
8117
8106
|
await handleConfig(strapi2);
|
|
@@ -8119,13 +8108,7 @@ const setupGQL = async ({ strapi: strapi2 }) => {
|
|
|
8119
8108
|
}
|
|
8120
8109
|
};
|
|
8121
8110
|
const handleConfig = async (strapi2) => {
|
|
8122
|
-
const extensionService = strapi2
|
|
8123
|
-
extensionService.shadowCRUD(getModelUid(strapi2, "comment")).disable();
|
|
8124
|
-
extensionService.shadowCRUD(getModelUid(strapi2, "comment")).disableQueries();
|
|
8125
|
-
extensionService.shadowCRUD(getModelUid(strapi2, "comment")).disableMutations();
|
|
8126
|
-
extensionService.shadowCRUD(getModelUid(strapi2, "comment-report")).disable();
|
|
8127
|
-
extensionService.shadowCRUD(getModelUid(strapi2, "comment-report")).disableQueries();
|
|
8128
|
-
extensionService.shadowCRUD(getModelUid(strapi2, "comment-report")).disableMutations();
|
|
8111
|
+
const extensionService = getExtensionService(strapi2);
|
|
8129
8112
|
const config2 = await getPluginService(strapi2, "common").getConfig();
|
|
8130
8113
|
extensionService.use(({ strapi: strapi22, nexus }) => {
|
|
8131
8114
|
const types = getTypes(config2, nexus);
|
|
@@ -8234,7 +8217,11 @@ const schemaConfig = z.object({
|
|
|
8234
8217
|
[CONFIG_PARAMS.AUTHOR_BLOCKED_PROPS]: z.array(z.string()),
|
|
8235
8218
|
gql: z.object({
|
|
8236
8219
|
auth: z.boolean().optional()
|
|
8237
|
-
}).optional()
|
|
8220
|
+
}).optional(),
|
|
8221
|
+
client: z.object({
|
|
8222
|
+
url: z.string().nullable(),
|
|
8223
|
+
contactEmail: z.string().nullable()
|
|
8224
|
+
}).default({ url: null, contactEmail: null })
|
|
8238
8225
|
});
|
|
8239
8226
|
const config = {
|
|
8240
8227
|
default: schemaConfig.parse(defaultPluginConfig),
|
|
@@ -8271,14 +8258,14 @@ const isRight = (e) => {
|
|
|
8271
8258
|
};
|
|
8272
8259
|
const makeLeft = (value) => ({ left: value });
|
|
8273
8260
|
const makeRight = (value) => ({ right: value });
|
|
8274
|
-
class
|
|
8261
|
+
let PluginError$1 = class PluginError extends Error {
|
|
8275
8262
|
constructor(status, message, payload = void 0) {
|
|
8276
8263
|
super();
|
|
8277
8264
|
this.name = "Strapi:Plugin:Comments";
|
|
8278
8265
|
this.status = status || 500;
|
|
8279
8266
|
this.message = message || "Internal error";
|
|
8280
8267
|
this.payload = payload;
|
|
8281
|
-
Object.setPrototypeOf(this,
|
|
8268
|
+
Object.setPrototypeOf(this, PluginError.prototype);
|
|
8282
8269
|
}
|
|
8283
8270
|
toString(e = this) {
|
|
8284
8271
|
return `${e.name} - ${e.message}`;
|
|
@@ -8293,9 +8280,9 @@ class PluginError2 extends Error {
|
|
|
8293
8280
|
}
|
|
8294
8281
|
return this;
|
|
8295
8282
|
}
|
|
8296
|
-
}
|
|
8283
|
+
};
|
|
8297
8284
|
const throwError = (ctx, e) => {
|
|
8298
|
-
if (e instanceof
|
|
8285
|
+
if (e instanceof PluginError$1) {
|
|
8299
8286
|
return ctx.throw(e.status, JSON.stringify(e));
|
|
8300
8287
|
}
|
|
8301
8288
|
return e;
|
|
@@ -8382,7 +8369,7 @@ const queryPaginationSchema = z.object({ pageSize: stringToNumberValidator.defau
|
|
|
8382
8369
|
const validate = (result) => {
|
|
8383
8370
|
if (!result.success) {
|
|
8384
8371
|
const message = result.error.issues.map((i) => `Path: ${i.path.join(".")} Code: ${i.code} Message: ${i.message}`).join("\n");
|
|
8385
|
-
return makeLeft(new
|
|
8372
|
+
return makeLeft(new PluginError$1(400, message));
|
|
8386
8373
|
}
|
|
8387
8374
|
return makeRight(result.data);
|
|
8388
8375
|
};
|
|
@@ -8450,7 +8437,7 @@ const getCommentSchema = (enabledCollections) => {
|
|
|
8450
8437
|
relation: getRelationValidator(enabledCollections),
|
|
8451
8438
|
content: z.string().min(1),
|
|
8452
8439
|
author: externalAuthorSchema.optional(),
|
|
8453
|
-
threadOf: z.
|
|
8440
|
+
threadOf: z.string().optional(),
|
|
8454
8441
|
approvalStatus: z.nativeEnum(APPROVAL_STATUS).optional(),
|
|
8455
8442
|
locale: z.string().optional()
|
|
8456
8443
|
});
|
|
@@ -8537,16 +8524,16 @@ const findAllPerAuthorValidator = (params, payload) => {
|
|
|
8537
8524
|
...params
|
|
8538
8525
|
}));
|
|
8539
8526
|
};
|
|
8540
|
-
const getReportAbuseSchema = (
|
|
8527
|
+
const getReportAbuseSchema = (config2) => {
|
|
8541
8528
|
return z.object({
|
|
8542
|
-
relation: getRelationValidator(
|
|
8543
|
-
commentId:
|
|
8529
|
+
relation: getRelationValidator(config2[CONFIG_PARAMS.ENABLED_COLLECTIONS]),
|
|
8530
|
+
commentId: stringToNumberValidator,
|
|
8544
8531
|
content: z.string().min(1),
|
|
8545
|
-
reason: z.
|
|
8532
|
+
reason: z.nativeEnum(config2.reportReasons)
|
|
8546
8533
|
});
|
|
8547
8534
|
};
|
|
8548
|
-
const reportAbuseValidator = (
|
|
8549
|
-
return validate(getReportAbuseSchema(
|
|
8535
|
+
const reportAbuseValidator = (config2, payload) => {
|
|
8536
|
+
return validate(getReportAbuseSchema(config2).safeParse(payload));
|
|
8550
8537
|
};
|
|
8551
8538
|
const getRemoveCommentSchema = (enabledCollections) => {
|
|
8552
8539
|
return z.object({
|
|
@@ -8713,7 +8700,7 @@ const dbBaseCommentSchema = z.object({
|
|
|
8713
8700
|
authorName: z.string().nullable(),
|
|
8714
8701
|
authorEmail: z.string().email().nullable(),
|
|
8715
8702
|
authorAvatar: z.string().nullable(),
|
|
8716
|
-
authorUser: z.string().optional().nullable(),
|
|
8703
|
+
authorUser: z.union([z.string(), z.object({ id: z.number(), email: z.string().email() })]).optional().nullable(),
|
|
8717
8704
|
locale: z.string().nullable()
|
|
8718
8705
|
});
|
|
8719
8706
|
const paginationSchema = z.object({
|
|
@@ -8803,7 +8790,7 @@ const reportSchema = z.object({
|
|
|
8803
8790
|
updatedAt: z.string(),
|
|
8804
8791
|
publishedAt: z.string().nullable(),
|
|
8805
8792
|
locale: z.string().nullable(),
|
|
8806
|
-
related: relatedSchema.nullable()
|
|
8793
|
+
related: relatedSchema.nullable().optional()
|
|
8807
8794
|
});
|
|
8808
8795
|
const findPageSchema = z.object({
|
|
8809
8796
|
results: z.array(reportSchema),
|
|
@@ -8838,7 +8825,7 @@ const reportResultValidator = {
|
|
|
8838
8825
|
update: updateResultSchema,
|
|
8839
8826
|
create: reportSchema
|
|
8840
8827
|
};
|
|
8841
|
-
const
|
|
8828
|
+
const getReportCommentRepositorySource = (strapi2) => {
|
|
8842
8829
|
const modelUid = getModelUid(strapi2, "comment-report");
|
|
8843
8830
|
const repository = strapi2.query(modelUid);
|
|
8844
8831
|
return {
|
|
@@ -8862,8 +8849,9 @@ const getReportCommentRepository = lodashExports.once((strapi2) => {
|
|
|
8862
8849
|
return repository.create(params).then(shouldValidateObject(isValidationEnabled, reportResultValidator.create));
|
|
8863
8850
|
}
|
|
8864
8851
|
};
|
|
8865
|
-
}
|
|
8866
|
-
const
|
|
8852
|
+
};
|
|
8853
|
+
const getReportCommentRepository = lodashExports.once(getReportCommentRepositorySource);
|
|
8854
|
+
const getCommentRepositorySource = (strapi2) => {
|
|
8867
8855
|
const modelUid = getModelUid(strapi2, "comment");
|
|
8868
8856
|
return {
|
|
8869
8857
|
async findMany(params) {
|
|
@@ -8894,8 +8882,9 @@ const getCommentRepository = lodashExports.once((strapi2) => {
|
|
|
8894
8882
|
return strapi2.query(modelUid).create(params).then(shouldValidateObject(isValidationEnabled, commentResultValidator.create));
|
|
8895
8883
|
}
|
|
8896
8884
|
};
|
|
8897
|
-
}
|
|
8898
|
-
const
|
|
8885
|
+
};
|
|
8886
|
+
const getCommentRepository = lodashExports.once(getCommentRepositorySource);
|
|
8887
|
+
const getStoreRepositorySource = (strapi2) => {
|
|
8899
8888
|
return {
|
|
8900
8889
|
getLocalConfig(prop, defaultValue) {
|
|
8901
8890
|
return strapi2.config.get([PLUGIN_SELECTOR, prop].filter(Boolean).join("."), defaultValue);
|
|
@@ -8972,7 +8961,8 @@ const getStoreRepository = lodashExports.once((strapi2) => {
|
|
|
8972
8961
|
return this.get();
|
|
8973
8962
|
}
|
|
8974
8963
|
};
|
|
8975
|
-
}
|
|
8964
|
+
};
|
|
8965
|
+
const getStoreRepository = lodashExports.once(getStoreRepositorySource);
|
|
8976
8966
|
const controllers$1 = ({ strapi: strapi2 }) => ({
|
|
8977
8967
|
getService(name) {
|
|
8978
8968
|
return getPluginService(strapi2, name);
|
|
@@ -8984,7 +8974,6 @@ const controllers$1 = ({ strapi: strapi2 }) => ({
|
|
|
8984
8974
|
const configResult = await this.getStoreRepository().get(true);
|
|
8985
8975
|
if (isRight(configResult)) {
|
|
8986
8976
|
const config2 = unwrapEither(configResult);
|
|
8987
|
-
console.log("config.enabledCollections", config2.enabledCollections);
|
|
8988
8977
|
const result = newCommentValidator(config2.enabledCollections, ctx.params.relation, ctx.request.body);
|
|
8989
8978
|
if (isRight(result)) {
|
|
8990
8979
|
return this.getService("client").create(result.right, ctx.state.user);
|
|
@@ -9056,7 +9045,7 @@ const controllers$1 = ({ strapi: strapi2 }) => ({
|
|
|
9056
9045
|
const configResult = await this.getStoreRepository().get(true);
|
|
9057
9046
|
if (isRight(configResult)) {
|
|
9058
9047
|
const config2 = unwrapEither(configResult);
|
|
9059
|
-
const result = reportAbuseValidator(config2
|
|
9048
|
+
const result = reportAbuseValidator(config2, {
|
|
9060
9049
|
...ctx.request.body,
|
|
9061
9050
|
...ctx.params
|
|
9062
9051
|
});
|
|
@@ -9327,7 +9316,6 @@ const routes$1 = [
|
|
|
9327
9316
|
path: "/:relation",
|
|
9328
9317
|
handler: "client.findAllInHierarchy",
|
|
9329
9318
|
config: {
|
|
9330
|
-
auth: false,
|
|
9331
9319
|
policies: [],
|
|
9332
9320
|
description: "Find all comments related to configured Collection / Single Type and return them in a nested structure",
|
|
9333
9321
|
tag: {
|
|
@@ -9342,7 +9330,6 @@ const routes$1 = [
|
|
|
9342
9330
|
path: "/:relation",
|
|
9343
9331
|
handler: "client.post",
|
|
9344
9332
|
config: {
|
|
9345
|
-
auth: false,
|
|
9346
9333
|
policies: [],
|
|
9347
9334
|
description: "Post a comment against configured Collection / Single Type",
|
|
9348
9335
|
tag: {
|
|
@@ -9357,7 +9344,6 @@ const routes$1 = [
|
|
|
9357
9344
|
path: "/:relation/flat",
|
|
9358
9345
|
handler: "client.findAllFlat",
|
|
9359
9346
|
config: {
|
|
9360
|
-
auth: false,
|
|
9361
9347
|
policies: [],
|
|
9362
9348
|
description: "Find all comments related to configured Collection / Single Type and return them in a flat structure for further processing",
|
|
9363
9349
|
tag: {
|
|
@@ -9372,7 +9358,6 @@ const routes$1 = [
|
|
|
9372
9358
|
path: "/:relation/comment/:commentId",
|
|
9373
9359
|
handler: "client.put",
|
|
9374
9360
|
config: {
|
|
9375
|
-
auth: false,
|
|
9376
9361
|
policies: [],
|
|
9377
9362
|
description: "Update comment related to configured Collection / Single Type if user is the author",
|
|
9378
9363
|
tag: {
|
|
@@ -9387,7 +9372,6 @@ const routes$1 = [
|
|
|
9387
9372
|
path: "/:relation/comment/:commentId/report-abuse",
|
|
9388
9373
|
handler: "client.reportAbuse",
|
|
9389
9374
|
config: {
|
|
9390
|
-
auth: false,
|
|
9391
9375
|
policies: [],
|
|
9392
9376
|
description: "Report an abuse against comment for configured Collection / Single Type",
|
|
9393
9377
|
tag: {
|
|
@@ -9402,7 +9386,6 @@ const routes$1 = [
|
|
|
9402
9386
|
path: "/:relation/comment/:commentId",
|
|
9403
9387
|
handler: "client.removeComment",
|
|
9404
9388
|
config: {
|
|
9405
|
-
auth: false,
|
|
9406
9389
|
policies: [],
|
|
9407
9390
|
description: "Remove comment related to configured Collection / Single Type if user is the author",
|
|
9408
9391
|
tag: {
|
|
@@ -9417,7 +9400,6 @@ const routes$1 = [
|
|
|
9417
9400
|
path: "/author/:authorId",
|
|
9418
9401
|
handler: "client.findAllPerAuthor",
|
|
9419
9402
|
config: {
|
|
9420
|
-
auth: false,
|
|
9421
9403
|
policies: [],
|
|
9422
9404
|
description: "Find all comments created by Strapi user",
|
|
9423
9405
|
tag: {
|
|
@@ -9432,7 +9414,6 @@ const routes$1 = [
|
|
|
9432
9414
|
path: "/author/:authorId/:type",
|
|
9433
9415
|
handler: "client.findAllPerAuthor",
|
|
9434
9416
|
config: {
|
|
9435
|
-
auth: false,
|
|
9436
9417
|
policies: [],
|
|
9437
9418
|
description: "Find all comments created by specified type of user",
|
|
9438
9419
|
tag: {
|
|
@@ -9453,6 +9434,29 @@ const routes = {
|
|
|
9453
9434
|
routes: adminRoutes$1
|
|
9454
9435
|
}
|
|
9455
9436
|
};
|
|
9437
|
+
class PluginError2 extends Error {
|
|
9438
|
+
constructor(status, message, payload = void 0) {
|
|
9439
|
+
super();
|
|
9440
|
+
this.name = "Strapi:Plugin:Comments";
|
|
9441
|
+
this.status = status || 500;
|
|
9442
|
+
this.message = message || "Internal error";
|
|
9443
|
+
this.payload = payload;
|
|
9444
|
+
Object.setPrototypeOf(this, PluginError2.prototype);
|
|
9445
|
+
}
|
|
9446
|
+
toString(e = this) {
|
|
9447
|
+
return `${e.name} - ${e.message}`;
|
|
9448
|
+
}
|
|
9449
|
+
toJSON() {
|
|
9450
|
+
if (this.payload) {
|
|
9451
|
+
return {
|
|
9452
|
+
...this.payload,
|
|
9453
|
+
name: this.name,
|
|
9454
|
+
message: this.message
|
|
9455
|
+
};
|
|
9456
|
+
}
|
|
9457
|
+
return this;
|
|
9458
|
+
}
|
|
9459
|
+
}
|
|
9456
9460
|
const buildNestedStructure = (entities, id = null, field = "threadOf", dropBlockedThreads = false, blockNestedThreads = false) => entities.filter((entity) => {
|
|
9457
9461
|
const entityField = lodashExports.get(entity, field);
|
|
9458
9462
|
if (entityField === null && id === null) {
|
|
@@ -9518,14 +9522,14 @@ const buildAuthorModel = (item, blockedAuthorProps, fieldsToPopulate = []) => {
|
|
|
9518
9522
|
);
|
|
9519
9523
|
return {
|
|
9520
9524
|
...rest,
|
|
9521
|
-
author
|
|
9525
|
+
author: lodashExports.isEmpty(author) ? item.author || {} : author
|
|
9522
9526
|
};
|
|
9523
9527
|
};
|
|
9524
9528
|
const resolveUserContextError = (user) => {
|
|
9525
9529
|
if (user) {
|
|
9526
|
-
throw new
|
|
9530
|
+
throw new PluginError2(401, "Not authenticated");
|
|
9527
9531
|
} else {
|
|
9528
|
-
throw new
|
|
9532
|
+
throw new PluginError2(403, "Not authorized");
|
|
9529
9533
|
}
|
|
9530
9534
|
};
|
|
9531
9535
|
const getAuthorName = (author) => {
|
|
@@ -9716,16 +9720,16 @@ const adminServices = ({ strapi: strapi2 }) => {
|
|
|
9716
9720
|
where: { id }
|
|
9717
9721
|
});
|
|
9718
9722
|
if (!entity) {
|
|
9719
|
-
throw new
|
|
9723
|
+
throw new PluginError$1(404, "Not found");
|
|
9720
9724
|
}
|
|
9721
9725
|
const { relatedId, uid } = this.getCommonService().parseRelationString(entity.related);
|
|
9722
|
-
const relatedEntity = await strapi2.
|
|
9726
|
+
const relatedEntity = await strapi2.documents(uid).findOne({ documentId: relatedId }).then((_2) => {
|
|
9723
9727
|
if (!_2) {
|
|
9724
|
-
throw new
|
|
9728
|
+
throw new PluginError$1(404, "Relation not found");
|
|
9725
9729
|
}
|
|
9726
9730
|
return { ..._2, uid };
|
|
9727
9731
|
});
|
|
9728
|
-
const levelThreadId = entity.threadOf && typeof entity.threadOf === "object" ? entity.threadOf.
|
|
9732
|
+
const levelThreadId = entity.threadOf && typeof entity.threadOf === "object" ? entity.threadOf.documentId : null;
|
|
9729
9733
|
const entitiesOnSameLevel = await this.getCommonService().findAllInHierarchy(
|
|
9730
9734
|
{
|
|
9731
9735
|
query: {
|
|
@@ -9782,7 +9786,7 @@ const adminServices = ({ strapi: strapi2 }) => {
|
|
|
9782
9786
|
data: { approvalStatus: APPROVAL_STATUS.APPROVED }
|
|
9783
9787
|
});
|
|
9784
9788
|
if (!entity) {
|
|
9785
|
-
throw new
|
|
9789
|
+
throw new PluginError$1(404, "Not found");
|
|
9786
9790
|
}
|
|
9787
9791
|
return this.getCommonService().sanitizeCommentEntity(entity, []);
|
|
9788
9792
|
},
|
|
@@ -9792,7 +9796,7 @@ const adminServices = ({ strapi: strapi2 }) => {
|
|
|
9792
9796
|
data: { approvalStatus: APPROVAL_STATUS.REJECTED }
|
|
9793
9797
|
});
|
|
9794
9798
|
if (!entity) {
|
|
9795
|
-
throw new
|
|
9799
|
+
throw new PluginError$1(404, "Not found");
|
|
9796
9800
|
}
|
|
9797
9801
|
return this.getCommonService().sanitizeCommentEntity(entity, []);
|
|
9798
9802
|
},
|
|
@@ -9838,14 +9842,14 @@ const adminServices = ({ strapi: strapi2 }) => {
|
|
|
9838
9842
|
}
|
|
9839
9843
|
});
|
|
9840
9844
|
}
|
|
9841
|
-
throw new
|
|
9845
|
+
throw new PluginError$1(
|
|
9842
9846
|
400,
|
|
9843
9847
|
"At least one of selected reports got invalid comment entity relation. Try again."
|
|
9844
9848
|
);
|
|
9845
9849
|
},
|
|
9846
9850
|
async resolveAllAbuseReportsForComment(id) {
|
|
9847
9851
|
if (!id) {
|
|
9848
|
-
throw new
|
|
9852
|
+
throw new PluginError$1(
|
|
9849
9853
|
400,
|
|
9850
9854
|
"There is something wrong with comment Id. Try again."
|
|
9851
9855
|
);
|
|
@@ -9862,7 +9866,7 @@ const adminServices = ({ strapi: strapi2 }) => {
|
|
|
9862
9866
|
},
|
|
9863
9867
|
async resolveAllAbuseReportsForThread(commentId) {
|
|
9864
9868
|
if (!commentId) {
|
|
9865
|
-
throw new
|
|
9869
|
+
throw new PluginError$1(
|
|
9866
9870
|
400,
|
|
9867
9871
|
"There is something wrong with comment Id. Try again."
|
|
9868
9872
|
);
|
|
@@ -9900,7 +9904,7 @@ const adminServices = ({ strapi: strapi2 }) => {
|
|
|
9900
9904
|
where: { id }
|
|
9901
9905
|
});
|
|
9902
9906
|
if (!entity) {
|
|
9903
|
-
throw new
|
|
9907
|
+
throw new PluginError$1(404, "Not found");
|
|
9904
9908
|
}
|
|
9905
9909
|
return getCommentRepository(strapi2).create({
|
|
9906
9910
|
data: {
|
|
@@ -9920,7 +9924,7 @@ const adminServices = ({ strapi: strapi2 }) => {
|
|
|
9920
9924
|
data: { content }
|
|
9921
9925
|
});
|
|
9922
9926
|
if (!entity) {
|
|
9923
|
-
throw new
|
|
9927
|
+
throw new PluginError$1(404, "Not found");
|
|
9924
9928
|
}
|
|
9925
9929
|
return this.getCommonService().sanitizeCommentEntity(entity, []);
|
|
9926
9930
|
}
|
|
@@ -9934,8 +9938,8 @@ const tryCatch = async (callback, throwError2) => {
|
|
|
9934
9938
|
}
|
|
9935
9939
|
};
|
|
9936
9940
|
const clientService = ({ strapi: strapi2 }) => {
|
|
9937
|
-
const createAuthor = (
|
|
9938
|
-
if (
|
|
9941
|
+
const createAuthor = (author, user) => {
|
|
9942
|
+
if (user) {
|
|
9939
9943
|
return {
|
|
9940
9944
|
authorUser: user.id
|
|
9941
9945
|
};
|
|
@@ -9957,7 +9961,7 @@ const clientService = ({ strapi: strapi2 }) => {
|
|
|
9957
9961
|
const { uid, relatedId } = this.getCommonService().parseRelationString(relation);
|
|
9958
9962
|
const relatedEntity = await strapi2.documents(uid).findOne({ documentId: relatedId, locale });
|
|
9959
9963
|
if (!relatedEntity) {
|
|
9960
|
-
throw new
|
|
9964
|
+
throw new PluginError2(
|
|
9961
9965
|
400,
|
|
9962
9966
|
`Relation for field "related" does not exist. Check your payload please.`
|
|
9963
9967
|
);
|
|
@@ -9972,21 +9976,24 @@ const clientService = ({ strapi: strapi2 }) => {
|
|
|
9972
9976
|
async () => {
|
|
9973
9977
|
return threadOf ? await this.getCommonService().findOne({ id: threadOf, related: relation, locale }) : null;
|
|
9974
9978
|
},
|
|
9975
|
-
new
|
|
9979
|
+
new PluginError2(400, "Thread does not exist")
|
|
9976
9980
|
);
|
|
9977
9981
|
if (isLeft(threadData)) {
|
|
9978
9982
|
throw unwrapEither(threadData);
|
|
9979
9983
|
}
|
|
9980
9984
|
const linkToThread = unwrapEither(threadData);
|
|
9981
|
-
this.getCommonService().isValidUserContext(user);
|
|
9985
|
+
const isValidContext = this.getCommonService().isValidUserContext(user);
|
|
9986
|
+
if (!isValidContext) {
|
|
9987
|
+
throw resolveUserContextError(user);
|
|
9988
|
+
}
|
|
9982
9989
|
const clearContent = await this.getCommonService().checkBadWords(content);
|
|
9983
|
-
const authorData = createAuthor(
|
|
9990
|
+
const authorData = createAuthor(author, user);
|
|
9984
9991
|
const authorNotProperlyProvided = !lodashExports.isEmpty(authorData) && !(authorData.authorId || authorData.authorUser);
|
|
9985
9992
|
if (lodashExports.isEmpty(authorData) || authorNotProperlyProvided) {
|
|
9986
|
-
throw new
|
|
9993
|
+
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.`);
|
|
9987
9994
|
}
|
|
9988
9995
|
if (isApprovalFlowEnabled && approvalStatus && approvalStatus !== APPROVAL_STATUS.PENDING) {
|
|
9989
|
-
throw new
|
|
9996
|
+
throw new PluginError2(400, "Invalid approval status");
|
|
9990
9997
|
}
|
|
9991
9998
|
const comment2 = await getCommentRepository(strapi2).create({
|
|
9992
9999
|
data: {
|
|
@@ -10039,7 +10046,7 @@ const clientService = ({ strapi: strapi2 }) => {
|
|
|
10039
10046
|
related: relation
|
|
10040
10047
|
});
|
|
10041
10048
|
if (reportAgainstEntity.isAdminComment) {
|
|
10042
|
-
throw new
|
|
10049
|
+
throw new PluginError2(
|
|
10043
10050
|
403,
|
|
10044
10051
|
`You're not allowed to take an action on that entity. This in a admin comment.`
|
|
10045
10052
|
);
|
|
@@ -10064,10 +10071,10 @@ const clientService = ({ strapi: strapi2 }) => {
|
|
|
10064
10071
|
return response;
|
|
10065
10072
|
}
|
|
10066
10073
|
} else {
|
|
10067
|
-
throw new
|
|
10074
|
+
throw new PluginError2(500, "Report cannot be created");
|
|
10068
10075
|
}
|
|
10069
10076
|
}
|
|
10070
|
-
throw new
|
|
10077
|
+
throw new PluginError2(
|
|
10071
10078
|
403,
|
|
10072
10079
|
`You're not allowed to take an action on that entity. Make sure that comment exist or you've authenticated your request properly.`
|
|
10073
10080
|
);
|
|
@@ -10081,7 +10088,7 @@ const clientService = ({ strapi: strapi2 }) => {
|
|
|
10081
10088
|
}
|
|
10082
10089
|
const author = user?.id || authorId;
|
|
10083
10090
|
if (!author) {
|
|
10084
|
-
throw new
|
|
10091
|
+
throw new PluginError2(
|
|
10085
10092
|
403,
|
|
10086
10093
|
`You're not allowed to take an action on that entity. Make sure that you've provided proper "authorId" or authenticated your request properly.`
|
|
10087
10094
|
);
|
|
@@ -10110,23 +10117,88 @@ const clientService = ({ strapi: strapi2 }) => {
|
|
|
10110
10117
|
const doNotPopulateAuthor = await this.getCommonService().getConfig(CONFIG_PARAMS$1.AUTHOR_BLOCKED_PROPS, []);
|
|
10111
10118
|
return this.getCommonService().sanitizeCommentEntity(removedEntity, doNotPopulateAuthor);
|
|
10112
10119
|
} else {
|
|
10113
|
-
throw new
|
|
10120
|
+
throw new PluginError2(
|
|
10114
10121
|
404,
|
|
10115
10122
|
`Entity does not exist or you're not allowed to take an action on it`
|
|
10116
10123
|
);
|
|
10117
10124
|
}
|
|
10118
10125
|
} catch (e) {
|
|
10119
|
-
throw new
|
|
10126
|
+
throw new PluginError2(
|
|
10120
10127
|
404,
|
|
10121
10128
|
`Entity does not exist or you're not allowed to take an action on it`
|
|
10122
10129
|
);
|
|
10123
10130
|
}
|
|
10124
10131
|
},
|
|
10125
10132
|
async sendAbuseReportEmail(reason, content) {
|
|
10133
|
+
const SUPER_ADMIN_ROLE = "strapi-super-admin";
|
|
10134
|
+
const rolesToNotify = await this.getCommonService().getConfig(CONFIG_PARAMS$1.MODERATOR_ROLES, [SUPER_ADMIN_ROLE]);
|
|
10135
|
+
if (rolesToNotify.length > 0) {
|
|
10136
|
+
const emails = await strapi2.query("admin::user").findMany({ where: { roles: { code: rolesToNotify } } }).then((users) => users.map((user) => user.email));
|
|
10137
|
+
if (emails.length > 0) {
|
|
10138
|
+
const from = await strapi2.query("admin::user").findOne({ where: { roles: { code: SUPER_ADMIN_ROLE } } });
|
|
10139
|
+
if (strapi2.plugin("email")) {
|
|
10140
|
+
await strapi2.plugin("email").service("email").send({
|
|
10141
|
+
to: emails,
|
|
10142
|
+
from: from.email,
|
|
10143
|
+
subject: "New abuse report on comment",
|
|
10144
|
+
text: `
|
|
10145
|
+
There was a new abuse report on your app.
|
|
10146
|
+
Reason: ${reason}
|
|
10147
|
+
Message: ${content}
|
|
10148
|
+
`
|
|
10149
|
+
});
|
|
10150
|
+
}
|
|
10151
|
+
}
|
|
10152
|
+
}
|
|
10126
10153
|
},
|
|
10127
10154
|
async markAsRemovedNested(commentId, status) {
|
|
10155
|
+
return this.getCommonService().modifiedNestedNestedComments(
|
|
10156
|
+
commentId,
|
|
10157
|
+
"removed",
|
|
10158
|
+
status
|
|
10159
|
+
);
|
|
10128
10160
|
},
|
|
10129
|
-
async sendResponseNotification(
|
|
10161
|
+
async sendResponseNotification(entity) {
|
|
10162
|
+
if (entity.threadOf) {
|
|
10163
|
+
const thread = typeof entity.threadOf === "object" ? entity.threadOf : await this.getCommonService().findOne({ id: entity.threadOf });
|
|
10164
|
+
let emailRecipient = thread?.author?.email;
|
|
10165
|
+
if (thread.authorUser && !emailRecipient) {
|
|
10166
|
+
const strapiUser = typeof thread.authorUser === "object" ? thread.authorUser : await strapi2.query("plugin::users-permissions.user").findOne({
|
|
10167
|
+
where: { id: thread.authorUser }
|
|
10168
|
+
});
|
|
10169
|
+
emailRecipient = strapiUser?.email;
|
|
10170
|
+
}
|
|
10171
|
+
if (emailRecipient) {
|
|
10172
|
+
const superAdmin = await strapi2.query("admin::user").findOne({
|
|
10173
|
+
where: {
|
|
10174
|
+
roles: { code: "strapi-super-admin" }
|
|
10175
|
+
}
|
|
10176
|
+
});
|
|
10177
|
+
const emailSender = await this.getCommonService().getConfig("client.contactEmail", superAdmin.email);
|
|
10178
|
+
const clientAppUrl = await this.getCommonService().getConfig("client.url", "our site");
|
|
10179
|
+
try {
|
|
10180
|
+
await strapi2.plugin("email").service("email").send({
|
|
10181
|
+
to: [emailRecipient],
|
|
10182
|
+
from: emailSender,
|
|
10183
|
+
subject: "You've got a new response to your comment",
|
|
10184
|
+
text: `Hello ${thread?.author?.name || emailRecipient}!
|
|
10185
|
+
You've got a new response to your comment by ${entity?.author?.name || entity?.author?.email}.
|
|
10186
|
+
|
|
10187
|
+
------
|
|
10188
|
+
|
|
10189
|
+
"${entity.content}"
|
|
10190
|
+
|
|
10191
|
+
------
|
|
10192
|
+
|
|
10193
|
+
Visit ${clientAppUrl} and continue the discussion.
|
|
10194
|
+
`
|
|
10195
|
+
});
|
|
10196
|
+
} catch (err) {
|
|
10197
|
+
strapi2.log.error(err);
|
|
10198
|
+
throw err;
|
|
10199
|
+
}
|
|
10200
|
+
}
|
|
10201
|
+
}
|
|
10130
10202
|
}
|
|
10131
10203
|
};
|
|
10132
10204
|
};
|
|
@@ -10136,7 +10208,7 @@ const commonService = ({ strapi: strapi2 }) => ({
|
|
|
10136
10208
|
async getConfig(prop, defaultValue, useLocal = false) {
|
|
10137
10209
|
const storeRepository = getStoreRepository(strapi2);
|
|
10138
10210
|
const config2 = await storeRepository.getConfig();
|
|
10139
|
-
if (prop &&
|
|
10211
|
+
if (prop && !useLocal) {
|
|
10140
10212
|
return lodashExports.get(config2, prop, defaultValue);
|
|
10141
10213
|
}
|
|
10142
10214
|
if (useLocal) {
|
|
@@ -10187,7 +10259,7 @@ const commonService = ({ strapi: strapi2 }) => ({
|
|
|
10187
10259
|
const [operator, direction] = getOrderBy(sort);
|
|
10188
10260
|
const fieldsQuery = {
|
|
10189
10261
|
sort: { [operator]: direction },
|
|
10190
|
-
select: Array.isArray(fields) ? lodashExports.uniq([...fields, defaultSelect]) : fields
|
|
10262
|
+
select: Array.isArray(fields) ? lodashExports.uniq([...fields, defaultSelect].flat()) : fields
|
|
10191
10263
|
};
|
|
10192
10264
|
const entries = await getCommentRepository(strapi2).findMany({
|
|
10193
10265
|
where: {
|
|
@@ -10274,10 +10346,12 @@ const commonService = ({ strapi: strapi2 }) => ({
|
|
|
10274
10346
|
authorUser: true
|
|
10275
10347
|
}
|
|
10276
10348
|
});
|
|
10349
|
+
console.log("findOne::entity", entity);
|
|
10277
10350
|
if (!entity) {
|
|
10278
|
-
throw new
|
|
10351
|
+
throw new PluginError$1(400, "Comment does not exist. Check your payload please.");
|
|
10279
10352
|
}
|
|
10280
10353
|
const doNotPopulateAuthor = await this.getConfig(CONFIG_PARAMS.AUTHOR_BLOCKED_PROPS, []);
|
|
10354
|
+
console.log("doNotPopulateAuthor", doNotPopulateAuthor);
|
|
10281
10355
|
const item = this.sanitizeCommentEntity(entity, doNotPopulateAuthor);
|
|
10282
10356
|
return filterOurResolvedReports(item);
|
|
10283
10357
|
},
|
|
@@ -10379,7 +10453,11 @@ const commonService = ({ strapi: strapi2 }) => ({
|
|
|
10379
10453
|
)
|
|
10380
10454
|
};
|
|
10381
10455
|
},
|
|
10382
|
-
|
|
10456
|
+
// TODO: we need to add deepLimit to the function to prevent infinite loops
|
|
10457
|
+
async modifiedNestedNestedComments(id, fieldName, value, deepLimit = 10) {
|
|
10458
|
+
if (deepLimit === 0) {
|
|
10459
|
+
return true;
|
|
10460
|
+
}
|
|
10383
10461
|
try {
|
|
10384
10462
|
const entities = await this.findMany({ where: { threadOf: id } });
|
|
10385
10463
|
const changedEntries = await getCommentRepository(strapi2).updateMany({
|
|
@@ -10388,7 +10466,7 @@ const commonService = ({ strapi: strapi2 }) => ({
|
|
|
10388
10466
|
});
|
|
10389
10467
|
if (entities.length === changedEntries.count && changedEntries.count > 0) {
|
|
10390
10468
|
const nestedTransactions = await Promise.all(
|
|
10391
|
-
entities.map((item) => this.modifiedNestedNestedComments(item.id, fieldName, value))
|
|
10469
|
+
entities.map((item) => this.modifiedNestedNestedComments(item.id, fieldName, value, deepLimit - 1))
|
|
10392
10470
|
);
|
|
10393
10471
|
return nestedTransactions.length === changedEntries.count;
|
|
10394
10472
|
}
|
|
@@ -10401,7 +10479,7 @@ const commonService = ({ strapi: strapi2 }) => ({
|
|
|
10401
10479
|
const config2 = await this.getConfig(CONFIG_PARAMS.BAD_WORDS, true);
|
|
10402
10480
|
if (config2) {
|
|
10403
10481
|
if (content && isProfane({ testString: content })) {
|
|
10404
|
-
throw new
|
|
10482
|
+
throw new PluginError$1(
|
|
10405
10483
|
400,
|
|
10406
10484
|
"Bad language used! Please polite your comment...",
|
|
10407
10485
|
{
|
|
@@ -11501,7 +11579,7 @@ lodash_min.exports;
|
|
|
11501
11579
|
if (bh(n2)) return c(n2, vu) + "";
|
|
11502
11580
|
if (bc(n2)) return vs ? vs.call(n2) : "";
|
|
11503
11581
|
var t2 = n2 + "";
|
|
11504
|
-
return "0" == t2 && 1 / n2 == -
|
|
11582
|
+
return "0" == t2 && 1 / n2 == -Infinity ? "-0" : t2;
|
|
11505
11583
|
}
|
|
11506
11584
|
function gu(n2, t2, r2) {
|
|
11507
11585
|
var e2 = -1, u2 = o, i2 = n2.length, c2 = true, a2 = [], l2 = a2;
|
|
@@ -11820,7 +11898,7 @@ lodash_min.exports;
|
|
|
11820
11898
|
}
|
|
11821
11899
|
function oi(n2, t2, r2, e2, u2, i2, o2, f2, c2, a2) {
|
|
11822
11900
|
var l2 = t2 & yn, s2 = l2 ? o2 : X, h2 = l2 ? X : o2, p3 = l2 ? i2 : X, _3 = l2 ? X : i2;
|
|
11823
|
-
t2 |= l2 ? bn : wn, t2 &= ~(l2 ? wn : bn), t2 & gn || (t2 &=
|
|
11901
|
+
t2 |= l2 ? bn : wn, t2 &= ~(l2 ? wn : bn), t2 & gn || (t2 &= -4);
|
|
11824
11902
|
var v2 = [n2, t2, u2, p3, s2, _3, h2, f2, c2, a2], g2 = r2.apply(X, v2);
|
|
11825
11903
|
return $i(n2) && Ss(g2, v2), g2.placeholder = e2, Yi(g2, n2, t2);
|
|
11826
11904
|
}
|
|
@@ -11844,12 +11922,12 @@ lodash_min.exports;
|
|
|
11844
11922
|
var c2 = t2 & vn;
|
|
11845
11923
|
if (!c2 && "function" != typeof n2) throw new pl(en);
|
|
11846
11924
|
var a2 = e2 ? e2.length : 0;
|
|
11847
|
-
if (a2 || (t2 &=
|
|
11925
|
+
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) {
|
|
11848
11926
|
var l2 = e2, s2 = u2;
|
|
11849
11927
|
e2 = u2 = X;
|
|
11850
11928
|
}
|
|
11851
11929
|
var h2 = c2 ? X : Os(n2), p3 = [n2, t2, r2, e2, u2, l2, s2, i2, o2, f2];
|
|
11852
|
-
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 &=
|
|
11930
|
+
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);
|
|
11853
11931
|
else var _3 = Zu(n2, t2, r2);
|
|
11854
11932
|
return Yi((h2 ? ms : Ss)(_3, p3), n2, t2);
|
|
11855
11933
|
}
|
|
@@ -12188,7 +12266,7 @@ lodash_min.exports;
|
|
|
12188
12266
|
function no(n2) {
|
|
12189
12267
|
if ("string" == typeof n2 || bc(n2)) return n2;
|
|
12190
12268
|
var t2 = n2 + "";
|
|
12191
|
-
return "0" == t2 && 1 / n2 == -
|
|
12269
|
+
return "0" == t2 && 1 / n2 == -Infinity ? "-0" : t2;
|
|
12192
12270
|
}
|
|
12193
12271
|
function to(n2) {
|
|
12194
12272
|
if (null != n2) {
|
|
@@ -12752,7 +12830,7 @@ lodash_min.exports;
|
|
|
12752
12830
|
return "function" == typeof r2 && r2 instanceof r2 && dl.call(r2) == jl;
|
|
12753
12831
|
}
|
|
12754
12832
|
function yc(n2) {
|
|
12755
|
-
return ic(n2) && n2 >= -
|
|
12833
|
+
return ic(n2) && n2 >= -9007199254740991 && n2 <= Wn;
|
|
12756
12834
|
}
|
|
12757
12835
|
function dc(n2) {
|
|
12758
12836
|
return "string" == typeof n2 || !bh(n2) && cc(n2) && we(n2) == rt;
|
|
@@ -12778,7 +12856,7 @@ lodash_min.exports;
|
|
|
12778
12856
|
}
|
|
12779
12857
|
function Ac(n2) {
|
|
12780
12858
|
if (!n2) return 0 === n2 ? n2 : 0;
|
|
12781
|
-
if (n2 = Ic(n2), n2 === Sn || n2 === -
|
|
12859
|
+
if (n2 = Ic(n2), n2 === Sn || n2 === -Infinity) {
|
|
12782
12860
|
return (n2 < 0 ? -1 : 1) * Ln;
|
|
12783
12861
|
}
|
|
12784
12862
|
return n2 === n2 ? n2 : 0;
|
|
@@ -12806,7 +12884,7 @@ lodash_min.exports;
|
|
|
12806
12884
|
return $u(n2, qc(n2));
|
|
12807
12885
|
}
|
|
12808
12886
|
function zc(n2) {
|
|
12809
|
-
return n2 ? Mr2(kc(n2), -
|
|
12887
|
+
return n2 ? Mr2(kc(n2), -9007199254740991, Wn) : 0 === n2 ? n2 : 0;
|
|
12810
12888
|
}
|
|
12811
12889
|
function Ec(n2) {
|
|
12812
12890
|
return null == n2 ? "" : vu(n2);
|
|
@@ -14719,7 +14797,6 @@ class DynamicOutputPropertyDef {
|
|
|
14719
14797
|
}
|
|
14720
14798
|
withNexusSymbol(DynamicOutputPropertyDef, NexusTypes.DynamicOutputProperty);
|
|
14721
14799
|
const virtualScalarAttributes = ["id"];
|
|
14722
|
-
const customFields = ["filterBy", "filterByValue"];
|
|
14723
14800
|
const addScalarAttribute = (builder, attributeName, attribute) => {
|
|
14724
14801
|
const { naming, mappers } = strapi.plugin("graphql").service("utils");
|
|
14725
14802
|
const gqlType = mappers.strapiScalarToGraphQLScalar(attribute.type);
|
|
@@ -14768,19 +14845,16 @@ const gqlService = ({ strapi: strapi2 }) => {
|
|
|
14768
14845
|
}
|
|
14769
14846
|
if (Array.isArray(queryFilters)) {
|
|
14770
14847
|
return queryFilters.reduce((acc, filtersItem) => {
|
|
14771
|
-
|
|
14772
|
-
acc.push(graphQLFiltersToStrapiQuery(filtersItem, contentType));
|
|
14773
|
-
}
|
|
14848
|
+
acc.push(graphQLFiltersToStrapiQuery(filtersItem, contentType));
|
|
14774
14849
|
return acc;
|
|
14775
|
-
});
|
|
14850
|
+
}, []);
|
|
14776
14851
|
}
|
|
14777
14852
|
const resultMap = {};
|
|
14778
|
-
const { filterBy, filterByValue, ...filters } = queryFilters;
|
|
14779
14853
|
const { attributes } = contentType;
|
|
14780
14854
|
const isAttribute = (attributeName) => {
|
|
14781
14855
|
return virtualScalarAttributes.includes(attributeName) || fp.has(attributeName, attributes);
|
|
14782
14856
|
};
|
|
14783
|
-
for (const [key, value] of Object.entries(
|
|
14857
|
+
for (const [key, value] of Object.entries(queryFilters)) {
|
|
14784
14858
|
if (isAttribute(key)) {
|
|
14785
14859
|
const attribute = attributes[key];
|
|
14786
14860
|
if (virtualScalarAttributes.includes(key) || isStrapiScalar(attribute)) {
|
|
@@ -14802,23 +14876,6 @@ const gqlService = ({ strapi: strapi2 }) => {
|
|
|
14802
14876
|
}
|
|
14803
14877
|
}
|
|
14804
14878
|
}
|
|
14805
|
-
if (filterBy === "DATE_CREATED") {
|
|
14806
|
-
const date = new Date(filterByValue);
|
|
14807
|
-
if (!filterByValue || Number.isNaN(+date)) {
|
|
14808
|
-
throw new Error('Invalid date specified in "filterByValue"');
|
|
14809
|
-
}
|
|
14810
|
-
const start = date.setHours(0, 0, 0, 0);
|
|
14811
|
-
const end = date.setHours(23, 59, 59, 999);
|
|
14812
|
-
resultMap.createdAt = {
|
|
14813
|
-
$between: [start, end]
|
|
14814
|
-
};
|
|
14815
|
-
}
|
|
14816
|
-
if (filterBy === "APPROVAL_STATUS") {
|
|
14817
|
-
if (!filterByValue) {
|
|
14818
|
-
throw new Error('Empty "filterByValue" parameter');
|
|
14819
|
-
}
|
|
14820
|
-
resultMap.approvalStatus = filterByValue;
|
|
14821
|
-
}
|
|
14822
14879
|
return resultMap;
|
|
14823
14880
|
};
|
|
14824
14881
|
return {
|
|
@@ -14850,9 +14907,6 @@ const gqlService = ({ strapi: strapi2 }) => {
|
|
|
14850
14907
|
for (const operator of rootLevelOperators()) {
|
|
14851
14908
|
operator.add(t, filtersTypeName);
|
|
14852
14909
|
}
|
|
14853
|
-
customFields.forEach((field) => {
|
|
14854
|
-
t.field(field, { type: "String" });
|
|
14855
|
-
});
|
|
14856
14910
|
}
|
|
14857
14911
|
});
|
|
14858
14912
|
}
|