Merge branch 'user-status-refactor' of github.com:coralproject/talk into user-status-refactor

* 'user-status-refactor' of github.com:coralproject/talk:
  added mount path to the endpoint to respect the mounting config
  linting
  removed dev requirement for engine
This commit is contained in:
okbel
2017-12-20 21:14:21 -03:00
9 changed files with 63 additions and 46 deletions
+2 -2
View File
@@ -42,7 +42,7 @@ if (process.env.NODE_ENV !== 'test') {
app.use(morgan('dev'));
}
if (process.env.NODE_ENV === 'development' && ENABLE_TRACING && APOLLO_ENGINE_KEY) {
if (ENABLE_TRACING && APOLLO_ENGINE_KEY) {
const {Engine} = require('apollo-engine');
const engine = new Engine({
@@ -50,7 +50,7 @@ if (process.env.NODE_ENV === 'development' && ENABLE_TRACING && APOLLO_ENGINE_KE
apiKey: APOLLO_ENGINE_KEY
},
graphqlPort: PORT,
endpoint: '/api/v1/graph/ql',
endpoint: `${MOUNT_PATH}api/v1/graph/ql`,
});
engine.start();
@@ -19,6 +19,7 @@ class PeopleContainer extends React.Component {
onKeyDownHandler = (e) => {
if (e.key === 'Enter') {
e.preventDefault();
// this.fetchUsers();
}
}
@@ -152,6 +152,7 @@ class ModerationQueue extends React.Component {
nextComments &&
nextComments.length < prevComments.length
) {
// Invalidate first cursor if referenced comment was removed.
if (
this.state.idCursors[0] &&
@@ -111,10 +111,10 @@ class ModerationContainer extends Component {
this.props.auth.user.id === user.id
? ''
: t(
'modqueue.notify_accepted',
user.username,
prepareNotificationText(comment.body)
);
'modqueue.notify_accepted',
user.username,
prepareNotificationText(comment.body)
);
return this.handleCommentChange(prev, comment, notifyText);
},
},
@@ -132,10 +132,10 @@ class ModerationContainer extends Component {
this.props.auth.user.id === user.id
? ''
: t(
'modqueue.notify_rejected',
user.username,
prepareNotificationText(comment.body)
);
'modqueue.notify_rejected',
user.username,
prepareNotificationText(comment.body)
);
return this.handleCommentChange(prev, comment, notifyText);
},
},
@@ -153,10 +153,10 @@ class ModerationContainer extends Component {
this.props.auth.user.id === user.id
? ''
: t(
'modqueue.notify_reset',
user.username,
prepareNotificationText(comment.body)
);
'modqueue.notify_reset',
user.username,
prepareNotificationText(comment.body)
);
return this.handleCommentChange(prev, comment, notifyText);
},
},
@@ -207,6 +207,7 @@ class ModerationContainer extends Component {
}
componentWillReceiveProps(nextProps) {
// Resubscribe when we change between assets.
if (
this.props.data.variables.asset_id !== nextProps.data.variables.asset_id
@@ -275,12 +276,14 @@ class ModerationContainer extends Component {
if (assetId) {
if (asset === null) {
// Not found.
return <NotFoundAsset assetId={assetId} />;
}
}
if (data.loading) {
// loading.
return <Spinner />;
}
@@ -424,23 +427,23 @@ const withModQueueQuery = withQuery(
({queueConfig}) => gql`
query CoralAdmin_Moderation($asset_id: ID, $sortOrder: SORT_ORDER, $allAssets: Boolean!, $nullStatuses: [COMMENT_STATUS!]) {
${Object.keys(queueConfig).map(
(queue) => `
(queue) => `
${queue}: comments(query: {
statuses: ${
queueConfig[queue].statuses
? `[${queueConfig[queue].statuses.join(', ')}],`
: '$nullStatuses'
}
queueConfig[queue].statuses
? `[${queueConfig[queue].statuses.join(', ')}],`
: '$nullStatuses'
}
${
queueConfig[queue].tags
? `tags: ["${queueConfig[queue].tags.join('", "')}"],`
: ''
}
queueConfig[queue].tags
? `tags: ["${queueConfig[queue].tags.join('", "')}"],`
: ''
}
${
queueConfig[queue].action_type
? `action_type: ${queueConfig[queue].action_type}`
: ''
}
queueConfig[queue].action_type
? `action_type: ${queueConfig[queue].action_type}`
: ''
}
asset_id: $asset_id,
sortOrder: $sortOrder,
limit: 20,
@@ -448,29 +451,29 @@ const withModQueueQuery = withQuery(
...CoralAdmin_Moderation_CommentConnection
}
`
)}
)}
${Object.keys(queueConfig).map(
(queue) => `
(queue) => `
${queue}Count: commentCount(query: {
statuses: ${
queueConfig[queue].statuses
? `[${queueConfig[queue].statuses.join(', ')}],`
: '$nullStatuses'
}
queueConfig[queue].statuses
? `[${queueConfig[queue].statuses.join(', ')}],`
: '$nullStatuses'
}
${
queueConfig[queue].tags
? `tags: ["${queueConfig[queue].tags.join('", "')}"],`
: ''
}
queueConfig[queue].tags
? `tags: ["${queueConfig[queue].tags.join('", "')}"],`
: ''
}
${
queueConfig[queue].action_type
? `action_type: ${queueConfig[queue].action_type}`
: ''
}
queueConfig[queue].action_type
? `action_type: ${queueConfig[queue].action_type}`
: ''
}
asset_id: $asset_id,
})
`
)}
)}
asset(id: $asset_id) @skip(if: $allAssets) {
id
title
@@ -50,6 +50,7 @@ class StreamContainer extends React.Component {
assetId: this.props.asset.id,
},
updateQuery: (prev, {subscriptionData: {data: {commentEdited}}}) => {
// Ignore mutations from me.
// TODO: need way to detect mutations created by this client, and allow mutations from other clients.
if (
@@ -82,6 +83,7 @@ class StreamContainer extends React.Component {
assetId: this.props.asset.id,
},
updateQuery: (prev, {subscriptionData: {data: {commentAdded}}}) => {
// Ignore mutations from me.
// TODO: need way to detect mutations created by this client, and allow mutations from other clients.
if (
@@ -338,14 +340,14 @@ const fragments = {
comment(id: $commentId) @include(if: $hasComment) {
...CoralEmbedStream_Stream_comment
${nest(
`
`
parent {
...CoralEmbedStream_Stream_comment
...nest
}
`,
THREADING_LEVEL
)}
THREADING_LEVEL
)}
}
id
title
+1
View File
@@ -45,6 +45,7 @@ export const can = (user, ...perms) => {
}
return perms.every((perm) => {
// Basic Permissions
const permAction = basicPerms[perm];
if (typeof permAction !== 'undefined') {
+1
View File
@@ -16,6 +16,7 @@ const debug = require('debug')('talk:config');
//==============================================================================
const CONFIG = {
// WEBPACK indicates when webpack is currently building.
WEBPACK: process.env.WEBPACK === 'TRUE',
+1 -1
View File
@@ -52,6 +52,7 @@
"@coralproject/graphql-anywhere-optimized": "^0.1.0",
"accepts": "^1.3.4",
"apollo-client": "^1.9.1",
"apollo-engine": "^0.6.0",
"apollo-server-express": "^1.2.0",
"apollo-utilities": "^1.0.3",
"app-module-path": "^2.2.0",
@@ -185,7 +186,6 @@
},
"devDependencies": {
"@coralproject/eslint-config-talk": "^0.0.4",
"apollo-engine": "^0.6.0",
"babel-jest": "^21.2.0",
"babel-plugin-dynamic-import-node": "^1.1.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
+8
View File
@@ -48,6 +48,7 @@ const loginRateLimiter = new Limit(
// UsersService is the interface for the application to interact with the
// UserModel through.
class UsersService {
/**
* Returns a user (if found) for the given email address.
*/
@@ -530,6 +531,7 @@ class UsersService {
}
if (checkAgainstWordlist) {
// check for profanity
let err = await Wordlist.usernameCheck(username);
if (err) {
@@ -639,11 +641,13 @@ class UsersService {
* @param {Object} token a jwt token used to sign in the user
*/
static async findOrCreateByIDToken(id, token) {
// Try to get the user.
let user = await UserModel.findOne({id});
// If the user was not found, try to look it up.
if (user === null) {
// If the user wasn't found, it will return null and the variable will be
// unchanged.
user = await lookupUserNotFound(token);
@@ -693,6 +697,7 @@ class UsersService {
DomainList.urlCheck(loc),
]);
if (!user) {
// Since we don't want to reveal that the email does/doesn't exist
// just go ahead and resolve the Promise with null and check in the
// endpoint.
@@ -772,6 +777,7 @@ class UsersService {
return UserModel.find({
$or: [
// Search by a prefix match on the username.
{
lowercaseUsername: {
@@ -973,6 +979,7 @@ class UsersService {
module.exports = UsersService;
events.on(USERS_BAN_CHANGE, async (user, {status, message}) => {
// Check to see if the user was banned now and is currently banned.
if (user.banned && status && message && message.length > 0) {
await UsersService.sendEmail(user, {
@@ -986,6 +993,7 @@ events.on(USERS_BAN_CHANGE, async (user, {status, message}) => {
});
events.on(USERS_SUSPENSION_CHANGE, async (user, {until, message}) => {
// Check to see if the user was suspended now and is currently suspended.
if (
user.suspended &&