Merge branch 'master' into sory-139595043-qbox

This commit is contained in:
gaba
2017-02-14 08:51:58 -08:00
57 changed files with 1179 additions and 663 deletions
+25 -10
View File
@@ -162,22 +162,37 @@ const createPublicComment = (context, commentInput) => {
}));
};
/**
* Sets the status of a comment
* @param {String} comment comment in graphql context
* @param {String} id identifier of the comment (uuid)
* @param {String} status the new status of the comment
*/
const setCommentStatus = ({comment}, {id, status}) => {
return CommentsService.setStatus(id, status)
.then(res => res);
};
module.exports = (context) => {
// TODO: refactor to something that'll return an error in the event an attempt
// is made to mutate state while not logged in. There's got to be a better way
// to do this.
if (context.user && context.user.can('mutation:createComment')) {
return {
Comment: {
create: (comment) => createPublicComment(context, comment)
}
};
}
return {
let mutators = {
Comment: {
create: () => Promise.reject(errors.ErrNotAuthorized)
create: () => Promise.reject(errors.ErrNotAuthorized),
setCommentStatus: () => Promise.reject(errors.ErrNotAuthorized)
}
};
if (context.user && context.user.can('mutation:createComment')) {
mutators.Comment.create = (comment) => createPublicComment(context, comment);
}
if (context.user && context.user.can('mutation:setCommentStatus')) {
mutators.Comment.setCommentStatus = (action) => setCommentStatus(context, action);
}
return mutators;
};
+2
View File
@@ -2,6 +2,7 @@ const _ = require('lodash');
const Comment = require('./comment');
const Action = require('./action');
const User = require('./user');
module.exports = (context) => {
@@ -9,6 +10,7 @@ module.exports = (context) => {
return _.merge(...[
Comment,
Action,
User,
].map((mutators) => {
// Each set of mutators is a function which takes the context.
+27
View File
@@ -0,0 +1,27 @@
const errors = require('../../errors');
const UsersService = require('../../services/users');
const setUserStatus = ({user}, {id, status}) => {
return UsersService.setStatus(id, status)
.then(res => res);
};
module.exports = (context) => {
// TODO: refactor to something that'll return an error in the event an attempt
// is made to mutate state while not logged in. There's got to be a better way
// to do this.
if (context.user && context.user.can('mutation:setUserStatus')) {
return {
User: {
setUserStatus: (action) => setUserStatus(context, action)
}
};
}
return {
User: {
setUserStatus: () => Promise.reject(errors.ErrNotAuthorized)
}
};
};
+6
View File
@@ -27,6 +27,12 @@ const RootMutation = {
deleteAction(_, {id}, {mutators: {Action}}) {
return wrapResponse(null)(Action.delete({id}));
},
setUserStatus(_, {id, status}, {mutators: {User}}) {
return wrapResponse(null)(User.setUserStatus({id, status}));
},
setCommentStatus(_, {id, status}, {mutators: {Comment}}) {
return wrapResponse(null)(Comment.setCommentStatus({id, status}));
}
};
module.exports = RootMutation;
+1 -6
View File
@@ -29,12 +29,7 @@ const RootQuery = {
if (user != null && user.hasRoles('ADMIN') && action_type) {
return Actions.getByTypes({action_type, item_type: 'COMMENTS'})
.then((actions) => {
// Map the actions from the items referenced byt this query. The actions
// returned by this query are explicitly going to be distinct by their
// `item_id`'s.
let ids = actions.map((action) => action.item_id);
.then((ids) => {
// Perform the query using the available resolver.
return Comments.getByQuery({ids, statuses, asset_id, parent_id, limit, cursor, sort});
+32
View File
@@ -44,6 +44,9 @@ type User {
# returns all comments based on a query.
comments(query: CommentsQuery): [Comment]
# returns user status
status: USER_STATUS
}
type Tag {
@@ -362,6 +365,13 @@ enum SORT_ORDER {
}
# All queries that can be executed.
enum USER_STATUS {
ACTIVE
BANNED
PENDING
APPROVED
}
type RootQuery {
# Site wide settings and defaults.
@@ -468,6 +478,22 @@ type DeleteActionResponse implements Response {
errors: [UserError]
}
# SetUserStatusResponse is the response returned with possibly some errors
# relating to the delete action attempt.
type SetUserStatusResponse implements Response {
# An array of errors relating to the mutation that occured.
errors: [UserError]
}
# SetCommentStatusResponse is the response returned with possibly some errors
# relating to the delete action attempt.
type SetCommentStatusResponse implements Response {
# An array of errors relating to the mutation that occured.
errors: [UserError]
}
# All mutations for the application are defined on this object.
type RootMutation {
@@ -482,6 +508,12 @@ type RootMutation {
# Delete an action based on the action id.
deleteAction(id: ID!): DeleteActionResponse
# Sets User status
setUserStatus(id: ID!, status: USER_STATUS!): SetUserStatusResponse
# Sets Comment status
setCommentStatus(id: ID!, status: COMMENT_STATUS!): SetCommentStatusResponse
}
################################################################################