Skip to content
This repository has been archived by the owner on Oct 11, 2022. It is now read-only.

Commit

Permalink
Merge branch 'alpha' of github.com:withspectrum/spectrum into 2.4.80
Browse files Browse the repository at this point in the history
  • Loading branch information
brianlovin committed Dec 4, 2018
2 parents 0fa2967 + 54e685e commit 2ae23bc
Show file tree
Hide file tree
Showing 36 changed files with 539 additions and 258 deletions.
11 changes: 3 additions & 8 deletions api/mutations/thread/publishThread.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
_adminProcessToxicThreadQueue,
_adminProcessUserSpammingThreadsQueue,
} from 'shared/bull/queues';
import getSpectrumScore from 'athena/queues/moderationEvents/spectrum';
import getPerspectiveScore from 'athena/queues/moderationEvents/perspective';
import { events } from 'shared/analytics';
import { trackQueue } from 'shared/bull/queues';
Expand Down Expand Up @@ -275,27 +274,23 @@ export default requireAuth(
const title = thread.content.title;
const text = `${title} ${body}`;

const scores = await Promise.all([
getSpectrumScore(text, dbThread.id, dbThread.creatorId).catch(err => 0),
getPerspectiveScore(text).catch(err => 0),
]).catch(err =>
const scores = await getPerspectiveScore(text).catch(err =>
console.error(
'Error getting thread moderation scores from providers',
err.message
)
);

const spectrumScore = scores && scores[0];
const perspectiveScore = scores && scores[1];

// if neither models returned results
if (!spectrumScore && !perspectiveScore) {
if (!perspectiveScore) {
debug('Toxicity checks from providers say not toxic');
return false;
}

// if both services agree that the thread is >= 98% toxic
if ((spectrumScore + perspectiveScore) / 2 >= 0.9) {
if (perspectiveScore >= 0.9) {
debug('Thread is toxic according to both providers');
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion api/mutations/user/editUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default requireAuth(
const pendingEmail = input.email;

// if user is changing their email, make sure it's not taken by someone else
if (pendingEmail !== currentUser.email) {
if (pendingEmail !== currentUser.email || !currentUser.email) {
if (!isEmail(input.email)) {
return new UserError('Please enter a valid email address.');
}
Expand Down
4 changes: 2 additions & 2 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"babel-plugin-transform-flow-strip-types": "^6.22.0",
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-preset-env": "^1.7.0",
"backpack-core": "^0.8.2",
"backpack-core": "^0.8.3",
"body-parser": "^1.18.3",
"bull": "3.3.10",
"casual": "^1.5.12",
Expand Down Expand Up @@ -116,7 +116,7 @@
"sanitize-filename": "^1.6.1",
"serialize-javascript": "^1.5.0",
"session-rethinkdb": "^2.0.0",
"slate": "^0.44.6",
"slate": "^0.44.7",
"slate-markdown": "0.1.0",
"slugg": "^1.1.0",
"string-replace-to-array": "^1.0.3",
Expand Down
7 changes: 6 additions & 1 deletion api/queries/user/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ import type { GraphQLContext } from '../../';
import type { DBUser } from 'shared/types';
import { isAdmin } from '../../utils/permissions';

export default ({ id, email }: DBUser, _: any, { user }: GraphQLContext) => {
export default async (
{ id }: DBUser,
_: any,
{ user, loaders }: GraphQLContext
) => {
// Only admins and the user themselves can view the email
if (!user || (id !== user.id && !isAdmin(user.id))) return null;
const { email } = await loaders.user.load(id);
return email;
};
103 changes: 19 additions & 84 deletions api/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2270,18 +2270,18 @@ backo2@^1.0.2:
resolved "https://registry.yarnpkg.com/backo2/-/backo2-1.0.2.tgz#31ab1ac8b129363463e35b3ebb69f4dfcfba7947"
integrity sha1-MasayLEpNjRj41s+u2n038+6eUc=

backpack-core@^0.8.2:
version "0.8.2"
resolved "https://registry.yarnpkg.com/backpack-core/-/backpack-core-0.8.2.tgz#d8ef661ecbee43a87bce1888603a54eee8490873"
integrity sha512-EKAiTtL0Ij97bQc+rvzAmSr9moYlbiZD1OBjujCIg/Hr1nasXtViJrw1EedOUjXNFudIa0acfnCAXde/8FcNKQ==
backpack-core@^0.8.3:
version "0.8.3"
resolved "https://registry.yarnpkg.com/backpack-core/-/backpack-core-0.8.3.tgz#7c92458d29c77987fcb278ee83b23b55624ec2af"
integrity sha512-d94a47CT1+/Ozb9L7wICoenQF4tyaSOxqPrKxFmk33TW67oKHrA6Ye/1ZJjBUVYwjfNCae6iO2xqyrjRzzQAcA==
dependencies:
"@babel/core" "^7.1.2"
babel-loader "^8.0.2"
babel-preset-backpack "^0.8.2"
cross-spawn "^5.0.1"
friendly-errors-webpack-plugin "^1.7.0"
json-loader "^0.5.7"
nodemon "^1.11.0"
nodemon "^1.18.7"
ramda "^0.23.0"
source-map-support "^0.4.15"
webpack "^4.23.1"
Expand Down Expand Up @@ -3685,11 +3685,6 @@ duplexer3@^0.1.4:
resolved "https://registry.yarnpkg.com/duplexer3/-/duplexer3-0.1.4.tgz#ee01dd1cac0ed3cbc7fdbea37dc0a8f1ce002ce2"
integrity sha1-7gHdHKwO08vH/b6jfcCo8c4ALOI=

duplexer@^0.1.1, duplexer@~0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/duplexer/-/duplexer-0.1.1.tgz#ace6ff808c1ce66b57d1ebf97977acb02334cfc1"
integrity sha1-rOb/gIwc5mtX0ev5eXessCM0z8E=

duplexify@^3.4.2, duplexify@^3.6.0:
version "3.6.1"
resolved "https://registry.yarnpkg.com/duplexify/-/duplexify-3.6.1.tgz#b1a7a29c4abfd639585efaecce80d666b1e34125"
Expand Down Expand Up @@ -3919,20 +3914,6 @@ etag@~1.8.1:
resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887"
integrity sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=

event-stream@~3.3.0:
version "3.3.6"
resolved "https://registry.yarnpkg.com/event-stream/-/event-stream-3.3.6.tgz#cac1230890e07e73ec9cacd038f60a5b66173eef"
integrity sha512-dGXNg4F/FgVzlApjzItL+7naHutA3fDqbV/zAZqDDlXTjiMnQmZKu+prImWKszeBM5UQeGvAl3u1wBiKeDh61g==
dependencies:
duplexer "^0.1.1"
flatmap-stream "^0.1.0"
from "^0.1.7"
map-stream "0.0.7"
pause-stream "^0.0.11"
split "^1.0.1"
stream-combiner "^0.2.2"
through "^2.3.8"

eventemitter3@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-3.1.0.tgz#090b4d6cdbd645ed10bf750d4b5407942d7ba163"
Expand Down Expand Up @@ -4265,11 +4246,6 @@ find-with-regex@^1.0.2, find-with-regex@^1.1.3:
resolved "https://registry.yarnpkg.com/find-with-regex/-/find-with-regex-1.1.3.tgz#d6c6f2debee898d36b6a77e05709b13dd5dc8a26"
integrity sha512-zkEVQ1H3PIQL/19ADKt1lCQU4QGM3OneiderUcFgn5EgTm/TnoUh7HxPAwP8w/vXxWSLC6KtpbDQpypJ5+majw==

flatmap-stream@^0.1.0:
version "0.1.2"
resolved "https://registry.yarnpkg.com/flatmap-stream/-/flatmap-stream-0.1.2.tgz#b1da359a93f24f6d96e46f948552d997e3c2863d"
integrity sha512-ucyr6WkLXjyMuHPtOUq4l+nSAxgWi7v4QO508eQ9resnGj+lSup26oIsUI5aH8k4Qfpjsxa8dDf9UCKkS2KHzQ==

[email protected]:
version "0.0.6"
resolved "https://registry.yarnpkg.com/flexbuffer/-/flexbuffer-0.0.6.tgz#039fdf23f8823e440c38f3277e6fef1174215b30"
Expand Down Expand Up @@ -4381,11 +4357,6 @@ from2@^2.1.0:
inherits "^2.0.1"
readable-stream "^2.0.0"

from@^0.1.7:
version "0.1.7"
resolved "https://registry.yarnpkg.com/from/-/from-0.1.7.tgz#83c60afc58b9c56997007ed1a768b3ab303a44fe"
integrity sha1-g8YK/Fi5xWmXAH7Rp2izqzA6RP4=

fs-extra@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-5.0.0.tgz#414d0110cdd06705734d055652c5411260c31abd"
Expand Down Expand Up @@ -6429,11 +6400,6 @@ map-obj@^1.0.0, map-obj@^1.0.1:
resolved "https://registry.yarnpkg.com/map-obj/-/map-obj-1.0.1.tgz#d933ceb9205d82bdcf4886f6742bdc2b4dea146d"
integrity sha1-2TPOuSBdgr3PSIb2dCvcK03qFG0=

[email protected]:
version "0.0.7"
resolved "https://registry.yarnpkg.com/map-stream/-/map-stream-0.0.7.tgz#8a1f07896d82b10926bd3744a2420009f88974a8"
integrity sha1-ih8HiW2CsQkmvTdEokIACfiJdKg=

map-visit@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/map-visit/-/map-visit-1.0.0.tgz#ecdca8f13144e660f1b5bd41f12f3479d98dfb8f"
Expand Down Expand Up @@ -6867,16 +6833,16 @@ node-releases@^1.0.1:
dependencies:
semver "^5.3.0"

nodemon@^1.11.0:
version "1.18.6"
resolved "https://registry.yarnpkg.com/nodemon/-/nodemon-1.18.6.tgz#89b1136634d6c0afc7de24cc932a760e999e2c76"
integrity sha512-4pHQNYEZun+IkIC2jCaXEhkZnfA7rQe73i8RkdRyDJls/K+WxR7IpI5uNUsAvQ0zWvYcCDNGD+XVtw2ZG86/uQ==
nodemon@^1.18.7:
version "1.18.7"
resolved "https://registry.yarnpkg.com/nodemon/-/nodemon-1.18.7.tgz#716b66bf3e89ac4fcfb38a9e61887a03fc82efbb"
integrity sha512-xuC1V0F5EcEyKQ1VhHYD13owznQbUw29JKvZ8bVH7TmuvVNHvvbp9pLgE4PjTMRJVe0pJ8fGRvwR2nMiosIsPQ==
dependencies:
chokidar "^2.0.4"
debug "^3.1.0"
ignore-by-default "^1.0.1"
minimatch "^3.0.4"
pstree.remy "^1.1.0"
pstree.remy "^1.1.2"
semver "^5.5.0"
supports-color "^5.2.0"
touch "^3.1.0"
Expand Down Expand Up @@ -7365,13 +7331,6 @@ path-type@^2.0.0:
dependencies:
pify "^2.0.0"

pause-stream@^0.0.11:
version "0.0.11"
resolved "https://registry.yarnpkg.com/pause-stream/-/pause-stream-0.0.11.tgz#fe5a34b0cbce12b5aa6a2b403ee2e73b602f1445"
integrity sha1-/lo0sMvOErWqaitAPuLnO2AvFEU=
dependencies:
through "~2.3"

[email protected]:
version "0.0.1"
resolved "https://registry.yarnpkg.com/pause/-/pause-0.0.1.tgz#1d408b3fdb76923b9543d96fb4c9dfd535d9cb5d"
Expand Down Expand Up @@ -7572,13 +7531,6 @@ prr@~1.0.1:
resolved "https://registry.yarnpkg.com/prr/-/prr-1.0.1.tgz#d3fc114ba06995a45ec6893f484ceb1d78f5f476"
integrity sha1-0/wRS6BplaRexok/SEzrHXj19HY=

ps-tree@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/ps-tree/-/ps-tree-1.1.0.tgz#b421b24140d6203f1ed3c76996b4427b08e8c014"
integrity sha1-tCGyQUDWID8e08dplrRCewjowBQ=
dependencies:
event-stream "~3.3.0"

pseudomap@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3"
Expand All @@ -7589,12 +7541,10 @@ psl@^1.1.24:
resolved "https://registry.yarnpkg.com/psl/-/psl-1.1.29.tgz#60f580d360170bb722a797cc704411e6da850c67"
integrity sha512-AeUmQ0oLN02flVHXWh9sSJF7mcdFq0ppid/JkErufc3hGIV/AMa8Fo9VgDo/cT2jFdOWoFvHp90qqBH54W+gjQ==

pstree.remy@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/pstree.remy/-/pstree.remy-1.1.0.tgz#f2af27265bd3e5b32bbfcc10e80bac55ba78688b"
integrity sha512-q5I5vLRMVtdWa8n/3UEzZX7Lfghzrg9eG2IKk2ENLSofKRCXVqMvMUHxCKgXNaqH/8ebhBxrqftHWnyTFweJ5Q==
dependencies:
ps-tree "^1.1.0"
pstree.remy@^1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/pstree.remy/-/pstree.remy-1.1.2.tgz#4448bbeb4b2af1fed242afc8dc7416a6f504951a"
integrity sha512-vL6NLxNHzkNTjGJUpMm5PLC+94/0tTlC1vkP9bdU0pOHih+EujMjgMTwfZopZvHWRFbqJ5Y73OMoau50PewDDA==

public-encrypt@^4.0.0:
version "4.0.3"
Expand Down Expand Up @@ -8580,10 +8530,10 @@ [email protected]:
react "^0.14.0 || ^15.0.0"
styled-components "^2.0.0"

slate@^0.44.6:
version "0.44.6"
resolved "https://registry.yarnpkg.com/slate/-/slate-0.44.6.tgz#47ab3127641bc1faa3e5a5b01bfab8861843c82e"
integrity sha512-Q5DASlX7tUXrAaQFb5AliZjAeuXkI1oVq3HM8A/mb4qClwpSpuKq/uOcA3855bFzAOXSjUM/kESK3M3oiIHnNA==
slate@^0.44.7:
version "0.44.7"
resolved "https://registry.yarnpkg.com/slate/-/slate-0.44.7.tgz#3cf8a3f2bd78c03e02a6cf8bb726ae9f43582e13"
integrity sha512-h2aW2r20qtn4oUk8rh7qbW3NluLMlsDCctFNwWdrDmGnwTfszfVApcapnOFmv+qmKnZsPZLqidl3mHnXVL/lcQ==
dependencies:
debug "^3.1.0"
direction "^0.1.5"
Expand Down Expand Up @@ -8728,13 +8678,6 @@ split-string@^3.0.1, split-string@^3.0.2:
dependencies:
extend-shallow "^3.0.0"

split@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/split/-/split-1.0.1.tgz#605bd9be303aa59fb35f9229fbea0ddec9ea07d9"
integrity sha512-mTyOoPbrivtXnwnIxZRFYRrPNtEFKlpB2fvjSnCQUiAA6qAZzqwna5envK4uk6OIeP17CsdF3rSBGYVBsU0Tkg==
dependencies:
through "2"

sprintf-js@~1.0.2:
version "1.0.3"
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"
Expand Down Expand Up @@ -8803,14 +8746,6 @@ stream-browserify@^2.0.1:
inherits "~2.0.1"
readable-stream "^2.0.2"

stream-combiner@^0.2.2:
version "0.2.2"
resolved "https://registry.yarnpkg.com/stream-combiner/-/stream-combiner-0.2.2.tgz#aec8cbac177b56b6f4fa479ced8c1912cee52858"
integrity sha1-rsjLrBd7Vrb0+kec7YwZEs7lKFg=
dependencies:
duplexer "~0.1.1"
through "~2.3.4"

stream-each@^1.1.0:
version "1.2.3"
resolved "https://registry.yarnpkg.com/stream-each/-/stream-each-1.2.3.tgz#ebe27a0c389b04fbcc233642952e10731afa9bae"
Expand Down Expand Up @@ -9130,7 +9065,7 @@ through2@^2.0.0:
readable-stream "~2.3.6"
xtend "~4.0.1"

through@2, through@^2.3.8, through@~2.3, through@~2.3.4:
through@^2.3.8, through@~2.3.4:
version "2.3.8"
resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"
integrity sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=
Expand Down
15 changes: 3 additions & 12 deletions athena/queues/moderationEvents/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { getThreadById } from '../../models/thread';
import { getCommunityById } from '../../models/community';
import { getChannelById } from '../../models/channel';
import { toState, toPlainText } from 'shared/draft-utils';
import getSpectrumScore from './spectrum';
import getPerspectiveScore from './perspective';
import { _adminSendToxicContentEmailQueue } from 'shared/bull/queues';
import type { Job, AdminToxicMessageJobData } from 'shared/bull/types';
Expand All @@ -21,11 +20,8 @@ export default async (job: Job<AdminToxicMessageJobData>) => {
? toPlainText(toState(JSON.parse(message.content.body)))
: message.content.body;

const scores = await Promise.all([
getSpectrumScore(text, message.id, message.senderId),
getPerspectiveScore(text),
]).catch(err =>
console.error('Error getting message moderation scores from providers', {
const perspectiveScore = await getPerspectiveScore(text).catch(err =>
console.error('Error getting message moderation score from providers', {
error: err.message,
data: {
text,
Expand All @@ -34,11 +30,7 @@ export default async (job: Job<AdminToxicMessageJobData>) => {
})
);

const spectrumScore = scores && scores[0];
const perspectiveScore = scores && scores[1];

// if neither models returned results
if (!spectrumScore && !perspectiveScore) return;
if (!perspectiveScore) return;

const [user, thread] = await Promise.all([
getUserById(message.senderId),
Expand All @@ -58,7 +50,6 @@ export default async (job: Job<AdminToxicMessageJobData>) => {
community,
channel,
toxicityConfidence: {
spectrumScore,
perspectiveScore,
},
});
Expand Down
2 changes: 1 addition & 1 deletion athena/queues/moderationEvents/perspective.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default async (text: string) => {
});

// if something failed?
if (!request || !request.data) return;
if (!request || !request.data) return null;

// get the scores from the request
const { attributeScores } = request.data;
Expand Down
42 changes: 0 additions & 42 deletions athena/queues/moderationEvents/spectrum.js

This file was deleted.

Loading

0 comments on commit 2ae23bc

Please sign in to comment.