app/frontend/comments/comments.component.tsx in decidim-comments-0.17.2 vs app/frontend/comments/comments.component.tsx in decidim-comments-0.18.0

- old
+ new

@@ -35,11 +35,11 @@ comments: [] } }; public render() { - const { commentable: { comments, totalCommentsCount = 0 }, reorderComments, orderBy, loading } = this.props; + const { commentable: { comments, totalCommentsCount = 0, userAllowedToComment }, reorderComments, orderBy, loading } = this.props; let commentClasses = "comments"; let commentHeader = I18n.t("components.comments.title", { count: totalCommentsCount }); if (loading) { commentClasses += " loading-comments"; @@ -59,10 +59,11 @@ /> </div> {this._renderBlockedCommentsWarning()} {this._renderCommentThreads()} {this._renderAddCommentForm()} + {this._renderBlockedCommentsForUserWarning()} </section> </div> ); } @@ -70,13 +71,13 @@ * Renders a warning message if the commentable doesn't accept new comments. * @private * @returns {Void|DOMElement} - A warning message or nothing. */ private _renderBlockedCommentsWarning() { - const { commentable: { acceptsNewComments } } = this.props; + const { commentable: { acceptsNewComments, userAllowedToComment } } = this.props; - if (!acceptsNewComments) { + if (!acceptsNewComments && !userAllowedToComment) { return ( <div className="callout warning"> <p>{I18n.t("components.comments.blocked_comments_warning")}</p> </div> ); @@ -84,10 +85,32 @@ return null; } /** + * Renders a warning message if the participatory_space is private and users + * don't have permissions. + * @private + * @returns {Void|DOMElement} - A warning message or nothing. + */ + private _renderBlockedCommentsForUserWarning() { + const { commentable: { acceptsNewComments, userAllowedToComment } } = this.props; + + if (acceptsNewComments) { + if (!userAllowedToComment) { + return ( + <div className="callout warning"> + <p>{I18n.t("components.comments.blocked_comments_for_user_warning")}</p> + </div> + ); + } + } + + return null; + } + + /** * Iterates the comment's collection and render a CommentThread for each one * @private * @returns {ReactComponent[]} - A collection of CommentThread components */ private _renderCommentThreads() { @@ -111,12 +134,12 @@ * @private * @returns {Void|ReactComponent} - A AddCommentForm component or nothing */ private _renderAddCommentForm() { const { session, commentable, orderBy } = this.props; - const { acceptsNewComments, commentsHaveAlignment } = commentable; + const { acceptsNewComments, commentsHaveAlignment, userAllowedToComment } = commentable; - if (acceptsNewComments) { + if (acceptsNewComments && userAllowedToComment) { return ( <AddCommentForm session={session} commentable={commentable} arguable={commentsHaveAlignment}