Skip to content

Commit

Permalink
GDPR15B
Browse files Browse the repository at this point in the history
* Suspend flaggings on reserved. This, again, can obviously be overridden wiht Admin+ by elevating the account... another precaution
* Stop slinging some objects around in memory with return statements in this lib

Post OpenUserJS#1657 df4ec36 (missed increment of GDPR14 i.e. should have been 15) OpenUserJS#1658
  • Loading branch information
Martii committed Aug 19, 2019
1 parent f4389bc commit 0fe2226
Showing 1 changed file with 32 additions and 13 deletions.
45 changes: 32 additions & 13 deletions libs/flag.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,49 @@ function flaggable(aModel, aContent, aUser, aCallback) {
// No one above a moderator is part of the moderation system
// since they can just remove content directly
if (!aUser || aUser.role < 3) {
return aCallback(false);
aCallback(false);
return;
}

// You can't flag yourself
// Only someone less than an admin can be flagged
// except system reserved
// It is not the responsibility of the community
// to police the site administration
if (aModel.modelName === 'User') {
return getFlag(aModel, aContent, aUser, function (aFlag) {
aCallback(aContent._id != aUser._id && aContent.role > 2, aContent, aFlag);
aCallback(
aContent._id != aUser._id && aContent.role > 2 && aContent.role !== 6,
aContent,
aFlag
);
});
}

getAuthor(aContent, function (aAuthor) {
// Content without an author shouldn't exist
if (!aAuthor) {
return aCallback(false);
aCallback(false);
return;
}

// You can't flag your own content
if (aAuthor._id == aUser._id) {
return aCallback(false);
aCallback(false);
return;
}

// Content belonging to an admin or above cannot be flagged
if (aAuthor.role < 3) {
return aCallback(aAuthor.role > 2, aAuthor);
// including system reserved
if (aAuthor.role < 3 || aAuthor.role === 6) {
aCallback(aAuthor.role > 2 && aAuthor.role !== 6, aAuthor);
return;
}

// You can't flag something twice
getFlag(aModel, aContent, aUser, function (aFlag) {
return aCallback(!aFlag, aAuthor, aFlag);
aCallback(!aFlag, aAuthor, aFlag);
return;
});
});
}
Expand Down Expand Up @@ -82,18 +93,23 @@ exports.getAuthor = getAuthor;

function getThreshold(aModel, aContent, aAuthor, aCallback) {
// Admins can't be flagged so they have no threshold
if (aAuthor.role < 3) { return aCallback(null); }
if (aAuthor.role < 3) {
aCallback(null);
return;
}

// Hardcode the threshold at 1.
// modelQuery.applyModelListQueryFlaggedFilter supports this hardcoded number.
// return aCallback(1);
// aCallback(1);
// return;

// Moderators have a doubled threshold
var threshold = thresholds[aModel.modelName] * (aAuthor.role < 4 ? 2 : 1);

// Calculate karma and add it to the threshold
getKarma(aAuthor, maxKarma, function (aKarma) {
return aCallback(threshold + aKarma);
aCallback(threshold + aKarma);
return;
});
}
exports.getThreshold = getThreshold;
Expand Down Expand Up @@ -180,7 +196,8 @@ function flag(aModel, aContent, aUser, aAuthor, aReason, aCallback) {
exports.flag = function (aModel, aContent, aUser, aReason, aCallback) {
flaggable(aModel, aContent, aUser, function (aCanFlag, aAuthor) {
if (!aCanFlag) {
return aCallback(false);
aCallback(false);
return;
}

flag(aModel, aContent, aUser, aAuthor, aReason, aCallback);
Expand All @@ -189,12 +206,14 @@ exports.flag = function (aModel, aContent, aUser, aReason, aCallback) {

exports.unflag = function (aModel, aContent, aUser, aReason, aCallback) {
if (!aUser) {
return aCallback(null);
aCallback(null);
return;
}

getFlag(aModel, aContent, aUser, function (aFlag) {
if (!aFlag) {
return aCallback(null);
aCallback(null);
return;
}

if (!aContent.flags) {
Expand Down

0 comments on commit 0fe2226

Please sign in to comment.