From 99cf08ac38bdee25d07f27a3d9bb5d74199d106c Mon Sep 17 00:00:00 2001 From: Amit Yadav Date: Wed, 18 Jan 2017 18:38:31 +0530 Subject: Message Editing and Deleting permissions (#4692) --- webapp/components/rhs_root_post.jsx | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'webapp/components/rhs_root_post.jsx') diff --git a/webapp/components/rhs_root_post.jsx b/webapp/components/rhs_root_post.jsx index 235ed8db7..4d2c221df 100644 --- a/webapp/components/rhs_root_post.jsx +++ b/webapp/components/rhs_root_post.jsx @@ -11,7 +11,6 @@ import RhsDropdown from 'components/rhs_dropdown.jsx'; import ChannelStore from 'stores/channel_store.jsx'; import UserStore from 'stores/user_store.jsx'; -import TeamStore from 'stores/team_store.jsx'; import * as GlobalActions from 'actions/global_actions.jsx'; import {flagPost, unflagPost} from 'actions/post_actions.jsx'; @@ -20,6 +19,7 @@ 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 {FormattedMessage} from 'react-intl'; @@ -34,6 +34,10 @@ export default class RhsRootPost extends React.Component { this.flagPost = this.flagPost.bind(this); this.unflagPost = this.unflagPost.bind(this); + this.canEdit = false; + this.canDelete = false; + this.editDisableAction = new DelayedAction(this.handleEditDisable); + this.state = {}; } @@ -42,6 +46,10 @@ export default class RhsRootPost extends React.Component { GlobalActions.showGetPostLinkModal(this.props.post); } + handleEditDisable() { + this.canEdit = false; + } + shouldComponentUpdate(nextProps) { if (nextProps.status !== this.props.status) { return true; @@ -96,13 +104,13 @@ export default class RhsRootPost extends React.Component { const post = this.props.post; const user = this.props.user; const mattermostLogo = Constants.MATTERMOST_ICON_SVG; - 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); var timestamp = user ? user.last_picture_update : 0; var channel = ChannelStore.get(post.channel_id); const flagIcon = Constants.FLAG_ICON_SVG; + this.canDelete = PostUtils.canDeletePost(post); + this.canEdit = PostUtils.canEditPost(post, this.editDisableAction); + var type = 'Post'; if (post.root_id.length > 0) { type = 'Comment'; @@ -189,7 +197,7 @@ export default class RhsRootPost extends React.Component { ); - if (isOwner || isAdmin) { + if (this.canDelete) { dropdownContents.push(