v1.18.x
barisusakli 9 years ago
parent e1c0a8f3b3
commit 037b901e85

@ -67,6 +67,9 @@
"post-delete-duration-expired-days": "You are only allowed to delete posts for %1 day(s) after posting",
"post-delete-duration-expired-days-hours": "You are only allowed to delete posts for %1 day(s) %2 hour(s) after posting",
"cant-delete-topic-has-reply": "You can't delete your topic after it has %1 reply",
"cant-delete-topic-has-replies": "You can't delete your topic after it has %1 replies",
"content-too-short": "Please enter a longer post. Posts should contain at least %1 character(s).",
"content-too-long": "Please enter a shorter post. Posts can't be longer than %1 character(s).",
"title-too-short": "Please enter a longer title. Titles should contain at least %1 character(s).",

@ -3,6 +3,7 @@
var async = require('async');
var meta = require('../meta');
var topics = require('../topics');
var user = require('../user');
var helpers = require('./helpers');
@ -182,25 +183,40 @@ module.exports = function(privileges) {
};
privileges.topics.canDelete = function(tid, uid, callback) {
topics.getTopicField(tid, 'cid', function(err, cid) {
var topicData;
async.waterfall([
function(next) {
topics.getTopicFields(tid, ['cid', 'postcount'], next);
},
function(_topicData, next) {
topicData = _topicData;
async.parallel({
isModerator: async.apply(user.isModerator, uid, topicData.cid),
isAdministrator: async.apply(user.isAdministrator, uid),
isOwner: async.apply(topics.isOwner, tid, uid),
'topics:delete': async.apply(helpers.isUserAllowedTo, 'topics:delete', uid, [topicData.cid])
}, next);
}
], function(err, results) {
if (err) {
return callback(err);
}
helpers.some([
async.apply(user.isModerator, uid, cid),
async.apply(user.isAdministrator, uid),
function(next) {
async.parallel({
owner: async.apply(topics.isOwner, tid, uid),
'topics:delete': async.apply(helpers.isUserAllowedTo, 'topics:delete', uid, [cid])
}, function(err, result) {
if (err) {
return next(err);
}
next(null, result.owner && result['topics:delete'][0]);
});
}
], callback);
if (results.isModerator || results.isAdministrator) {
return callback(null, true);
}
var preventTopicDeleteAfterReplies = parseInt(meta.config.preventTopicDeleteAfterReplies, 10) || 0;
if (preventTopicDeleteAfterReplies && (topicData.postcount - 1) >= preventTopicDeleteAfterReplies) {
var langKey = preventTopicDeleteAfterReplies > 1 ? 'cant-delete-topic-has-replies' : 'cant-delete-topic-has-reply';
return callback(new Error('[[error:' + langKey + ', ' + meta.config.preventTopicDeleteAfterReplies + ']]'));
}
if (!results['topics:delete'][0]) {
return callback(null, false);
}
callback(null, results.isOwner);
});
};

@ -52,6 +52,10 @@
<label for="postDeleteDuration">Number of seconds users are allowed to delete posts after posting. (0 disabled)</label>
<input id="postDeleteDuration" type="text" class="form-control" value="0" data-field="postDeleteDuration">
</div>
<div class="form-group">
<label for="preventTopicDeleteAfterReplies">Number of replies after users are disallowed to delete their own topics. (0 disabled)</label>
<input id="preventTopicDeleteAfterReplies" type="text" class="form-control" value="0" data-field="preventTopicDeleteAfterReplies">
</div>
<div class="form-group">
<label for="minimumTitleLength">Minimum Title Length</label>
<input id="minimumTitleLength" type="text" class="form-control" value="3" data-field="minimumTitleLength">

Loading…
Cancel
Save