Adjusted flag beheviour for staff

This commit is contained in:
Wyatt Johnson
2017-12-04 12:17:39 -07:00
parent 8b71175c46
commit 87ef0f1cb9
5 changed files with 50 additions and 21 deletions
+12 -5
View File
@@ -1,5 +1,8 @@
const errors = require('../../errors');
const {CREATE_ACTION, DELETE_ACTION} = require('../../perms/constants');
const {
IGNORE_FLAGS_AGAINST_STAFF,
} = require('../../config');
/**
* getActionItem will return the item that is associated with the given action.
@@ -56,12 +59,16 @@ const createAction = async (ctx, {item_id, item_type, action_type, group_id, met
// Gets the item referenced by the action.
const item = await getActionItem(ctx, {item_id, item_type});
if (action_type === 'FLAG' && item_type === 'USERS') {
// If we are ignoring flags against staff, ensure that the target isn't a
// staff member.
if (IGNORE_FLAGS_AGAINST_STAFF) {
if (action_type === 'FLAG') {
// The item is a user, and this is a flag. Check to see if they are staff,
// if they are, don't permit the flag.
if (item.isStaff()) {
throw errors.ErrNotAuthorized;
// If the item is a user, and this is a flag. Check to see if they are
// staff, if they are, don't permit the flag.
if (item_type === 'USERS' && item.isStaff()) {
return null;
}
}
}
+13 -3
View File
@@ -19,7 +19,8 @@ const {
} = require('../../perms/constants');
const {
DISABLE_AUTOFLAG_SUSPECT_WORDS
DISABLE_AUTOFLAG_SUSPECT_WORDS,
IGNORE_FLAGS_AGAINST_STAFF,
} = require('../../config');
const debug = require('debug')('talk:graph:mutators:tags');
@@ -292,7 +293,7 @@ const moderationPhases = [
}
},
// This phase checks to see if the comment's length exeeds maximum.
// This phase checks to see if the comment's length exceeds maximum.
(context, comment, {assetSettings: {charCountEnable, charCount}}) => {
// Reject if the comment is too long
@@ -313,6 +314,15 @@ const moderationPhases = [
}
},
// If a given user is a staff member, always approve their comment.
(context) => {
if (IGNORE_FLAGS_AGAINST_STAFF && context.user && context.user.isStaff()) {
return {
status: 'ACCEPTED',
};
}
},
// This phase checks the comment if it has any links in it if the check is
// enabled.
(context, comment, {assetSettings: {premodLinksEnable}}) => {
@@ -362,7 +372,7 @@ const moderationPhases = [
}
},
// This phase checks to see if the comment was already perscribed a status.
// This phase checks to see if the comment was already prescribed a status.
(context, comment) => {
// If the status was already defined, don't redefine it. It's only defined