diff --git a/client/coral-embed-stream/src/components/Comment.js b/client/coral-embed-stream/src/components/Comment.js
index 4233325c5..92c59d936 100644
--- a/client/coral-embed-stream/src/components/Comment.js
+++ b/client/coral-embed-stream/src/components/Comment.js
@@ -7,6 +7,7 @@ import Content from 'coral-plugin-commentcontent/CommentContent';
import PubDate from 'coral-plugin-pubdate/PubDate';
import {ReplyBox, ReplyButton} from 'coral-plugin-replies';
import FlagComment from 'coral-plugin-flags/FlagComment';
+import {can} from 'coral-framework/services/perms';
import {TransitionGroup} from 'react-transition-group';
import cn from 'classnames';
@@ -219,6 +220,18 @@ export default class Comment extends React.Component {
this.setState(resetCursors);
};
+ showReplyBox = () => {
+ if (!this.props.currentUser) {
+ this.props.showSignInDialog();
+ return;
+ }
+ if (can(this.props.currentUser, 'INTERACT_WITH_COMMUNITY')) {
+ this.props.setActiveReplyBox(this.props.comment.id);
+ return;
+ }
+ return;
+ }
+
// getVisibileReplies returns a list containing comments
// which were authored by current user or comes before the `idCursor`.
getVisibileReplies() {
@@ -479,10 +492,9 @@ export default class Comment extends React.Component {
{!disableReply &&
setActiveReplyBox(comment.id)}
+ onClick={this.showReplyBox}
parentCommentId={parentId || comment.id}
currentUserId={currentUser && currentUser.id}
- banned={false}
/>
}
(WrappedComponent) => {
}
);
+ const mapStateToProps = (state) => ({
+ user: state.auth.toJS().user,
+ });
+
const mapDispatchToProps = (dispatch) =>
bindActionCreators({showSignInDialog}, dispatch);
const enhance = compose(
withFragments({
- root: gql`
- fragment ${capitalize(reaction)}Button_root on RootQuery {
- me {
- status
- }
- }
- `,
comment: gql`
fragment ${capitalize(reaction)}Button_comment on Comment {
action_summaries {
@@ -232,7 +229,7 @@ export default (reaction) => (WrappedComponent) => {
}
}`
}),
- connect(null, mapDispatchToProps),
+ connect(mapStateToProps, mapDispatchToProps),
withDeleteReaction,
withPostReaction
);
diff --git a/client/coral-framework/services/perms.js b/client/coral-framework/services/perms.js
index e93744506..825c978ca 100644
--- a/client/coral-framework/services/perms.js
+++ b/client/coral-framework/services/perms.js
@@ -23,7 +23,13 @@ export const can = (user, ...perms) => {
return false;
}
+ const banned = user.status === 'BANNED';
+ const suspended = user.suspension.until && new Date(user.suspension.until) > new Date();
+
return perms.every((perm) => {
+ if (perm === 'INTERACT_WITH_COMMUNITY') {
+ return !banned && !suspended;
+ }
const role = roles[perm];
if (typeof role === 'undefined') {
throw new Error(`${perm} is not a valid role`);
diff --git a/client/coral-plugin-flags/FlagButton.js b/client/coral-plugin-flags/FlagButton.js
index 9a772f102..73ed50e9c 100644
--- a/client/coral-plugin-flags/FlagButton.js
+++ b/client/coral-plugin-flags/FlagButton.js
@@ -1,6 +1,7 @@
import React, {Component} from 'react';
import t from 'coral-framework/services/i18n';
+import {can} from 'coral-framework/services/perms';
import {PopupMenu, Button} from 'coral-ui';
import onClickOutside from 'react-onclickoutside';
@@ -32,10 +33,12 @@ class FlagButton extends Component {
this.props.showSignInDialog();
return;
}
- if (this.state.showMenu) {
- this.closeMenu();
- } else {
- this.setState({showMenu: true});
+ if (can(currentUser, 'INTERACT_WITH_COMMUNITY')) {
+ if (this.state.showMenu) {
+ this.closeMenu();
+ } else {
+ this.setState({showMenu: true});
+ }
}
}
diff --git a/client/coral-plugin-replies/ReplyButton.js b/client/coral-plugin-replies/ReplyButton.js
index 6fb6a5aca..a66e3c156 100644
--- a/client/coral-plugin-replies/ReplyButton.js
+++ b/client/coral-plugin-replies/ReplyButton.js
@@ -6,21 +6,20 @@ import classnames from 'classnames';
const name = 'coral-plugin-replies';
-const ReplyButton = ({banned, onClick}) => {
+const ReplyButton = ({onClick}) => {
return (
);
};
ReplyButton.propTypes = {
onClick: PropTypes.func.isRequired,
- banned: PropTypes.bool.isRequired
};
export default ReplyButton;
diff --git a/plugin-api/beta/client/services/index.js b/plugin-api/beta/client/services/index.js
index 16872b9f3..509d4f55c 100644
--- a/plugin-api/beta/client/services/index.js
+++ b/plugin-api/beta/client/services/index.js
@@ -1 +1,2 @@
export {t} from 'coral-framework/services/i18n';
+export {can} from 'coral-framework/services/perms';
diff --git a/plugins/coral-plugin-auth/client/components/FakeComment.js b/plugins/coral-plugin-auth/client/components/FakeComment.js
index 9900ccdc6..390dd409b 100644
--- a/plugins/coral-plugin-auth/client/components/FakeComment.js
+++ b/plugins/coral-plugin-auth/client/components/FakeComment.js
@@ -30,7 +30,6 @@ export const FakeComment = ({username, created_at, body}) => (
onClick={() => {}}
parentCommentId={'commentID'}
currentUserId={{}}
- banned={false}
/>
diff --git a/plugins/coral-plugin-love/client/LoveButton.js b/plugins/coral-plugin-love/client/LoveButton.js
index 4e9b56d44..de4c4c9e7 100644
--- a/plugins/coral-plugin-love/client/LoveButton.js
+++ b/plugins/coral-plugin-love/client/LoveButton.js
@@ -1,8 +1,8 @@
import React from 'react';
import {Icon} from 'coral-ui';
import styles from './styles.css';
-import t from 'coral-framework/services/i18n';
import {withReaction} from 'plugin-api/beta/client/hocs';
+import {t, can} from 'plugin-api/beta/client/services';
class LoveButton extends React.Component {
handleClick = () => {
@@ -10,18 +10,18 @@ class LoveButton extends React.Component {
postReaction,
deleteReaction,
showSignInDialog,
- alreadyReacted
+ alreadyReacted,
+ user,
} = this.props;
- const {root: {me}} = this.props;
// If the current user does not exist, trigger sign in dialog.
- if (!me) {
+ if (!user) {
showSignInDialog();
return;
}
- // If the current user is banned, do nothing.
- if (me.status === 'BANNED') {
+ // If the current user is suspended, do nothing.
+ if (!can(user, 'INTERACT_WITH_COMMUNITY')) {
return;
}