diff options
author | Amit Yadav <iit.amit@gmail.com> | 2017-01-18 18:38:31 +0530 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2017-01-18 08:08:31 -0500 |
commit | 99cf08ac38bdee25d07f27a3d9bb5d74199d106c (patch) | |
tree | e85ca087c2ec1b6bfe859d509b0f9e5c1a991630 /webapp/components/post_view | |
parent | 8f0175e15c4d6bd08ca6795851455468811c3dc9 (diff) | |
download | chat-99cf08ac38bdee25d07f27a3d9bb5d74199d106c.tar.gz chat-99cf08ac38bdee25d07f27a3d9bb5d74199d106c.tar.bz2 chat-99cf08ac38bdee25d07f27a3d9bb5d74199d106c.zip |
Message Editing and Deleting permissions (#4692)
Diffstat (limited to 'webapp/components/post_view')
-rw-r--r-- | webapp/components/post_view/components/post_info.jsx | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/webapp/components/post_view/components/post_info.jsx b/webapp/components/post_view/components/post_info.jsx index aa204add1..c4de46e8f 100644 --- a/webapp/components/post_view/components/post_info.jsx +++ b/webapp/components/post_view/components/post_info.jsx @@ -8,12 +8,10 @@ import PostTime from './post_time.jsx'; import * as GlobalActions from 'actions/global_actions.jsx'; import * as PostActions from 'actions/post_actions.jsx'; -import TeamStore from 'stores/team_store.jsx'; -import UserStore from 'stores/user_store.jsx'; - import * as Utils from 'utils/utils.jsx'; import * as PostUtils from 'utils/post_utils.jsx'; import Constants from 'utils/constants.jsx'; +import DelayedAction from 'utils/delayed_action.jsx'; import {Tooltip, OverlayTrigger} from 'react-bootstrap'; import React from 'react'; @@ -28,6 +26,10 @@ export default class PostInfo extends React.Component { this.removePost = this.removePost.bind(this); this.flagPost = this.flagPost.bind(this); this.unflagPost = this.unflagPost.bind(this); + + this.canEdit = false; + this.canDelete = false; + this.editDisableAction = new DelayedAction(this.handleEditDisable); } handleDropdownClick(e) { @@ -38,6 +40,10 @@ export default class PostInfo extends React.Component { } } + handleEditDisable() { + this.canEdit = false; + } + componentDidMount() { $('#post_dropdown' + this.props.post.id).on('shown.bs.dropdown', () => this.props.handleDropdownOpened(true)); $('#post_dropdown' + this.props.post.id).on('hidden.bs.dropdown', () => this.props.handleDropdownOpened(false)); @@ -45,9 +51,9 @@ export default class PostInfo extends React.Component { createDropdown() { var post = this.props.post; - var isOwner = this.props.currentUser.id === post.user_id; - var isAdmin = TeamStore.isTeamAdminForCurrentTeam() || UserStore.isSystemAdminForCurrentUser(); - const isSystemMessage = post.type && post.type.startsWith(Constants.SYSTEM_MESSAGE_PREFIX); + + this.canDelete = PostUtils.canDeletePost(post); + this.canEdit = PostUtils.canEditPost(post, this.editDisableAction); if (post.state === Constants.POST_FAILED || post.state === Constants.POST_LOADING) { return ''; @@ -139,7 +145,7 @@ export default class PostInfo extends React.Component { </li> ); - if (isOwner || isAdmin) { + if (this.canDelete) { dropdownContents.push( <li key='deletePost' @@ -162,12 +168,12 @@ export default class PostInfo extends React.Component { ); } - if (isOwner && !isSystemMessage) { + if (this.canEdit) { dropdownContents.push( <li key='editPost' role='presentation' - className='dropdown-submenu' + className={this.canEdit ? 'dropdown-submenu' : 'dropdown-submenu hide'} > <a href='#' |