feat: #6021 add min:rep-post-links (#11938)

new reputation limit to post links
if post queue is enabled and user doesn't have enough reputation to post links, queue their posts

if post queue is NOT enabled and user doesn't have enough reputation to post links show error

check content on topic post, topic reply, post edit
This commit is contained in:
Barış Soner Uşaklı
2023-08-21 14:00:36 -04:00
committed by GitHub
parent c989a4a328
commit 979f24b173
7 changed files with 39 additions and 1 deletions

View File

@@ -85,6 +85,24 @@ module.exports = function (Posts) {
postData.data.content = result.postData.content;
}
Posts.canUserPostContentWithLinks = async function (uid, content) {
if (!content) {
return false;
}
const [reputation, isPrivileged] = await Promise.all([
user.getUserField(uid, 'reputation'),
user.isPrivileged(uid),
]);
if (!isPrivileged && reputation < meta.config['min:rep:post-links']) {
const parsed = await plugins.hooks.fire('filter:parse.raw', String(content));
if (parsed.match(/<a[^>]*>([^<]+)<\/a>/g)) {
return false;
}
}
return true;
};
Posts.shouldQueue = async function (uid, data) {
const [userData, isMemberOfExempt, categoryQueueEnabled] = await Promise.all([
user.getUserFields(uid, ['uid', 'reputation', 'postcount']),
@@ -94,7 +112,12 @@ module.exports = function (Posts) {
const shouldQueue = meta.config.postQueue && categoryQueueEnabled &&
!isMemberOfExempt &&
(!userData.uid || userData.reputation < meta.config.postQueueReputationThreshold || userData.postcount <= 0);
(
!userData.uid ||
userData.reputation < meta.config.postQueueReputationThreshold ||
userData.postcount <= 0 ||
!await Posts.canUserPostContentWithLinks(uid, data.content)
);
const result = await plugins.hooks.fire('filter:post.shouldQueue', {
shouldQueue: !!shouldQueue,
uid: uid,