diff --git a/app/components/channel_drawer/channels_list/list/index.js b/app/components/channel_drawer/channels_list/list/index.js index 989f2046a..ca719a2a5 100644 --- a/app/components/channel_drawer/channels_list/list/index.js +++ b/app/components/channel_drawer/channels_list/list/index.js @@ -12,6 +12,7 @@ import { getSortedDirectChannelIds, } from 'mattermost-redux/selectors/entities/channels'; import {getCurrentUserId, getCurrentUserRoles} from 'mattermost-redux/selectors/entities/users'; +import {getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams'; import {getTheme, getFavoritesPreferences} from 'mattermost-redux/selectors/entities/preferences'; import {showCreateOption} from 'mattermost-redux/utils/channel_utils'; import {isAdmin, isSystemAdmin} from 'mattermost-redux/utils/user_utils'; @@ -26,9 +27,10 @@ function mapStateToProps(state) { const publicChannelIds = getSortedPublicChannelIds(state); const privateChannelIds = getSortedPrivateChannelIds(state); const directChannelIds = getSortedDirectChannelIds(state); + const currentTeamId = getCurrentTeamId(state); return { - canCreatePrivateChannels: showCreateOption(state, config, license, General.PRIVATE_CHANNEL, isAdmin(roles), isSystemAdmin(roles)), + canCreatePrivateChannels: showCreateOption(state, config, license, currentTeamId, General.PRIVATE_CHANNEL, isAdmin(roles), isSystemAdmin(roles)), unreadChannelIds, favoriteChannelIds, publicChannelIds, diff --git a/app/components/post/index.js b/app/components/post/index.js index 5722c1f53..6ec909aeb 100644 --- a/app/components/post/index.js +++ b/app/components/post/index.js @@ -8,8 +8,10 @@ import {createPost, deletePost, removePost} from 'mattermost-redux/actions/posts import {getPost} from 'mattermost-redux/selectors/entities/posts'; import {getCurrentUserId, getCurrentUserRoles} from 'mattermost-redux/selectors/entities/users'; import {getMyPreferences, getTheme} from 'mattermost-redux/selectors/entities/preferences'; -import {getCurrentTeamUrl} from 'mattermost-redux/selectors/entities/teams'; -import {isPostFlagged} from 'mattermost-redux/utils/post_utils'; +import {getCurrentTeamUrl, getCurrentTeamId} from 'mattermost-redux/selectors/entities/teams'; +import {getCurrentChannelId} from 'mattermost-redux/selectors/entities/channels'; +import {canDeletePost, canEditPost, isPostFlagged} from 'mattermost-redux/utils/post_utils'; +import {isAdmin, isSystemAdmin} from 'mattermost-redux/utils/user_utils'; import {insertToDraft, setPostTooltipVisible} from 'app/actions/views/channel'; import {addReaction} from 'app/actions/views/emoji'; @@ -23,6 +25,9 @@ function mapStateToProps(state, ownProps) { const {config, license} = state.entities.general; const roles = getCurrentUserId(state) ? getCurrentUserRoles(state) : ''; const myPreferences = getMyPreferences(state); + const currentUserId = getCurrentUserId(state); + const currentTeamId = getCurrentTeamId(state); + const currentChannelId = getCurrentChannelId(state); let isFirstReply = true; let isLastReply = true; @@ -51,17 +56,25 @@ function mapStateToProps(state, ownProps) { const {deviceWidth} = getDimensions(state); + let canDelete = false; + let canEdit = false; + if (post) { + canDelete = canDeletePost(state, config, license, currentTeamId, currentChannelId, currentUserId, post, isAdmin(roles), isSystemAdmin(roles)); + canEdit = canEditPost(state, config, license, currentTeamId, currentChannelId, currentUserId, post); + } + return { config, + canDelete, + canEdit, currentTeamUrl: getCurrentTeamUrl(state), - currentUserId: getCurrentUserId(state), + currentUserId, deviceWidth, post, isFirstReply, isLastReply, commentedOnPost, license, - roles, theme: getTheme(state), isFlagged: isPostFlagged(post.id, myPreferences), }; diff --git a/app/components/post/post.js b/app/components/post/post.js index 5123e445f..16fddc5a7 100644 --- a/app/components/post/post.js +++ b/app/components/post/post.js @@ -26,8 +26,7 @@ import {getToolTipVisible} from 'app/utils/tooltip'; import {Posts} from 'mattermost-redux/constants'; import DelayedAction from 'mattermost-redux/utils/delayed_action'; import EventEmitter from 'mattermost-redux/utils/event_emitter'; -import {canDeletePost, canEditPost, isPostEphemeral, isPostPendingOrFailed, isSystemMessage} from 'mattermost-redux/utils/post_utils'; -import {isAdmin, isSystemAdmin} from 'mattermost-redux/utils/user_utils'; +import {editDisable, isPostEphemeral, isPostPendingOrFailed, isSystemMessage} from 'mattermost-redux/utils/post_utils'; import Config from 'assets/config'; @@ -56,8 +55,9 @@ export default class Post extends PureComponent { license: PropTypes.object.isRequired, managedConfig: PropTypes.object.isRequired, navigator: PropTypes.object, + canEdit: PropTypes.bool.isRequired, + canDelete: PropTypes.bool.isRequired, onPermalinkPress: PropTypes.func, - roles: PropTypes.string, shouldRenderReplyButton: PropTypes.bool, showFullDate: PropTypes.bool, showLongPost: PropTypes.bool, @@ -79,32 +79,26 @@ export default class Post extends PureComponent { constructor(props) { super(props); - const {config, license, currentUserId, roles, post} = props; + const {config, license, currentUserId, post} = props; this.editDisableAction = new DelayedAction(this.handleEditDisable); if (post) { - this.state = { - canEdit: canEditPost(config, license, currentUserId, post, this.editDisableAction), - canDelete: canDeletePost(config, license, currentUserId, post, isAdmin(roles), isSystemAdmin(roles)), - }; - } else { - this.state = { - canEdit: false, - canDelete: false, - }; + editDisable(config, license, currentUserId, post, this.editDisableAction); } + this.state = { + canEdit: this.props.canEdit, + }; } componentWillReceiveProps(nextProps) { if (nextProps.config !== this.props.config || nextProps.license !== this.props.license || nextProps.currentUserId !== this.props.currentUserId || - nextProps.post !== this.props.post || - nextProps.roles !== this.props.roles) { - const {config, license, currentUserId, roles, post} = nextProps; + nextProps.post !== this.props.post) { + const {config, license, currentUserId, post} = nextProps; + editDisable(config, license, currentUserId, post, this.editDisableAction); this.setState({ - canEdit: canEditPost(config, license, currentUserId, post, this.editDisableAction), - canDelete: canDeletePost(config, license, currentUserId, post, isAdmin(roles), isSystemAdmin(roles)), + canEdit: nextProps.canEdit, }); } } @@ -446,7 +440,7 @@ export default class Post extends PureComponent { { const {actions, postId} = this.props; - if (remove) { + if (remove && this.props.canRemoveReaction) { actions.removeReaction(postId, emoji); - } else { + } else if (!remove && this.props.canAddReaction) { actions.addReaction(postId, emoji); } }; diff --git a/app/screens/channel_info/index.js b/app/screens/channel_info/index.js index ccddf1afe..db0432c7d 100644 --- a/app/screens/channel_info/index.js +++ b/app/screens/channel_info/index.js @@ -57,8 +57,8 @@ function mapStateToProps(state) { } return { - canDeleteChannel: showDeleteOption(config, license, currentChannel, isAdmin(roles), isSystemAdmin(roles), isChannelAdmin(roles)), - canEditChannel: showManagementOptions(config, license, currentChannel, isAdmin(roles), isSystemAdmin(roles), isChannelAdmin(roles)), + canDeleteChannel: showDeleteOption(state, config, license, currentChannel, isAdmin(roles), isSystemAdmin(roles), isChannelAdmin(roles)), + canEditChannel: showManagementOptions(state, config, license, currentChannel, isAdmin(roles), isSystemAdmin(roles), isChannelAdmin(roles)), currentChannel, currentChannelCreatorName, currentChannelMemberCount, diff --git a/app/screens/more_channels/index.js b/app/screens/more_channels/index.js index 27b6d45c0..d0ecb2b63 100644 --- a/app/screens/more_channels/index.js +++ b/app/screens/more_channels/index.js @@ -36,7 +36,7 @@ function mapStateToProps(state) { const channels = joinableChannels(state); return { - canCreateChannels: showCreateOption(config, license, General.OPEN_CHANNEL, isAdmin(roles), isSystemAdmin(roles)), + canCreateChannels: showCreateOption(state, config, license, currentTeamId, General.OPEN_CHANNEL, isAdmin(roles), isSystemAdmin(roles)), currentUserId, currentTeamId, channels,