adds suspendUser func and mutation.

This commit is contained in:
gaba
2017-03-02 15:54:50 -08:00
parent 1899dcbb7e
commit 2fa832a3f4
9 changed files with 69 additions and 18 deletions
+18 -10
View File
@@ -6,18 +6,26 @@ const setUserStatus = ({user}, {id, status}) => {
.then(res => res);
};
module.exports = (context) => {
if (context.user && context.user.can('mutation:setUserStatus')) {
return {
User: {
setUserStatus: (action) => setUserStatus(context, action)
}
};
}
const suspendUser = ({user}, {id}) => {
return UsersService.suspendUser(id)
.then(res => res);
};
return {
module.exports = (context) => {
let mutators = {
User: {
setUserStatus: () => Promise.reject(errors.ErrNotAuthorized)
setUserStatus: () => Promise.reject(errors.ErrNotAuthorized),
suspendUser: () => Promise.reject(errors.ErrNotAuthorized)
}
};
if (context.user && context.user.can('mutation:setUserStatus')) {
mutators.User.setUserStatus = (action) => setUserStatus(context, action);
}
if (context.user && context.user.can('mutation:suspendUser')) {
mutators.User.suspendUser = (action) => suspendUser(context, action);
}
return mutators;
};
+3
View File
@@ -46,6 +46,9 @@ const RootMutation = {
setUserStatus(_, {id, status}, {mutators: {User}}) {
return wrapResponse(null)(User.setUserStatus({id, status}));
},
suspendUser(_, {id}, {mutators: {User}}) {
return wrapResponse(null)(User.suspendUser({id}));
},
setCommentStatus(_, {id, status}, {mutators: {Comment}}) {
return wrapResponse(null)(Comment.setCommentStatus({id, status}));
}
+11
View File
@@ -639,6 +639,14 @@ type SetUserStatusResponse implements Response {
errors: [UserError]
}
# SuspendUserResponse is the response returned with possibly some errors
# relating to the suspend action attempt.
type SuspendUserResponse implements Response {
# An array of errors relating to the mutation that occurred.
errors: [UserError]
}
# SetCommentStatusResponse is the response returned with possibly some errors
# relating to the delete action attempt.
type SetCommentStatusResponse implements Response {
@@ -668,6 +676,9 @@ type RootMutation {
# Sets User status. Requires the `ADMIN` role.
setUserStatus(id: ID!, status: USER_STATUS!): SetUserStatusResponse
# Sets User status to BANNED and canEditName to true. Requires the `ADMIN` role.
suspendUser(id: ID!): SuspendUserResponse
# Sets Comment status. Requires the `ADMIN` role.
setCommentStatus(id: ID!, status: COMMENT_STATUS!): SetCommentStatusResponse
}