Merge branch 'master' into client-targets

This commit is contained in:
Belén Curcio
2017-06-12 14:09:09 -03:00
committed by GitHub
9 changed files with 42 additions and 24 deletions
@@ -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 &&
<ActionButton>
<ReplyButton
onClick={() => setActiveReplyBox(comment.id)}
onClick={this.showReplyBox}
parentCommentId={parentId || comment.id}
currentUserId={currentUser && currentUser.id}
banned={false}
/>
</ActionButton>}
<Slot
@@ -223,6 +223,7 @@ class Stream extends React.Component {
activeReplyBox={this.props.activeReplyBox}
addNotification={addNotification}
depth={0}
disableReply={!open}
postComment={this.props.postComment}
asset={asset}
currentUser={user}
+5 -8
View File
@@ -208,18 +208,15 @@ export default (reaction) => (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
);
+6
View File
@@ -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`);
+7 -4
View File
@@ -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});
}
}
}
+2 -3
View File
@@ -6,21 +6,20 @@ import classnames from 'classnames';
const name = 'coral-plugin-replies';
const ReplyButton = ({banned, onClick}) => {
const ReplyButton = ({onClick}) => {
return (
<button
className={classnames(`${name}-reply-button`)}
onClick={onClick}>
{t('reply')}
<i className={`${name}-icon material-icons`}
aria-hidden={true}>{banned ? 'BANNED' : 'reply'}</i>
aria-hidden={true}>reply</i>
</button>
);
};
ReplyButton.propTypes = {
onClick: PropTypes.func.isRequired,
banned: PropTypes.bool.isRequired
};
export default ReplyButton;
+1
View File
@@ -1 +1,2 @@
export {t} from 'coral-framework/services/i18n';
export {can} from 'coral-framework/services/perms';
@@ -30,7 +30,6 @@ export const FakeComment = ({username, created_at, body}) => (
onClick={() => {}}
parentCommentId={'commentID'}
currentUserId={{}}
banned={false}
/>
</div>
<div className="commentActionsRight comment__action-container">
@@ -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;
}