mirror of
https://github.com/wassname/talk.git
synced 2026-07-22 13:00:29 +08:00
adds new mutations: setCommentStatus
This commit is contained in:
@@ -14,10 +14,9 @@ const ActionButton = ({type = '', user, ...props}) => {
|
||||
className={`${type.toLowerCase()} ${styles.actionButton}`}
|
||||
cStyle={type.toLowerCase()}
|
||||
icon={menuActionsMap[type].icon}
|
||||
onClick={() => {}}
|
||||
onClick={type === 'APPROVE' ? props.acceptComment : props.rejectComment}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default ActionButton;
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import key from 'keymaster';
|
||||
import isEqual from 'lodash/isEqual';
|
||||
|
||||
import {modQueueQuery} from '../../graphql/queries';
|
||||
import {banUser} from '../../graphql/mutations';
|
||||
import {banUser, setCommentStatus} from '../../graphql/mutations';
|
||||
|
||||
import {fetchSettings} from 'actions/settings';
|
||||
import {updateAssets} from 'actions/assets';
|
||||
@@ -52,6 +52,11 @@ class ModerationContainer extends Component {
|
||||
return <div><Spinner/></div>;
|
||||
}
|
||||
|
||||
if (data.error) {
|
||||
console.log(data);
|
||||
return <div>Error</div>;
|
||||
}
|
||||
|
||||
if (providedAssetId) {
|
||||
asset = assets.find(asset => asset.id === this.props.params.id);
|
||||
|
||||
@@ -61,7 +66,6 @@ class ModerationContainer extends Component {
|
||||
}
|
||||
|
||||
const enablePremodTab = !!data.premod.length;
|
||||
console.log(props.banUser);
|
||||
return (
|
||||
<div>
|
||||
<ModerationHeader asset={asset} />
|
||||
@@ -75,6 +79,8 @@ class ModerationContainer extends Component {
|
||||
enablePremodTab={enablePremodTab}
|
||||
suspectWords={settings.wordlist.suspect}
|
||||
showBanUserDialog={props.showBanUserDialog}
|
||||
acceptComment={props.acceptComment}
|
||||
rejectComment={props.rejectComment}
|
||||
/>
|
||||
<BanUserDialog
|
||||
open={moderation.banDialog}
|
||||
@@ -106,6 +112,7 @@ const mapDispatchToProps = dispatch => ({
|
||||
|
||||
export default compose(
|
||||
connect(mapStateToProps, mapDispatchToProps),
|
||||
setCommentStatus,
|
||||
modQueueQuery,
|
||||
banUser
|
||||
)(ModerationContainer);
|
||||
|
||||
@@ -15,6 +15,8 @@ const ModerationQueue = props => {
|
||||
suspectWords={props.suspectWords}
|
||||
actions={actionsMap[comment.status]}
|
||||
showBanUserDialog={props.showBanUserDialog}
|
||||
acceptComment={props.acceptComment}
|
||||
rejectComment={props.rejectComment}
|
||||
{...comment}
|
||||
/>;
|
||||
})
|
||||
|
||||
@@ -13,7 +13,7 @@ const lang = new I18n(translations);
|
||||
import I18n from 'coral-framework/modules/i18n/i18n';
|
||||
import translations from 'coral-admin/src/translations.json';
|
||||
|
||||
const Comment = props => {
|
||||
const Comment = ({actions = [], ...props}) => {
|
||||
const links = linkify.getMatches(props.body);
|
||||
|
||||
return (
|
||||
@@ -30,8 +30,12 @@ const Comment = props => {
|
||||
<div className={styles.sideActions}>
|
||||
{links ? <span className={styles.hasLinks}><Icon name='error_outline'/> Contains Link</span> : null}
|
||||
<div className={`actions ${styles.actions}`}>
|
||||
{props.actions.map((action, i) =>
|
||||
<ActionButton type={action} user={props.user} key={i}
|
||||
{actions.map((action, i) =>
|
||||
<ActionButton key={i}
|
||||
type={action}
|
||||
user={props.user}
|
||||
acceptComment={() => props.acceptComment({commentId: props.id})}
|
||||
rejectComment={() => props.rejectComment({commentId: props.id})}
|
||||
showBanUserDialog={() => props.showBanUserDialog(props.user, props.id)}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// rejectComment
|
||||
import {graphql} from 'react-apollo';
|
||||
import SET_USER_STATUS from './setUserStatus.graphql';
|
||||
import SET_COMMENT_STATUS from './setCommentStatus.graphql';
|
||||
|
||||
export const banUser = graphql(SET_USER_STATUS, {
|
||||
props: ({mutate}) => ({
|
||||
@@ -14,3 +15,26 @@ export const banUser = graphql(SET_USER_STATUS, {
|
||||
});
|
||||
}}),
|
||||
});
|
||||
|
||||
export const setCommentStatus = graphql(SET_COMMENT_STATUS, {
|
||||
props: ({mutate}) => ({
|
||||
acceptComment: ({commentId}) => {
|
||||
return mutate({
|
||||
variables: {
|
||||
commentId,
|
||||
status: 'ACCEPTED'
|
||||
},
|
||||
refetchQueries: ['ModQueue']
|
||||
});
|
||||
},
|
||||
rejectComment: ({commentId}) => {
|
||||
return mutate({
|
||||
variables: {
|
||||
commentId,
|
||||
status: 'REJECTED'
|
||||
},
|
||||
refetchQueries: ['ModQueue']
|
||||
});
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
mutation setCommentStatus($commentId: ID!, $status: COMMENT_STATUS!){
|
||||
setCommentStatus(id: $commentId, status: $status)
|
||||
}
|
||||
@@ -2,8 +2,7 @@ import {graphql} from 'react-apollo';
|
||||
import MOD_QUEUE_QUERY from './modQueueQuery.graphql';
|
||||
|
||||
export const modQueueQuery = graphql(MOD_QUEUE_QUERY, {
|
||||
options: (props) => {
|
||||
const {id = ''} = props.params;
|
||||
options: ({params: {id = ''}}) => {
|
||||
return {
|
||||
variables: {
|
||||
asset_id: id
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
query ModQueue ($asset_id: ID!) {
|
||||
all: comments(query: {
|
||||
statuses: [ACCEPTED, REJECTED, PREMOD],
|
||||
statuses: [REJECTED, PREMOD],
|
||||
asset_id: $asset_id
|
||||
}) {
|
||||
...commentView
|
||||
|
||||
@@ -162,22 +162,36 @@ 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')) {
|
||||
if (context.user && context.user.can('mutation:createComment', 'mutation:setUserStatus')) {
|
||||
return {
|
||||
Comment: {
|
||||
create: (comment) => createPublicComment(context, comment)
|
||||
create: (comment) => createPublicComment(context, comment),
|
||||
setCommentStatus: (action) => setCommentStatus(context, action)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
Comment: {
|
||||
create: () => Promise.reject(errors.ErrNotAuthorized)
|
||||
create: () => Promise.reject(errors.ErrNotAuthorized),
|
||||
setCommentStatus: () => Promise.reject(errors.ErrNotAuthorized)
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -29,6 +29,9 @@ const RootMutation = {
|
||||
},
|
||||
setUserStatus(_, {id, status}, {mutators: {User}}) {
|
||||
return User.setUserStatus({id, status});
|
||||
},
|
||||
setCommentStatus(_, {id, status}, {mutators: {Comment}}) {
|
||||
return Comment.setCommentStatus({id, status});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -491,8 +491,11 @@ type RootMutation {
|
||||
# Delete an action based on the action id.
|
||||
deleteAction(id: ID!): DeleteActionResponse
|
||||
|
||||
# Sets user status
|
||||
# Sets User status
|
||||
setUserStatus(id: ID!, status: USER_STATUS!): Boolean
|
||||
|
||||
# Sets Comment status
|
||||
setCommentStatus(id: ID!, status: COMMENT_STATUS!): Boolean
|
||||
}
|
||||
|
||||
################################################################################
|
||||
|
||||
+2
-1
@@ -148,7 +148,8 @@ const USER_GRAPH_OPERATIONS = [
|
||||
'mutation:createAction',
|
||||
'mutation:deleteAction',
|
||||
'mutation:editName',
|
||||
'mutation:setUserStatus'
|
||||
'mutation:setUserStatus',
|
||||
'mutation:setCommentStatus'
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,6 +7,12 @@ const ALLOWED_TAGS = [
|
||||
{name: 'STAFF'}
|
||||
];
|
||||
|
||||
const STATUSES = [
|
||||
'ACCEPTED',
|
||||
'REJECTED',
|
||||
'PREMOD',
|
||||
];
|
||||
|
||||
module.exports = class CommentsService {
|
||||
|
||||
/**
|
||||
@@ -249,4 +255,25 @@ module.exports = class CommentsService {
|
||||
|
||||
return CommentModel.find(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets Comment Status
|
||||
* @param {String} id identifier of the comment (uuid)
|
||||
* @param {String} status the new status of the comment
|
||||
* @return {Promise}
|
||||
*/
|
||||
|
||||
static setStatus(id, status) {
|
||||
|
||||
// Check to see if the comment status is in the allowable set of statuses.
|
||||
if (STATUSES.indexOf(status) === -1) {
|
||||
|
||||
// Comment status is not supported! Error out here.
|
||||
return Promise.reject(new Error(`status ${status} is not supported`));
|
||||
}
|
||||
|
||||
return CommentModel.update({id}, {
|
||||
$set: {status}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user