Skip to content

Commit

Permalink
v1.1.0 max post age
Browse files Browse the repository at this point in the history
v1.1.0 now you can limit post age
  • Loading branch information
TheBronx committed Sep 4, 2016
1 parent 3835880 commit d982108
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 5 deletions.
8 changes: 7 additions & 1 deletion Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ var MIN_POSTS_TO_UPVOTE = 20,
REP_LOG_NAMESPACE = "reputationLog",
DISABLED_CATEGORIES_IDS = [],
MAX_POINTS_FOR_UPVOTE = 10,
MAX_POINTS_FOR_DOWNVOTE = 10;
MAX_POINTS_FOR_DOWNVOTE = 10,
MAX_POST_AGE_DAYS = 0; // 0 means disabled

var Config = {
minPostToDownvote: function () {
Expand Down Expand Up @@ -84,6 +85,9 @@ var Config = {
getDisabledCategories: function () {
return DISABLED_CATEGORIES_IDS;
},
getMaxPostAgeDays: function() {
return MAX_POST_AGE_DAYS;
},
getSettings: function () {
var settings = {};
settings.minPostsToUpvote = MIN_POSTS_TO_UPVOTE;
Expand All @@ -100,6 +104,7 @@ var Config = {
settings.repLogNamespace = REP_LOG_NAMESPACE;
settings.maxUpvoteWeigh = MAX_POINTS_FOR_UPVOTE;
settings.maxDownvoteWeigh = MAX_POINTS_FOR_DOWNVOTE;
settings.maxPostAgeDays = MAX_POST_AGE_DAYS;
return settings;
},
setSettings: function (settings) {
Expand All @@ -116,6 +121,7 @@ var Config = {
DISABLED_CATEGORIES_IDS = intArray(settings.disabledCategoriesIds);
MAX_POINTS_FOR_UPVOTE = settings.maxUpvoteWeigh;
MAX_POINTS_FOR_DOWNVOTE = settings.maxDownvoteWeigh;
MAX_POST_AGE_DAYS = parseInt(settings.maxPostAgeDays, 10) || 0;
}
};

Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,10 @@ Undoing votes:
### Rule #10
Upvotes and downvotes should have a maximum weigh, configurable. So that rule **#8** doesn't make vote points tend to infinity.

### Rule #11
Optional: you can limit upvotes and downvotes to recent posts. In other words, if a message is too old, users won't be able to vote it.
You can configure what "too old" means for you, for example 30 days, 90 days, or 0 if you want to disable this feature and allow votes in old posts.
**Note** unvotes are always allowed.

### (TO-DO)
- Ban for low reputation
6 changes: 4 additions & 2 deletions ReputationManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ var ReputationManager = function (Config) {
userPermissions.isOldEnoughToUpvote,
userPermissions.hasVotedTooManyPostsInThread,
userPermissions.hasVotedAuthorTooManyTimesThisMonth,
userPermissions.hasVotedTooManyTimesToday
userPermissions.hasVotedTooManyTimesToday,
userPermissions.postIsNotTooOld
],
function (err) {
if (err) {
Expand All @@ -41,7 +42,8 @@ var ReputationManager = function (Config) {
userPermissions.hasEnoughReputationToDownvote,
userPermissions.hasVotedTooManyPostsInThread,
userPermissions.hasVotedAuthorTooManyTimesThisMonth,
userPermissions.hasVotedTooManyTimesToday
userPermissions.hasVotedTooManyTimesToday,
userPermissions.postIsNotTooOld
],
function (err) {
if (err) {
Expand Down
9 changes: 9 additions & 0 deletions UserVotingPermissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ var UserVotingPermissions = function (Config, db, user, post) {
else callback();
};

this.postIsNotTooOld = function (callback) {
if (Config.getMaxPostAgeDays() === 0) return callback();

var now = new Date();
var postAgeDays = (now - _this.post.timestamp)/24/60/60/1000;
if (postAgeDays > Config.getMaxPostAgeDays()) callback({'reason': 'postTooOld'});
else callback();
};

function countVotesInThread(userId, threadId, callback) {
var voteIdentifier = Config.getPerThreadLogId(userId, threadId);
db.getSetMembers(voteIdentifier, function (err, setMembers) {
Expand Down
2 changes: 1 addition & 1 deletion library.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

var plugin = {'settingsVersion': '1.0.4'},
var plugin = {'settingsVersion': '1.1.0'},
db = module.parent.require('./database'),
users = module.parent.require('./user'),
meta = module.parent.require('./meta'),
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nodebb-plugin-reputation-rules",
"version": "1.0.4",
"version": "1.1.0",
"description": "Reputation rules to prevent abuse and make it more reliable",
"main": "library.js",
"repository": {
Expand Down
1 change: 1 addition & 0 deletions public/languages/en_GB/nodebb-plugin-reputation-rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"tooManyVotesInThread": "You can't vote more messages in this thread",
"tooManyVotesToSameUserThisMonth": "You can't vote this user again until next month",
"tooManyVotesToday": "You can't vote more messages today",
"postTooOld": "You can't vote this message, it is too old",
"unknownError": "Error voting"
}
1 change: 1 addition & 0 deletions public/languages/es/nodebb-plugin-reputation-rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"tooManyVotesInThread": "No puedes votar más mensajes en este hilo",
"tooManyVotesToSameUserThisMonth": "Ya has votado a este usuario este mes",
"tooManyVotesToday": "No puedes votar más mensajes hoy",
"postTooOld": "No puedes votar este mensaje, es muy antiguo",
"unknownError": "Error al votar"
}
8 changes: 8 additions & 0 deletions public/templates/admin/plugins/reputation-rules.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@
<div data-key="disabledCategoriesIds" data-attributes='{"data-type":"input", "style":"width:80%;margin-bottom:10px;"}' data-split="<br>" data-new='' style="width:100%;"></div>
<br>
</div>

<div class="form-group">
<!-- (MAX_POST_AGE_DAYS) -->
<label>Maximum post age, in number of days, to allow votes:</label>
<input class="form-control" type="number" data-key="maxPostAgeDays" title="Maximum post age, in number of days, to allow votes">
<p class="help-block">Enter zero to disable this and allow votes to any post. Unvotes are ALWAYS allowed.</p>
<br>
</div>
</div>
</div>

Expand Down

0 comments on commit d982108

Please sign in to comment.