feat: #8900, postQueue setting for category

v1.18.x
Barış Soner Uşaklı 4 years ago
parent 14bb0a4469
commit 1eb5fabdb1

@ -20,6 +20,7 @@
"chatDeleteDuration": 0,
"chatMessageDelay": 200,
"newbiePostDelayThreshold": 3,
"postQueue": 0,
"postQueueReputationThreshold": 0,
"groupsExemptFromPostQueue": ["administrators", "Global Moderators"],
"minimumPostLength": 8,

@ -11,6 +11,7 @@
"num-recent-replies": "# of Recent Replies",
"ext-link": "External Link",
"is-section": "Treat this category as a section",
"post-queue": "Post queue",
"tag-whitelist": "Tag Whitelist",
"upload-image": "Upload Image",
"delete-image": "Remove",

@ -21,7 +21,6 @@ topicsAPI.create = async function (caller, data) {
const payload = { ...data };
payload.tags = payload.tags || [];
payload.uid = caller.uid;
payload.uid = caller.uid;
payload.req = apiHelpers.buildReqObject(caller);
payload.timestamp = Date.now();
payload.fromQueue = false;

@ -5,11 +5,12 @@ const validator = require('validator');
const db = require('../database');
const meta = require('../meta');
const plugins = require('../plugins');
const utils = require('../utils');
const intFields = [
'cid', 'parentCid', 'disabled', 'isSection', 'order',
'topic_count', 'post_count', 'numRecentReplies',
'minTags', 'maxTags',
'minTags', 'maxTags', 'postQueue',
];
module.exports = function (Categories) {
@ -63,12 +64,13 @@ module.exports = function (Categories) {
};
};
function defaultMinMaxTags(category, fields, fieldName, defaultField) {
function defaultIntField(category, fields, fieldName, defaultField) {
if (!fields.length || fields.includes(fieldName)) {
const useDefault = !category.hasOwnProperty(fieldName) ||
category[fieldName] === null ||
category[fieldName] === '' ||
!parseInt(category[fieldName], 10);
!utils.isNumber(category[fieldName]);
category[fieldName] = useDefault ? meta.config[defaultField] : category[fieldName];
}
}
@ -78,8 +80,9 @@ function modifyCategory(category, fields) {
return;
}
defaultMinMaxTags(category, fields, 'minTags', 'minimumTagsPerTopic');
defaultMinMaxTags(category, fields, 'maxTags', 'maximumTagsPerTopic');
defaultIntField(category, fields, 'minTags', 'minimumTagsPerTopic');
defaultIntField(category, fields, 'maxTags', 'maximumTagsPerTopic');
defaultIntField(category, fields, 'postQueue', 'postQueue');
db.parseIntFields(category, intFields, fields);

@ -4,6 +4,7 @@ const categories = require('../../categories');
const analytics = require('../../analytics');
const plugins = require('../../plugins');
const translator = require('../../translator');
const meta = require('../../meta');
const categoriesController = module.exports;
@ -42,6 +43,7 @@ categoriesController.get = async function (req, res, next) {
categories: data.allCategories,
selectedCategory: selectedCategory,
customClasses: data.customClasses,
postQueueEnabled: !!meta.config.postQueue,
});
};

@ -15,9 +15,15 @@ const socketHelpers = require('../socket.io/helpers');
module.exports = function (Posts) {
Posts.shouldQueue = async function (uid, data) {
const userData = await user.getUserFields(uid, ['uid', 'reputation', 'postcount']);
const isMemberOfExempt = await groups.isMemberOfAny(userData.uid, meta.config.groupsExemptFromPostQueue);
const shouldQueue = meta.config.postQueue && !isMemberOfExempt && (!userData.uid || userData.reputation < meta.config.postQueueReputationThreshold || userData.postcount <= 0);
const [userData, isMemberOfExempt, categoryQueueEnabled] = await Promise.all([
user.getUserFields(uid, ['uid', 'reputation', 'postcount']),
groups.isMemberOfAny(uid, meta.config.groupsExemptFromPostQueue),
isCategoryQueueEnabled(data),
]);
const shouldQueue = meta.config.postQueue && categoryQueueEnabled &&
!isMemberOfExempt &&
(!userData.uid || userData.reputation < meta.config.postQueueReputationThreshold || userData.postcount <= 0);
const result = await plugins.hooks.fire('filter:post.shouldQueue', {
shouldQueue: !!shouldQueue,
uid: uid,
@ -26,6 +32,24 @@ module.exports = function (Posts) {
return result.shouldQueue;
};
async function isCategoryQueueEnabled(data) {
const type = getType(data);
const cid = await getCid(type, data);
if (!cid) {
throw new Error('[[error:invalid-cid]]');
}
return await categories.getCategoryField(cid, 'postQueue');
}
function getType(data) {
if (data.tid && data.content) {
return 'reply';
} else if (data.cid && data.title && data.content) {
return 'topic';
}
throw new Error('[[error:invalid-type]]');
}
async function removeQueueNotification(id) {
await notifications.rescind('post-queue-' + id);
const data = await getParsedObject(id);
@ -46,7 +70,7 @@ module.exports = function (Posts) {
}
Posts.addToQueue = async function (data) {
const type = data.title ? 'topic' : 'reply';
const type = getType(data);
const now = Date.now();
const id = type + '-' + now;
await canPost(type, data);

@ -80,16 +80,6 @@
<input id="cid-{category.cid}-link" type="text" class="form-control" placeholder="http://domain.com" data-name="link" value="{category.link}" />
</div>
</div>
<div class="col-sm-6 col-xs-12">
<div class="form-group">
<div class="checkbox">
<label class="mdl-switch mdl-js-switch mdl-js-ripple-effect">
<input type="checkbox" class="mdl-switch__input" id="cid-{category.cid}-isSection" data-name="isSection" <!-- IF category.isSection -->checked<!-- ENDIF category.isSection --> />
<span class="mdl-switch__label"><strong>[[admin/manage/categories:is-section]]</strong></span>
</label>
</div>
</div>
</div>
</fieldset>
<fieldset class="row">
<div class="col-sm-6 col-xs-12">
@ -111,9 +101,35 @@
</fieldset>
<fieldset class="row">
<div class="col-lg-12">
<label for="tag-whitelist">[[admin/manage/categories:tag-whitelist]]</label><br />
<input id="tag-whitelist" type="text" class="form-control" data-name="tagWhitelist" value="" />
<div class="form-group">
<label for="tag-whitelist">[[admin/manage/categories:tag-whitelist]]</label><br />
<input id="tag-whitelist" type="text" class="form-control" data-name="tagWhitelist" value="" />
</div>
</div>
</fieldset>
<fieldset class="row">
<div class="col-lg-6">
<div class="form-group">
<div class="checkbox">
<label class="mdl-switch mdl-js-switch mdl-js-ripple-effect">
<input type="checkbox" class="mdl-switch__input" id="cid-{category.cid}-isSection" data-name="isSection" <!-- IF category.isSection -->checked<!-- ENDIF category.isSection --> />
<span class="mdl-switch__label"><strong>[[admin/manage/categories:is-section]]</strong></span>
</label>
</div>
</div>
</div>
{{{ if postQueueEnabled }}}
<div class="col-lg-6">
<div class="form-group">
<div class="checkbox">
<label class="mdl-switch mdl-js-switch mdl-js-ripple-effect">
<input type="checkbox" class="mdl-switch__input" data-name="postQueue" {{{ if category.postQueue }}}checked{{{ end }}} />
<span class="mdl-switch__label"><strong>[[admin/manage/categories:post-queue]]</strong></span>
</label>
</div>
</div>
</div>
{{{ end }}}
</fieldset>
</div>
</div>

Loading…
Cancel
Save