);
-export default CreateDisplayNameDialog;
+export default CreateUsernameDialog;
diff --git a/client/coral-sign-in/containers/ChangeDisplayNameContainer.js b/client/coral-sign-in/containers/ChangeUsernameContainer.js
similarity index 74%
rename from client/coral-sign-in/containers/ChangeDisplayNameContainer.js
rename to client/coral-sign-in/containers/ChangeUsernameContainer.js
index 625985b63..33ae63614 100644
--- a/client/coral-sign-in/containers/ChangeDisplayNameContainer.js
+++ b/client/coral-sign-in/containers/ChangeUsernameContainer.js
@@ -4,21 +4,21 @@ import {connect} from 'react-redux';
import validate from 'coral-framework/helpers/validate';
import errorMsj from 'coral-framework/helpers/error';
-import CreateDisplayNameDialog from '../components/CreateDisplayNameDialog';
+import CreateUsernameDialog from '../components/CreateUsernameDialog';
import I18n from 'coral-framework/modules/i18n/i18n';
import translations from '../translations';
const lang = new I18n(translations);
import {
- showCreateDisplayNameDialog,
- hideCreateDisplayNameDialog,
+ showCreateUsernameDialog,
+ hideCreateUsernameDialog,
invalidForm,
validForm,
- createDisplayName
+ createUsername
} from '../../coral-framework/actions/auth';
-class ChangeDisplayNameContainer extends Component {
+class ChangeUsernameContainer extends Component {
initialState = {
formData: {
username: '',
@@ -31,7 +31,7 @@ class ChangeDisplayNameContainer extends Component {
super(props);
this.state = this.initialState;
this.handleChange = this.handleChange.bind(this);
- this.handleSubmitDisplayName = this.handleSubmitDisplayName.bind(this);
+ this.handleSubmitUsername = this.handleSubmitUsername.bind(this);
this.handleClose = this.handleClose.bind(this);
this.addError = this.addError.bind(this);
}
@@ -81,13 +81,13 @@ class ChangeDisplayNameContainer extends Component {
this.setState({showErrors: show});
}
- handleSubmitDisplayName(e) {
+ handleSubmitUsername(e) {
e.preventDefault();
const {errors} = this.state;
const {validForm, invalidForm} = this.props;
this.displayErrors();
if (this.isCompleted() && !Object.keys(errors).length) {
- this.props.createDisplayName(this.props.user.id, this.state.formData);
+ this.props.createUsername(this.props.user.id, this.state.formData);
validForm();
} else {
invalidForm(lang.t('createdisplay.checkTheForm'));
@@ -95,19 +95,19 @@ class ChangeDisplayNameContainer extends Component {
}
handleClose() {
- this.props.hideCreateDisplayNameDialog();
+ this.props.hideCreateUsernameDialog();
}
render() {
const {loggedIn, auth, offset} = this.props;
return (
- ({
});
const mapDispatchToProps = dispatch => ({
- createDisplayName: (userid, formData) => dispatch(createDisplayName(userid, formData)),
- showCreateDisplayNameDialog: () => dispatch(showCreateDisplayNameDialog()),
- hideCreateDisplayNameDialog: () => dispatch(hideCreateDisplayNameDialog()),
+ createUsername: (userid, formData) => dispatch(createUsername(userid, formData)),
+ showCreateUsernameDialog: () => dispatch(showCreateUsernameDialog()),
+ hideCreateUsernameDialog: () => dispatch(hideCreateUsernameDialog()),
invalidForm: error => dispatch(invalidForm(error)),
validForm: () => dispatch(validForm())
});
@@ -132,4 +132,4 @@ const mapDispatchToProps = dispatch => ({
export default connect(
mapStateToProps,
mapDispatchToProps
-)(ChangeDisplayNameContainer);
+)(ChangeUsernameContainer);
diff --git a/client/coral-sign-in/translations.js b/client/coral-sign-in/translations.js
index 36ce3fce4..a2bb60819 100644
--- a/client/coral-sign-in/translations.js
+++ b/client/coral-sign-in/translations.js
@@ -26,7 +26,7 @@ export default {
emailORusernameInUse: 'Email address or Username already in use',
requiredField: 'This field is required',
passwordsDontMatch: 'Passwords don\'t match.',
- specialCharacters: 'Display names can contain letters, numbers and _ only',
+ specialCharacters: 'Usernames can contain letters, numbers and _ only',
checkTheForm: 'Invalid Form. Please, check the fields'
},
'createdisplay': {
@@ -37,8 +37,8 @@ export default {
requiredField: 'Required field',
errorCreate: 'Error when changing username',
checkTheForm: 'Invalid Form. Please, check the fields',
- specialCharacters: 'Display names can contain letters, numbers and _ only'
- },
+ specialCharacters: 'Usernames can contain letters, numbers and _ only'
+ }
},
es: {
'signIn': {
diff --git a/errors.js b/errors.js
index ad8288dad..6d9abbcfd 100644
--- a/errors.js
+++ b/errors.js
@@ -54,8 +54,8 @@ const ErrEmailTaken = new APIError('Email address already in use', {
status: 400
});
-const ErrDisplayTaken = new APIError('Username already in use', {
- translation_key: 'DISPLAYNAME_IN_USE',
+const ErrUsernameTaken = new APIError('Username already in use', {
+ translation_key: 'USERNAME_IN_USE',
status: 400
});
@@ -64,8 +64,8 @@ const ErrSpecialChars = new APIError('No special characters are allowed in a use
status: 400
});
-const ErrMissingDisplay = new APIError('A username is required to create a user', {
- translation_key: 'DISPLAY_NAME_REQUIRED',
+const ErrMissingUsername = new APIError('A username is required to create a user', {
+ translation_key: 'USERNAME_REQUIRED',
status: 400
});
@@ -142,6 +142,12 @@ const ErrInstallLock = new APIError('install lock active', {
status: 500
});
+// ErrPermissionUpdateUsername is returned when the user does not have permission to update their username.
+const ErrPermissionUpdateUsername = new APIError('You do not have permission to update your username.', {
+ translation_key: 'EDIT_USERNAME_NOT_AUTHORIZED',
+ status: 500
+});
+
module.exports = {
ExtendableError,
APIError,
@@ -152,14 +158,15 @@ module.exports = {
ErrMissingToken,
ErrEmailTaken,
ErrSpecialChars,
- ErrMissingDisplay,
+ ErrMissingUsername,
ErrContainsProfanity,
- ErrDisplayTaken,
+ ErrUsernameTaken,
ErrAssetCommentingClosed,
ErrNotFound,
ErrInvalidAssetURL,
ErrAuthentication,
ErrNotAuthorized,
+ ErrPermissionUpdateUsername,
ErrSettingsInit,
ErrInstallLock
};
diff --git a/graph/loaders/comments.js b/graph/loaders/comments.js
index 24b66f4bd..ad78a1e92 100644
--- a/graph/loaders/comments.js
+++ b/graph/loaders/comments.js
@@ -68,6 +68,38 @@ const getCountsByParentID = (context, parent_ids) => {
.then((results) => results.map((result) => result ? result.count : 0));
};
+/**
+ * Retrieves the count of comments based on the passed in query.
+ * @param {Object} context graph context
+ * @param {Object} query query to execute against the comments collection
+ * to compute the counts
+ * @return {Promise} resolves to the counts of the comments from the
+ * query
+ */
+const getCommentCountByQuery = (context, {ids, statuses, asset_id, parent_id}) => {
+ let query = CommentModel.find();
+
+ if (ids) {
+ query = query.where({id: {$in: ids}});
+ }
+
+ if (statuses) {
+ query = query.where({status: {$in: statuses}});
+ }
+
+ if (asset_id != null) {
+ query = query.where({asset_id});
+ }
+
+ if (parent_id !== undefined) {
+ query = query.where({parent_id});
+ }
+
+ return CommentModel
+ .find(query)
+ .count();
+};
+
/**
* Retrieves comments based on the passed in query that is filtered by the
* current used passed in via the context.
@@ -101,6 +133,7 @@ const getCommentsByQuery = ({user}, {ids, statuses, asset_id, parent_id, author_
});
}
+ // Only let an admin request any user or the current user request themself.
if (user && (user.hasRoles('ADMIN') || user.id === author_id) && author_id != null) {
comments = comments.where({author_id});
}
@@ -136,7 +169,13 @@ const getCommentsByQuery = ({user}, {ids, statuses, asset_id, parent_id, author_
.limit(limit);
};
-const genRecentReplies = (_, ids) => {
+/**
+ * Gets the recent replies.
+ * @param {Object} context graph context
+ * @param {Array} ids ids of parent ids
+ * @return {Promise} resolves to recent replies
+ */
+const genRecentReplies = (context, ids) => {
return CommentModel.aggregate([
// get all the replies for the comments in question
@@ -180,6 +219,12 @@ const genRecentReplies = (_, ids) => {
.then(util.arrayJoinBy(ids, 'parent_id'));
};
+/**
+ * Gets the recent comments.
+ * @param {Object} context graph context
+ * @param {Array} ids ids of asset ids
+ * @return {Promise} resolves to recent comments from assets
+ */
const genRecentComments = (_, ids) => {
return CommentModel.aggregate([
@@ -233,6 +278,7 @@ const genRecentComments = (_, ids) => {
module.exports = (context) => ({
Comments: {
getByQuery: (query) => getCommentsByQuery(context, query),
+ getCountByQuery: (query) => getCommentCountByQuery(context, query),
countByAssetID: new util.SharedCacheDataLoader('Comments.countByAssetID', 3600, (ids) => getCountsByAssetID(context, ids)),
countByParentID: new util.SharedCacheDataLoader('Comments.countByParentID', 3600, (ids) => getCountsByParentID(context, ids)),
genRecentReplies: new DataLoader((ids) => genRecentReplies(context, ids)),
diff --git a/graph/resolvers/root_query.js b/graph/resolvers/root_query.js
index eb66274dd..ced4e65cf 100644
--- a/graph/resolvers/root_query.js
+++ b/graph/resolvers/root_query.js
@@ -39,6 +39,23 @@ const RootQuery = {
return Comments.getByQuery(query);
},
+ commentCount(_, {query: {action_type, statuses, asset_id, parent_id}}, {user, loaders: {Actions, Comments}}) {
+ if (user == null || !user.hasRoles('ADMIN')) {
+ return null;
+ }
+
+ if (action_type) {
+ return Actions.getByTypes({action_type, item_type: 'COMMENTS'})
+ .then((ids) => {
+
+ // Perform the query using the available resolver.
+ return Comments.getCountByQuery({ids, statuses, asset_id, parent_id});
+ });
+ }
+
+ return Comments.getCountByQuery({statuses, asset_id, parent_id});
+ },
+
metrics(_, {from, to, sort, limit = 10}, {user, loaders: {Metrics}}) {
if (user == null || !user.hasRoles('ADMIN')) {
return null;
diff --git a/graph/typeDefs.graphql b/graph/typeDefs.graphql
index cabb50985..72a54a0cd 100644
--- a/graph/typeDefs.graphql
+++ b/graph/typeDefs.graphql
@@ -27,7 +27,7 @@ type User {
# The ID of the User.
id: ID!
- # username of a user.
+ # Username of a user.
username: String!
# Action summaries against the user.
@@ -96,10 +96,40 @@ enum ACTION_TYPE {
# CommentsQuery allows the ability to query comments by a specific methods.
input CommentsQuery {
- # current status of a comment.
+ # Current status of a comment. Requires the `ADMIN` role.
statuses: [COMMENT_STATUS!]
- # asset that a comment is on.
+ # Asset that a comment is on.
+ asset_id: ID
+
+ # The parent of the comment that we want to retrieve.
+ parent_id: ID
+
+ # Comments returned will only be ones which have at least one action of this
+ # type. Requires the `ADMIN` role.
+ action_type: ACTION_TYPE
+
+ # Limit the number of results to be returned.
+ limit: Int = 10
+
+ # Skip results from the last created_at timestamp.
+ cursor: Date
+
+ # Filter by a specific tag name.
+ tag: [String]
+
+ # Sort the results by created_at.
+ sort: SORT_ORDER = REVERSE_CHRONOLOGICAL
+}
+
+# CommentCountQuery allows the ability to query comment counts by specific
+# methods.
+input CommentCountQuery {
+
+ # Current status of a comment. Requires the `ADMIN` role.
+ statuses: [COMMENT_STATUS!]
+
+ # Asset that a comment is on.
asset_id: ID
# the parent of the comment that we want to retrieve.
@@ -109,17 +139,8 @@ input CommentsQuery {
# type.
action_type: ACTION_TYPE
- # limit the number of results to be returned.
- limit: Int = 10
-
- # skip results from the last created_at timestamp.
- cursor: Date
-
- # filter by a specific tag name.
+ # Filter by a specific tag name.
tag: [String]
-
- # sort the results by created_at.
- sort: SORT_ORDER = REVERSE_CHRONOLOGICAL
}
# Comment is the base representation of user interaction in Talk.
@@ -146,7 +167,7 @@ type Comment {
# The count of replies on a comment.
replyCount: Int
- # Actions completed on the parent.
+ # Actions completed on the parent. Requires the `ADMIN` role.
actions: [Action]
# Action summaries against a comment.
@@ -350,7 +371,7 @@ type Asset {
closedAt: Date
# Summary of all Actions against all entities associated with the Asset.
- # (likes, flags, etc.)
+ # (likes, flags, etc.). Requires the `ADMIN` role.
action_summaries: [AssetActionSummary]
# The date that the asset was created.
@@ -418,7 +439,7 @@ type RootQuery {
# Site wide settings and defaults.
settings: Settings
- # All assets.
+ # All assets. Requires the `ADMIN` role.
assets: [Asset]
# Find or create an asset by url, or just find with the ID.
@@ -427,7 +448,12 @@ type RootQuery {
# Comments returned based on a query.
comments(query: CommentsQuery!): [Comment]
- # The currently logged in user based on the request.
+ # Returne the count of comments satisfied by the query. Note that this edge is
+ # expensive as it is not batched. Requires the `ADMIN` role.
+ commentCount(query: CommentCountQuery!): Int
+
+ # The currently logged in user based on the request. Requires any logged in
+ # role.
me: User
# Metrics related to user actions are saturated into the assets returned. The
@@ -554,10 +580,10 @@ type RootMutation {
# Delete an action based on the action id.
deleteAction(id: ID!): DeleteActionResponse
- # Sets User status
+ # Sets User status. Requires the `ADMIN` role.
setUserStatus(id: ID!, status: USER_STATUS!): SetUserStatusResponse
- # Sets Comment status
+ # Sets Comment status. Requires the `ADMIN` role.
setCommentStatus(id: ID!, status: COMMENT_STATUS!): SetCommentStatusResponse
}
diff --git a/routes/api/account/index.js b/routes/api/account/index.js
index 3de9d41c3..4eab8b920 100644
--- a/routes/api/account/index.js
+++ b/routes/api/account/index.js
@@ -123,7 +123,7 @@ router.put('/username', authorization.needed(), (req, res, next) => {
})
.catch(error => {
if (error.code === 11000) {
- next(errors.ErrDisplayTaken);
+ next(errors.ErrUsernameTaken);
} else {
next(error);
}
diff --git a/services/passport.js b/services/passport.js
index d265d9812..229541521 100644
--- a/services/passport.js
+++ b/services/passport.js
@@ -103,8 +103,6 @@ if (process.env.TALK_FACEBOOK_APP_ID && process.env.TALK_FACEBOOK_APP_SECRET &&
clientSecret: process.env.TALK_FACEBOOK_APP_SECRET,
callbackURL: `${process.env.TALK_ROOT_URL}/api/v1/auth/facebook/callback`,
- // TODO: remove displayName reference when we have steps in the FE to handle
- // the username create flow.
profileFields: ['id', 'displayName', 'picture.type(large)']
}, (accessToken, refreshToken, profile, done) => {
UsersService
diff --git a/services/setup.js b/services/setup.js
index 2bfbc66a0..1f1542d5e 100644
--- a/services/setup.js
+++ b/services/setup.js
@@ -57,7 +57,7 @@ module.exports = class SetupService {
// Verify other properties of the user.
return Promise.all([
- UsersService.isValidDisplayName(username, false),
+ UsersService.isValidUsername(username, false),
UsersService.isValidPassword(password),
settingsModel.validate()
]);
diff --git a/services/users.js b/services/users.js
index f715fa9f4..b09a7d399 100644
--- a/services/users.js
+++ b/services/users.js
@@ -109,7 +109,7 @@ module.exports = class UsersService {
* @param {Object} profile - User social/external profile
* @param {Function} done [description]
*/
- static findOrCreateExternalUser({id, provider, displayname}) {
+ static findOrCreateExternalUser({id, provider, displayName}) {
return UserModel
.findOne({
profiles: {
@@ -124,7 +124,7 @@ module.exports = class UsersService {
return user;
}
- let username = UsersService.castUsername(displayname);
+ let username = UsersService.castUsername(displayName);
// The user was not found, lets create them!
user = new UserModel({
@@ -176,11 +176,11 @@ module.exports = class UsersService {
* @param {Boolean} checkAgainstWordlist enables cheching against the wordlist
* @return {Promise}
*/
- static isValidUserName(username, checkAgainstWordlist = true) {
+ static isValidUsername(username, checkAgainstWordlist = true) {
const onlyLettersNumbersUnderscore = /^[A-Za-z0-9_]+$/;
if (!username) {
- return Promise.reject(errors.ErrMissingDisplay);
+ return Promise.reject(errors.ErrMissingUsername);
}
if (!onlyLettersNumbersUnderscore.test(username)) {
@@ -230,7 +230,7 @@ module.exports = class UsersService {
username = username.trim();
return Promise.all([
- UsersService.isValidUserName(username),
+ UsersService.isValidUsername(username),
UsersService.isValidPassword(password)
])
.then(() => { // username is valid
@@ -257,7 +257,7 @@ module.exports = class UsersService {
if (err) {
if (err.code === 11000) {
if (err.message.match('Username')) {
- return reject(errors.ErrDisplayTaken);
+ return reject(errors.ErrUsernameTaken);
}
return reject(errors.ErrEmailTaken);
}
@@ -688,7 +688,7 @@ module.exports = class UsersService {
}
}).then((result) => {
return result.nModified > 0 ? result :
- Promise.reject(new Error('You do not have permission to update your username.'));
+ Promise.reject(errors.ErrPermissionUpdateUsername);
});
}
};
diff --git a/test/e2e/pages/embedStreamPage.js b/test/e2e/pages/embedStreamPage.js
index b25eec419..ca72df1db 100644
--- a/test/e2e/pages/embedStreamPage.js
+++ b/test/e2e/pages/embedStreamPage.js
@@ -19,7 +19,7 @@ const embedStreamCommands = {
.setValue('@signInDialogEmail', user.email)
.setValue('@signInDialogPassword', user.pass)
.setValue('@signUpDialogConfirmPassword', user.pass)
- .setValue('@signUpDialogDisplayName', user.username)
+ .setValue('@signUpDialogUsername', user.username)
.waitForElementVisible('@signUpButton')
.click('@signUpButton')
.waitForElementVisible('@signInViewTrigger')
@@ -95,7 +95,7 @@ module.exports = {
signUpDialogConfirmPassword: {
selector: '#signInDialog #confirmPassword'
},
- signUpDialogDisplayName: {
+ signUpDialogUsername: {
selector: '#signInDialog #username'
},
logInButton: {
diff --git a/yarn.lock b/yarn.lock
index f1c047be2..5413439fa 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -175,11 +175,11 @@ anymatch@^1.3.0:
arrify "^1.0.0"
micromatch "^2.1.5"
-apollo-client@^0.7.3:
- version "0.7.3"
- resolved "https://registry.yarnpkg.com/apollo-client/-/apollo-client-0.7.3.tgz#f27702409ce4b90c3adbd78d8434c3e8d762c7dd"
+apollo-client@^0.8.3:
+ version "0.8.6"
+ resolved "https://registry.yarnpkg.com/apollo-client/-/apollo-client-0.8.6.tgz#9aa18b03ec338f0a3804122df7f77493a10b72a0"
dependencies:
- graphql-anywhere "^2.0.0"
+ graphql-anywhere "^2.1.0"
graphql-tag "^1.1.1"
redux "^3.4.0"
symbol-observable "^1.0.2"
@@ -3303,7 +3303,7 @@ graceful-fs@~2.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/graceful-readlink/-/graceful-readlink-1.0.1.tgz#4cafad76bc62f02fa039b2f94e9a3dd3a391a725"
-graphql-anywhere@^2.0.0:
+graphql-anywhere@^2.0.0, graphql-anywhere@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/graphql-anywhere/-/graphql-anywhere-2.1.0.tgz#888c0a1718db3ff866b313070747777380560f69"
@@ -6375,9 +6375,9 @@ react-addons-test-utils@15.3.2:
version "15.3.2"
resolved "https://registry.yarnpkg.com/react-addons-test-utils/-/react-addons-test-utils-15.3.2.tgz#c09a44f583425a4a9c1b38444d7a6c3e6f0f41f6"
-react-apollo@^0.8.1:
- version "0.8.3"
- resolved "https://registry.yarnpkg.com/react-apollo/-/react-apollo-0.8.3.tgz#e799bdc913948bb487dfa90921b2ea8d08464816"
+react-apollo@^0.10.0:
+ version "0.10.1"
+ resolved "https://registry.yarnpkg.com/react-apollo/-/react-apollo-0.10.1.tgz#97fd50855f8575672aa68330b9c64a201cd13343"
dependencies:
graphql-anywhere "^2.0.0"
hoist-non-react-statics "^1.2.0"