@rnaga/wp-node 1.3.6 → 1.3.9
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/crud/comment.crud.d.ts.map +1 -1
- package/crud/comment.crud.js +33 -9
- package/crud/meta.crud.d.ts +1 -1
- package/package.json +1 -1
- package/query-builder/comments.query.d.ts +1 -0
- package/query-builder/comments.query.d.ts.map +1 -1
- package/query-builder/comments.query.js +7 -0
- package/transactions/comment.trx.d.ts.map +1 -1
- package/transactions/comment.trx.js +33 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"comment.crud.d.ts","sourceRoot":"","sources":["../../src/crud/comment.crud.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGhD,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAKnD,OAAO,KAAK,GAAG,MAAM,eAAe,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAI9B,KAAK,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,GAAG,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;AAExD,KAAK,YAAY,GAAG;IAClB,cAAc,EAAE,MAAM,CAAC;IACvB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,wBAAwB,CAAC,E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AAC,CAAC,EAC1D,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,CAAC,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE;;;;;;;;;;;CA+LvE"}
|
package/crud/comment.crud.js
CHANGED
|
@@ -174,6 +174,11 @@ let CommentCrud = class CommentCrud extends crud_1.Crud {
|
|
|
174
174
|
throw new error_1.CrudError(error_1.StatusMessage.NOT_FOUND, "Comment not found");
|
|
175
175
|
}
|
|
176
176
|
const { user } = await this.getUser();
|
|
177
|
+
// If comment type is "note", then only allow users who can "edit_comment"
|
|
178
|
+
if (comment.props.comment_type === "note" &&
|
|
179
|
+
!(await user.can("edit_comment", comment.props.comment_ID))) {
|
|
180
|
+
throw new error_1.CrudError(error_1.StatusMessage.UNAUTHORIZED, "Sorry, you are not allowed to read this comment");
|
|
181
|
+
}
|
|
177
182
|
if (context == "edit" && !(await user.can("moderate_comments"))) {
|
|
178
183
|
throw new error_1.CrudError(error_1.StatusMessage.UNAUTHORIZED, "Sorry, you are not allowed to edit comments");
|
|
179
184
|
}
|
|
@@ -190,9 +195,11 @@ let CommentCrud = class CommentCrud extends crud_1.Crud {
|
|
|
190
195
|
const { remoteIp } = options ?? {};
|
|
191
196
|
const { user, userId } = await this.getUser();
|
|
192
197
|
const role = await user.role();
|
|
193
|
-
if (
|
|
198
|
+
if (role.is("anonymous") || !user.props) {
|
|
194
199
|
const options = this.components.get(options_1.Options);
|
|
195
|
-
if (await options.get("comment_registration"))
|
|
200
|
+
if ((await options.get("comment_registration")) ||
|
|
201
|
+
// Don't allow anonymous users to create notes (since WP 6.9)
|
|
202
|
+
data.comment_type === "note") {
|
|
196
203
|
throw new error_1.CrudError(error_1.StatusMessage.UNAUTHORIZED, "Sorry, you must be logged in to comment");
|
|
197
204
|
}
|
|
198
205
|
}
|
|
@@ -213,24 +220,37 @@ let CommentCrud = class CommentCrud extends crud_1.Crud {
|
|
|
213
220
|
if (!data.comment_post_ID) {
|
|
214
221
|
throw new error_1.CrudError(error_1.StatusMessage.UNAUTHORIZED, "Sorry, you are not allowed to create this comment without a post");
|
|
215
222
|
}
|
|
216
|
-
const
|
|
223
|
+
const postUtil = this.components.get(post_util_1.PostUtil);
|
|
224
|
+
const post = await postUtil.get(data.comment_post_ID);
|
|
225
|
+
// Check for notes
|
|
226
|
+
const isNote = data.comment_type === "note";
|
|
227
|
+
if (isNote && !(await user.can("edit_post", data.comment_post_ID))) {
|
|
228
|
+
throw new error_1.CrudError(error_1.StatusMessage.UNAUTHORIZED, "Sorry, you are not allowed to create a note on this post");
|
|
229
|
+
}
|
|
217
230
|
if (!post.props ||
|
|
218
|
-
"draft" === post.props.post_status ||
|
|
231
|
+
(!isNote && "draft" === post.props.post_status) ||
|
|
219
232
|
"trash" === post.props.post_status ||
|
|
220
233
|
!this.canReadPostComment(post) ||
|
|
221
|
-
!this.commentUtil.isOpen(post)) {
|
|
234
|
+
(!this.commentUtil.isOpen(post) && !isNote)) {
|
|
222
235
|
throw new error_1.CrudError(error_1.StatusMessage.UNAUTHORIZED, "Sorry, you are not allowed to create a comment on this post");
|
|
223
236
|
}
|
|
224
237
|
if (data.comment_ID) {
|
|
225
238
|
throw new error_1.CrudError(error_1.StatusMessage.BAD_REQUEST, "Cannot create existing comment");
|
|
226
239
|
}
|
|
227
|
-
// Do not allow comments to be created with a non-default type.
|
|
240
|
+
// Do not allow comments to be created with a non-default type or note.
|
|
228
241
|
if (data.comment_type &&
|
|
229
242
|
data.comment_type?.length > 0 &&
|
|
230
|
-
"comment" !== data.comment_type
|
|
243
|
+
"comment" !== data.comment_type &&
|
|
244
|
+
"note" !== data.comment_type) {
|
|
231
245
|
throw new error_1.CrudError(error_1.StatusMessage.BAD_REQUEST, "Cannot create a comment with that type");
|
|
232
246
|
}
|
|
233
|
-
|
|
247
|
+
// Dont allow empty comment unless "_wp_note_status" meta is set
|
|
248
|
+
// and comment type is note
|
|
249
|
+
const noteMetaStatus = data.comment_meta?.["_wp_note_status"];
|
|
250
|
+
const isNoteMetaAllowed = data.comment_type === "note" &&
|
|
251
|
+
(noteMetaStatus === "resolved" || noteMetaStatus === "reopen");
|
|
252
|
+
if (!isNoteMetaAllowed &&
|
|
253
|
+
(!data.comment_content || data.comment_content == "")) {
|
|
234
254
|
throw new error_1.CrudError(error_1.StatusMessage.BAD_REQUEST, "Invalid comment content");
|
|
235
255
|
}
|
|
236
256
|
// Set author data if the user's logged in.
|
|
@@ -258,7 +278,11 @@ let CommentCrud = class CommentCrud extends crud_1.Crud {
|
|
|
258
278
|
(await optionsCore.get("require_name_email"))) {
|
|
259
279
|
throw new error_1.CrudError(error_1.StatusMessage.UNAUTHORIZED, "Creating a comment requires valid author name and email values.");
|
|
260
280
|
}
|
|
261
|
-
|
|
281
|
+
// Don't check for duplicates or flooding for notes.
|
|
282
|
+
data.comment_approved =
|
|
283
|
+
"note" === data.comment_type
|
|
284
|
+
? "1"
|
|
285
|
+
: await this.commentUtil.getStatus(data);
|
|
262
286
|
const commentTrx = this.components.get(transactions_1.CommentTrx);
|
|
263
287
|
return this.returnValue(await commentTrx.upsert(data));
|
|
264
288
|
}
|
package/crud/meta.crud.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ export declare class MetaCrud extends Crud {
|
|
|
28
28
|
data: number;
|
|
29
29
|
info: undefined;
|
|
30
30
|
}>;
|
|
31
|
-
list(table: types.MetaTable, args?: Partial<z.infer<typeof val.crud.
|
|
31
|
+
list(table: types.MetaTable, args?: Partial<z.infer<typeof val.crud.metaListParams>>, options?: {
|
|
32
32
|
unserialize?: boolean;
|
|
33
33
|
}): Promise<{
|
|
34
34
|
data: ({
|
package/package.json
CHANGED
|
@@ -16,6 +16,7 @@ export declare class CommentsQuery extends QueryBuilder<CommentsQuery> {
|
|
|
16
16
|
get children(): CommentsQuery;
|
|
17
17
|
get(id: number): this;
|
|
18
18
|
countApproved(postId: number): this;
|
|
19
|
+
withoutNote(): this;
|
|
19
20
|
withMeta(type?: "inner" | "right"): this;
|
|
20
21
|
withPosts(ids?: number[], type?: "inner" | "left"): this;
|
|
21
22
|
withUsers(userIds?: number[], type?: "inner" | "left"): this;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"comments.query.d.ts","sourceRoot":"","sources":["../../src/query-builder/comments.query.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,OAAO,KAAK,KAAK,KAAK,MAAM,UAAU,CAAC;AAEvC,KAAK,WAAW,CAAC,CAAC,SAAS,MAAM,IAC/B,WAAW,CAAC,EAAE,SAAS,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAE/D,KAAK,eAAe,GAAG,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,SAAS,GAAG,MAAM,IAAI,MAAM,CAAC,EAAE,GAC3E,CAAC,GACD,KAAK,CAAC;AAEV,qBACa,aAAc,SAAQ,YAAY,CAAC,aAAa,CAAC;;IAKnD,KAAK,EAAE,KAAK,CAAC,KAAK,GAAG,GAAG,GAAG,IAAI,GAAG,KAAK,CAAC;IAC/C,SAAS,CAAC,QAAQ,EAAE,aAAa;IAC1B,OAAO,EAAE,KAAK,CAAC,YAAY;IANpC,QAAQ,CAAC,KAAK,cAAc;gBAInB,KAAK,EAAE,KAAK,CAAC,KAAK,GAAG,GAAG,GAAG,IAAI,GAAG,KAAK,CAAC,EACrC,QAAQ,EAAE,aAAa,EAC1B,OAAO,EAAE,KAAK,CAAC,YAAY;IAKpC,IAAI,IAAI,SAGP;IAED,IAAI,MAAM,8BAKT;IAED,IAAI,QAAQ,kBAKX;IAED,GAAG,CAAC,EAAE,EAAE,MAAM;IAMd,aAAa,CAAC,MAAM,EAAE,MAAM;
|
|
1
|
+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,MAAY;CAoBnB"}
|
|
@@ -56,6 +56,13 @@ let CommentsQuery = CommentsQuery_1 = class CommentsQuery extends query_builder_
|
|
|
56
56
|
.where(column("comments", "comment_post_ID"), postId)
|
|
57
57
|
.where(column("comments", "comment_approved"), "1")
|
|
58
58
|
.count("* as count");
|
|
59
|
+
this.withoutNote();
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
// Exclude notes (since WP 6.9)
|
|
63
|
+
withoutNote() {
|
|
64
|
+
const { column } = this.alias;
|
|
65
|
+
this.builder.whereNotIn(column("comments", "comment_type"), ["note"]);
|
|
59
66
|
return this;
|
|
60
67
|
}
|
|
61
68
|
withMeta(type = "right") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"comment.trx.d.ts","sourceRoot":"","sources":["../../src/transactions/comment.trx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAMxC,OAAO,QAAQ,MAAM,aAAa,CAAC;AAEnC,OAAO,KAAK,GAAG,MAAM,eAAe,CAAC;AAErC,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAE5B,KAAK,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,GAAG,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;AAExD,qBACa,UAAW,SAAQ,GAAG;IAE/B,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,UAAU;gBAHV,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,UAAU;IAK1B,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"comment.trx.d.ts","sourceRoot":"","sources":["../../src/transactions/comment.trx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAMxC,OAAO,QAAQ,MAAM,aAAa,CAAC;AAEnC,OAAO,KAAK,GAAG,MAAM,eAAe,CAAC;AAErC,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAE5B,KAAK,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,GAAG,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;AAExD,qBACa,UAAW,SAAQ,GAAG;IAE/B,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,UAAU;gBAHV,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,UAAU;IAK1B,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,UAAU,CAAC;IA2GjC,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,GAAE,MAAW;IAiCnD,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,UAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;IAiE1D,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAsE1C,YAAY,CAChB,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,GAAG,GAAG,GAAG,SAAS,GAAG,GAAG,GAAG,MAAM,GAAG,OAAO;CA6CnE"}
|
|
@@ -90,7 +90,14 @@ let CommentTrx = class CommentTrx extends trx_1.Trx {
|
|
|
90
90
|
...input,
|
|
91
91
|
};
|
|
92
92
|
}
|
|
93
|
-
|
|
93
|
+
// If comment type is "note", it can allow empty content.
|
|
94
|
+
const parsedInput = input.comment_type === "note"
|
|
95
|
+
? val.trx.commentUpsert
|
|
96
|
+
.extend({
|
|
97
|
+
comment_content: zod_1.z.string().optional().default(""),
|
|
98
|
+
})
|
|
99
|
+
.parse(input)
|
|
100
|
+
: val.trx.commentUpsert.parse(input);
|
|
94
101
|
const dateTimeUtil = this.components.get(date_time_util_1.DateTimeUtil);
|
|
95
102
|
const dateTime = dateTimeUtil.get();
|
|
96
103
|
parsedInput.comment_date = dateTime.mySQLDatetime;
|
|
@@ -241,7 +248,20 @@ let CommentTrx = class CommentTrx extends trx_1.Trx {
|
|
|
241
248
|
async trash(commentId) {
|
|
242
249
|
const EMPTY_TRASH_DAYS = this.config.config.constants.EMPTY_TRASH_DAYS;
|
|
243
250
|
if (!EMPTY_TRASH_DAYS) {
|
|
244
|
-
|
|
251
|
+
const commentUtil = this.components.get(comment_util_1.CommentUtil);
|
|
252
|
+
const comment = await commentUtil.get(commentId);
|
|
253
|
+
const commentChildren = await comment.children();
|
|
254
|
+
// First remove the comment itself (parent)
|
|
255
|
+
let success = await this.remove(commentId, true);
|
|
256
|
+
// Check if comment is note type and it's parent comment,
|
|
257
|
+
// then remove children too (since WP 6.9)
|
|
258
|
+
if (comment.props?.comment_type === "note" &&
|
|
259
|
+
0 === comment.props.comment_parent) {
|
|
260
|
+
for (const child of commentChildren || []) {
|
|
261
|
+
success = success && (await this.remove(child.comment_ID, true));
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return success;
|
|
245
265
|
}
|
|
246
266
|
const queryUtil = this.components.get(query_util_1.QueryUtil);
|
|
247
267
|
const comment = await queryUtil.comments((query) => {
|
|
@@ -257,7 +277,17 @@ let CommentTrx = class CommentTrx extends trx_1.Trx {
|
|
|
257
277
|
const metaTrx = this.components.get(meta_trx_1.MetaTrx);
|
|
258
278
|
await metaTrx.upsert("comment", commentId, "_wp_trash_meta_status", comment.comment_approved);
|
|
259
279
|
await metaTrx.upsert("comment", commentId, "_wp_trash_meta_time", (0, common_1.currentUnixTimestamp)());
|
|
260
|
-
|
|
280
|
+
let success = true;
|
|
281
|
+
// Check if comment is note type and its parent comment
|
|
282
|
+
if (comment.comment_type === "note" && 0 === comment.comment_parent) {
|
|
283
|
+
const commentUtil = this.components.get(comment_util_1.CommentUtil);
|
|
284
|
+
const comment = await commentUtil.get(commentId);
|
|
285
|
+
const commentChildren = await comment.children();
|
|
286
|
+
for (const child of commentChildren || []) {
|
|
287
|
+
success = success && (await this.trash(child.comment_ID));
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return success;
|
|
261
291
|
}
|
|
262
292
|
// wp_set_comment_status
|
|
263
293
|
async updateStatus(commentId, commentStatus) {
|