Skip to content

Commit

Permalink
hardening comment data endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremywrnr committed Jan 31, 2023
1 parent c6a281e commit f21a2e2
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions app/imports/api/comments/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ export const addressComment = new ValidatedMethod({
}).validator(),
run({ commentId }) {
const comment = Comments.findOne({ _id: commentId });

// Locking the demo session.
if (!comment || comment.talk == lockedTalkId) {
console.error("Session is locked.");
return false;
}

if (comment) {
const newAddress = !comment.addressed;
return Comments.update(commentId, {
Expand All @@ -83,7 +90,7 @@ export const completeComment = new ValidatedMethod({
}).validator(),
run({ commentId }) {
const comment = Comments.findOne({ _id: commentId });
if (!comment) {
if (!comment || comment.talk == lockedTalkId) {
return false;
} else {
const newComplete = !comment.completed;
Expand All @@ -103,7 +110,7 @@ export const agreeComment = new ValidatedMethod({
run({ author, commentId }) {
author = author.trim();
const comment = Comments.findOne({ _id: commentId });
if (!comment) {
if (!comment || comment.talk == lockedTalkId) {
return false;
}

Expand Down Expand Up @@ -136,7 +143,7 @@ export const discussComment = new ValidatedMethod({
run({ author, commentId }) {
author = author.trim();
const comment = Comments.findOne({ _id: commentId });
if (!comment) {
if (!comment || comment.talk == lockedTalkId) {
return false;
}

Expand Down Expand Up @@ -172,7 +179,7 @@ export const updateComment = new ValidatedMethod({
console.error("Session is locked.");
return false;
}

if (comment && comment.author == author) {
const newOwn = comment.userOwn || newContent.includes("#private");
Comments.update(commentId, {
Expand All @@ -190,6 +197,10 @@ export const toggleVisibility = new ValidatedMethod({
}).validator(),
run({ author, commentId }) {
const comment = Comments.findOne({ _id: commentId });
if (!comment || comment.talk == lockedTalkId) {
return false;
}

if (comment && comment.author == author) {
Comments.update(commentId, {
$set: { userOwn: !comment.userOwn },
Expand All @@ -206,6 +217,10 @@ export const deleteComment = new ValidatedMethod({
}).validator(),
run({ author, commentId }) {
const comment = Comments.findOne({ _id: commentId });
if (!comment || comment.talk == lockedTalkId) {
return false;
}

if (comment && comment.author == author) {
// console.log({ type: "comment.delete", ...comment });
Comments.remove(commentId);
Expand Down

0 comments on commit f21a2e2

Please sign in to comment.