From a6afcfd53104345a4098dd582defa2f5d7c5bd12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 17 Nov 2020 21:28:32 -0500 Subject: [PATCH] feat: #8475, allow flagging self posts dont count flags towards self posts dont allow flagging your own account --- public/language/en-GB/flags.json | 2 +- src/flags.js | 5 ++++- src/socket.io/posts/tools.js | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/public/language/en-GB/flags.json b/public/language/en-GB/flags.json index 10698842cc..13b3567bc9 100644 --- a/public/language/en-GB/flags.json +++ b/public/language/en-GB/flags.json @@ -67,7 +67,7 @@ "sort-upvotes": "Most upvotes", "sort-replies": "Most replies", - "modal-title": "Report Inappropriate Content", + "modal-title": "Report Content", "modal-body": "Please specify your reason for flagging %1 %2 for review. Alternatively, use one of the quick report buttons if applicable.", "modal-reason-spam": "Spam", "modal-reason-offensive": "Offensive", diff --git a/src/flags.js b/src/flags.js index 3292cdd946..98ecfb2251 100644 --- a/src/flags.js +++ b/src/flags.js @@ -257,6 +257,9 @@ Flags.validate = async function (payload) { throw new Error('[[error:not-enough-reputation-to-flag]]'); } } else if (payload.type === 'user') { + if (parseInt(payload.id, 10) === parseInt(payload.uid, 10)) { + throw new Error('[[error:cant-flag-self]]'); + } const editable = await privileges.users.canEdit(payload.uid, payload.id); if (!editable && !meta.config['reputation:disabled'] && reporter.reputation < meta.config['min:rep:flag']) { throw new Error('[[error:not-enough-reputation-to-flag]]'); @@ -395,7 +398,7 @@ Flags.create = async function (type, id, uid, reason, timestamp) { posts.setPostField(id, 'flagId', flagId) ); - if (targetUid) { + if (targetUid && parseInt(targetUid, 10) !== parseInt(uid, 10)) { batched.push(user.incrementUserFlagsBy(targetUid, 1)); } } else if (type === 'user') { diff --git a/src/socket.io/posts/tools.js b/src/socket.io/posts/tools.js index a0e4ae4715..b62f651e7a 100644 --- a/src/socket.io/posts/tools.js +++ b/src/socket.io/posts/tools.js @@ -42,7 +42,7 @@ module.exports = function (SocketPosts) { postData.display_edit_tools = results.canEdit.flag; postData.display_delete_tools = results.canDelete.flag; postData.display_purge_tools = results.canPurge; - postData.display_flag_tools = socket.uid && !postData.selfPost && results.canFlag.flag; + postData.display_flag_tools = socket.uid && results.canFlag.flag; postData.display_moderator_tools = postData.display_edit_tools || postData.display_delete_tools; postData.display_move_tools = results.isAdmin || results.isModerator; postData.display_change_owner_tools = results.isAdmin || results.isModerator;