From 76a255fb7bf819ac85d5b5b516da9d66456e4cbf Mon Sep 17 00:00:00 2001 From: Wyatt Johnson Date: Thu, 2 Nov 2017 17:16:57 -0600 Subject: [PATCH] initial pass at status support --- .nodemon.json | 8 +- bin/cli-users | 109 +--- circle.yml | 7 +- client/coral-admin/src/containers/Header.js | 2 +- .../routes/Community/containers/Community.js | 2 +- .../components/CloseCommentsInfo.js | 2 +- client/coral-settings/components/Bio.css | 21 - client/coral-settings/components/Bio.js | 18 - .../coral-settings/containers/BioContainer.js | 45 -- errors.js | 2 +- graph/mutators/action.js | 10 - graph/mutators/user.js | 118 +++- graph/resolvers/root_mutation.js | 15 +- graph/resolvers/user.js | 13 +- graph/setupFunctions.js | 6 +- graph/typeDefs.graphql | 194 ++++-- models/enum/user_status.js | 6 - models/enum/user_status_username.js | 25 + models/user.js | 141 +++- package.json | 61 +- perms/constants/mutation.js | 6 +- perms/reducers/index.js | 11 +- perms/reducers/mutation.js | 12 +- perms/reducers/query.js | 14 +- perms/reducers/subscription.js | 8 +- routes/api/account/index.js | 9 - routes/api/users/index.js | 80 +-- routes/index.js | 75 ++- scripts/e2e-ci.sh | 4 +- serve.js | 4 +- services/assets.js | 4 +- services/{domainlist.js => domain_list.js} | 16 +- services/users.js | 293 ++------- test/helpers/mongoose.js | 3 +- test/helpers/rejection.js | 3 + test/server/graph/mutations/addTag.js | 2 +- test/server/graph/mutations/createComment.js | 116 ++-- test/server/graph/mutations/removeTag.js | 2 +- .../graph/mutations/setUserBanStatus.js | 104 +++ .../mutations/setUserSuspensionStatus.js | 115 ++++ .../graph/mutations/setUserUsernameStatus.js | 87 +++ .../graph/mutations/updateAssetSettings.js | 3 +- test/server/graph/mutations/updateSettings.js | 3 +- test/server/routes/api/account/index.js | 57 -- test/server/routes/api/user/index.js | 49 -- .../{domainlist.js => domain_list.js} | 20 +- test/server/services/scraper.js | 22 - test/server/services/users.js | 169 ++--- yarn.lock | 614 ++++-------------- 49 files changed, 1112 insertions(+), 1598 deletions(-) delete mode 100644 client/coral-settings/components/Bio.css delete mode 100644 client/coral-settings/components/Bio.js delete mode 100644 client/coral-settings/containers/BioContainer.js delete mode 100644 models/enum/user_status.js create mode 100644 models/enum/user_status_username.js rename services/{domainlist.js => domain_list.js} (85%) create mode 100644 test/helpers/rejection.js create mode 100644 test/server/graph/mutations/setUserBanStatus.js create mode 100644 test/server/graph/mutations/setUserSuspensionStatus.js create mode 100644 test/server/graph/mutations/setUserUsernameStatus.js delete mode 100644 test/server/routes/api/account/index.js rename test/server/services/{domainlist.js => domain_list.js} (87%) delete mode 100644 test/server/services/scraper.js diff --git a/.nodemon.json b/.nodemon.json index 7f7fd3d59..36fed8700 100644 --- a/.nodemon.json +++ b/.nodemon.json @@ -1,5 +1,11 @@ { + "exec": "npm-run-all --parallel generate-introspection start:development", "verbose": true, "ignore": ["test/*", "client/*", "dist/*", "plugins/*/client"], - "ext": "js,json,graphql" + "ext": "js,json,graphql", + "watch": [ + ".", + "bin/cli", + "bin/cli-serve" + ] } diff --git a/bin/cli-users b/bin/cli-users index 89f53a67d..b82ee561d 100755 --- a/bin/cli-users +++ b/bin/cli-users @@ -106,20 +106,17 @@ async function createUser(options) { } const user = await UsersService.createLocalUser(answers.email.trim(), answers.password.trim(), answers.username.trim()); - console.log(`Created user ${user.id}.`); if (answers.roles.length > 0) { - return Promise.all(answers.roles.map((role) => { - return UsersService - .addRoleToUser(user.id, role) - .then(() => { - console.log(`Added the role ${role} to User ${user.id}.`); - }); - })); + for (const role of answers.roles) { + await UsersService.addRoleToUser(user.id, role); + } } - util.shutdown(); + await UsersService.sendEmailConfirmation(user, answers.email.trim()); + console.log(`Created User ${user.id}.`); + util.shutdown(); } catch (err) { console.error(err); util.shutdown(); @@ -241,12 +238,12 @@ function listUsers() { }); users.forEach((user) => { - let state = user.disabled ? 'Disabled' : 'Enabled'; const profile = user.profiles.find(({provider}) => provider === 'local'); + let state; if (profile && profile.metadata && profile.metadata.confirmed_at) { - state += ', Verified'; + state = 'Verified'; } else { - state += ', Unverified'; + state = 'Unverified'; } table.push([ @@ -336,74 +333,6 @@ function removeRole(userID, role) { }); } -/** - * Ban a user - * @param {String} userID id of the user to ban - */ -function ban(userID) { - UsersService - .setStatus(userID, 'BANNED') - .then(() => { - console.log(`Banned the User ${userID}.`); - util.shutdown(); - }) - .catch((err) => { - console.error(err); - util.shutdown(1); - }); -} - -/** - * Unban a user - * @param {String} userUD id of the user to remove the role from - */ -function unban(userID) { - UsersService - .setStatus(userID, 'ACTIVE') - .then(() => { - console.log(`Unban the User ${userID}.`); - util.shutdown(); - }) - .catch((err) => { - console.error(err); - util.shutdown(1); - }); -} - -/** - * Disable a given user. - * @param {String} userID the ID of a user to disable - */ -function disableUser(userID) { - UsersService - .disableUser(userID) - .then(() => { - console.log(`User ${userID} was disabled.`); - util.shutdown(); - }) - .catch((err) => { - console.error(err); - util.shutdown(1); - }); -} - -/** - * Enabled a given user. - * @param {String} userID the ID of a user to enable - */ -function enableUser(userID) { - UsersService - .enableUser(userID) - .then(() => { - console.log(`User ${userID} was enabled.`); - util.shutdown(); - }) - .catch((err) => { - console.error(err); - util.shutdown(1); - }); -} - /** * Verifies an email address for a user. * @@ -472,26 +401,6 @@ program .description('removes a role from a given user') .action(removeRole); -program - .command('ban ') - .description('ban a given user') - .action(ban); - -program - .command('uban ') - .description('unban a given user') - .action(unban); - -program - .command('disable ') - .description('disable a given user from logging in') - .action(disableUser); - -program - .command('enable ') - .description('enable a given user from logging in') - .action(enableUser); - program .command('verify ') .description('verifies the given user\'s email address') diff --git a/circle.yml b/circle.yml index 9f35736c6..ebb746669 100644 --- a/circle.yml +++ b/circle.yml @@ -7,6 +7,8 @@ machine: environment: PATH: "${PATH}:${HOME}/${CIRCLE_PROJECT_REPONAME}/node_modules/.bin" NODE_ENV: "test" + MOCHA_FILE: "${CIRCLE_TEST_REPORTS}/junit/test-results.xml" + MOCHA_REPORTER: "mocha-junit-reporter" pre: # TODO: use the following to add in support for MongoDB 3.4. # # Upgrade the database version to 3.4. @@ -47,10 +49,11 @@ database: test: override: # Run the tests using the junit reporter. - - MOCHA_FILE=$CIRCLE_TEST_REPORTS/junit/test-results.xml MOCHA_REPORTER=mocha-junit-reporter yarn test + - yarn test + # Run the end to end tests + - yarn e2e:ci # Check dependancies using nsp. - nsp check - - yarn e2e-ci deployment: release: diff --git a/client/coral-admin/src/containers/Header.js b/client/coral-admin/src/containers/Header.js index a5c1f0afc..e2c3692c4 100644 --- a/client/coral-admin/src/containers/Header.js +++ b/client/coral-admin/src/containers/Header.js @@ -14,7 +14,7 @@ export default withQuery(gql` }) flaggedUsernamesCount: userCount(query: { action_type: FLAG, - statuses: [PENDING] + statuses: [SET, CHANGED] }) } `, { diff --git a/client/coral-admin/src/routes/Community/containers/Community.js b/client/coral-admin/src/routes/Community/containers/Community.js index 4cf9eeb8a..6cb5e700d 100644 --- a/client/coral-admin/src/routes/Community/containers/Community.js +++ b/client/coral-admin/src/routes/Community/containers/Community.js @@ -22,7 +22,7 @@ const withData = withQuery(gql` query TalkAdmin_Community { flaggedUsernamesCount: userCount(query: { action_type: FLAG, - statuses: [PENDING] + statuses: [SET, CHANGED] }) ...${getDefinitionName(FlaggedAccounts.fragments.root)} ...${getDefinitionName(FlaggedUser.fragments.root)} diff --git a/client/coral-configure/components/CloseCommentsInfo.js b/client/coral-configure/components/CloseCommentsInfo.js index d10419f3f..cc0e12a77 100644 --- a/client/coral-configure/components/CloseCommentsInfo.js +++ b/client/coral-configure/components/CloseCommentsInfo.js @@ -26,4 +26,4 @@ CloseCommentsInfo.propTypes = { onClick: PropTypes.func, }; -export default CloseCommentsInfo; \ No newline at end of file +export default CloseCommentsInfo; diff --git a/client/coral-settings/components/Bio.css b/client/coral-settings/components/Bio.css deleted file mode 100644 index 8c36b989d..000000000 --- a/client/coral-settings/components/Bio.css +++ /dev/null @@ -1,21 +0,0 @@ -.bio textarea { - width: 100%; - box-sizing: border-box; - border-radius: 2px; - min-height: 100px; - margin: 10px 0; - border: solid 1px #d8d8d8; -} - -.bio h1 { - font-size: 16px; - margin: 3px 0; -} - -.bio p { - margin: 3px 0; -} - -.actions { - text-align: right; -} diff --git a/client/coral-settings/components/Bio.js b/client/coral-settings/components/Bio.js deleted file mode 100644 index cd1347781..000000000 --- a/client/coral-settings/components/Bio.js +++ /dev/null @@ -1,18 +0,0 @@ -import React from 'react'; -import styles from './Bio.css'; -import {Button} from '../../coral-ui'; - -export default ({bio, handleSave, handleInput, handleCancel}) => ( -
-

Bio

-

Tell the community about yourself

-
-