feat: #8475, allow flagging self posts

dont count flags towards self posts
dont allow flagging your own account
This commit is contained in:
Barış Soner Uşaklı
2020-11-17 21:28:32 -05:00
parent 62b62821c1
commit a6afcfd531
3 changed files with 6 additions and 3 deletions

View File

@@ -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') {