From a1de0a23befa477b2be8781415140a4bd9cd7768 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Mon, 24 May 2021 17:27:59 -0300 Subject: [PATCH 1/4] [IMPROVEMENT] Show only the option that user can manage in TeamChannelsView --- app/views/TeamChannelsView.js | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/app/views/TeamChannelsView.js b/app/views/TeamChannelsView.js index 03398edc90..ff11e8a272 100644 --- a/app/views/TeamChannelsView.js +++ b/app/views/TeamChannelsView.js @@ -52,6 +52,7 @@ class TeamChannelsView extends React.Component { StoreLastMessage: PropTypes.bool, addTeamChannelPermission: PropTypes.array, removeTeamChannelPermission: PropTypes.array, + editRoomPermission: PropTypes.array, showActionSheet: PropTypes.func, deleteRoom: PropTypes.func } @@ -291,31 +292,37 @@ class TeamChannelsView extends React.Component { } }, 1000, true); - options = (item) => { + options = (item, options) => { const { theme } = this.props; const isAutoJoinChecked = item.teamDefault; const autoJoinIcon = isAutoJoinChecked ? 'checkbox-checked' : 'checkbox-unchecked'; const autoJoinIconColor = isAutoJoinChecked ? themes[theme].tintActive : themes[theme].auxiliaryTintColor; - return ([ + const optionsToShow = [ { + name: 'Auto-join', title: I18n.t('Auto-join'), icon: item.t === 'p' ? 'channel-private' : 'channel-public', onPress: () => this.toggleAutoJoin(item), right: () => }, { + name: 'Remove_from_Team', title: I18n.t('Remove_from_Team'), icon: 'close', danger: true, onPress: () => this.remove(item) }, { + name: 'Delete', title: I18n.t('Delete'), icon: 'delete', danger: true, onPress: () => this.delete(item) } - ]); + ]; + + // options.has because "options" is an object type Set + return (optionsToShow.filter(opt => options.has(opt.name))); } toggleAutoJoin = async(item) => { @@ -391,13 +398,23 @@ class TeamChannelsView extends React.Component { showChannelActions = async(item) => { logEvent(events.ROOM_SHOW_BOX_ACTIONS); - const { showActionSheet, removeTeamChannelPermission } = this.props; + const { showActionSheet, removeTeamChannelPermission, editRoomPermission } = this.props; + + const options = new Set(); + const permissionsTeam = await RocketChat.hasPermission([removeTeamChannelPermission], this.team.rid); + if (permissionsTeam[0]) { + options.add('Auto-join'); + options.add('Remove_from_Team'); + } + const permissionsChannel = await RocketChat.hasPermission([editRoomPermission], item._id); + if (permissionsChannel[0]) { + options.add('Delete'); + } - const permissions = await RocketChat.hasPermission([removeTeamChannelPermission], this.team.rid); - if (!permissions[0]) { + if (options.size === 0) { return; } - showActionSheet({ options: this.options(item) }); + showActionSheet({ options: this.options(item, options) }); } renderItem = ({ item }) => { @@ -482,7 +499,8 @@ const mapStateToProps = state => ({ isMasterDetail: state.app.isMasterDetail, StoreLastMessage: state.settings.Store_Last_Message, addTeamChannelPermission: state.permissions['add-team-channel'], - removeTeamChannelPermission: state.permissions['remove-team-channel'] + removeTeamChannelPermission: state.permissions['remove-team-channel'], + editRoomPermission: state.permissions['edit-room'] }); const mapDispatchToProps = dispatch => ({ From a61b1c73ad6fae4625feebdc2d6275c78d8117e3 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Mon, 24 May 2021 19:41:31 -0300 Subject: [PATCH 2/4] Refactor the showActionSheet function --- app/views/TeamChannelsView.js | 92 +++++++++++++++++------------------ 1 file changed, 45 insertions(+), 47 deletions(-) diff --git a/app/views/TeamChannelsView.js b/app/views/TeamChannelsView.js index ff11e8a272..a79e7dba1b 100644 --- a/app/views/TeamChannelsView.js +++ b/app/views/TeamChannelsView.js @@ -32,6 +32,11 @@ import { CustomIcon } from '../lib/Icons'; import { themes } from '../constants/colors'; const API_FETCH_COUNT = 25; +const PERMISSION_DELETE_C = 'delete-c'; +const PERMISSION_DELETE_P = 'delete-p'; +const PERMISSION_EDIT_TEAM_CHANNEL = 'edit-team-channel'; +const PERMISSION_ADD_TEAM_CHANNEL = 'add-team-channel'; + const getItemLayout = (data, index) => ({ length: data.length, @@ -51,8 +56,9 @@ class TeamChannelsView extends React.Component { width: PropTypes.number, StoreLastMessage: PropTypes.bool, addTeamChannelPermission: PropTypes.array, - removeTeamChannelPermission: PropTypes.array, - editRoomPermission: PropTypes.array, + editTeamChannelPermission: PropTypes.array, + deleteCPermission: PropTypes.array, + deletePPermission: PropTypes.array, showActionSheet: PropTypes.func, deleteRoom: PropTypes.func } @@ -292,39 +298,6 @@ class TeamChannelsView extends React.Component { } }, 1000, true); - options = (item, options) => { - const { theme } = this.props; - const isAutoJoinChecked = item.teamDefault; - const autoJoinIcon = isAutoJoinChecked ? 'checkbox-checked' : 'checkbox-unchecked'; - const autoJoinIconColor = isAutoJoinChecked ? themes[theme].tintActive : themes[theme].auxiliaryTintColor; - const optionsToShow = [ - { - name: 'Auto-join', - title: I18n.t('Auto-join'), - icon: item.t === 'p' ? 'channel-private' : 'channel-public', - onPress: () => this.toggleAutoJoin(item), - right: () => - }, - { - name: 'Remove_from_Team', - title: I18n.t('Remove_from_Team'), - icon: 'close', - danger: true, - onPress: () => this.remove(item) - }, - { - name: 'Delete', - title: I18n.t('Delete'), - icon: 'delete', - danger: true, - onPress: () => this.delete(item) - } - ]; - - // options.has because "options" is an object type Set - return (optionsToShow.filter(opt => options.has(opt.name))); - } - toggleAutoJoin = async(item) => { try { const { data } = this.state; @@ -398,23 +371,47 @@ class TeamChannelsView extends React.Component { showChannelActions = async(item) => { logEvent(events.ROOM_SHOW_BOX_ACTIONS); - const { showActionSheet, removeTeamChannelPermission, editRoomPermission } = this.props; + const { + showActionSheet, editTeamChannelPermission, deleteCPermission, + deletePPermission, theme + } = this.props; + const isAutoJoinChecked = item.teamDefault; + const autoJoinIcon = isAutoJoinChecked ? 'checkbox-checked' : 'checkbox-unchecked'; + const autoJoinIconColor = isAutoJoinChecked ? themes[theme].tintActive : themes[theme].auxiliaryTintColor; - const options = new Set(); - const permissionsTeam = await RocketChat.hasPermission([removeTeamChannelPermission], this.team.rid); + const options = []; + const permissionsTeam = await RocketChat.hasPermission([editTeamChannelPermission], this.team.rid); if (permissionsTeam[0]) { - options.add('Auto-join'); - options.add('Remove_from_Team'); + options.push({ + name: 'Auto-join', + title: I18n.t('Auto-join'), + icon: item.t === 'p' ? 'channel-private' : 'channel-public', + onPress: () => this.toggleAutoJoin(item), + right: () => + }, + { + name: 'Remove_from_Team', + title: I18n.t('Remove_from_Team'), + icon: 'close', + danger: true, + onPress: () => this.remove(item) + }); } - const permissionsChannel = await RocketChat.hasPermission([editRoomPermission], item._id); + const permissionsChannel = await RocketChat.hasPermission([item.t === 'c' ? deleteCPermission : deletePPermission], item._id); if (permissionsChannel[0]) { - options.add('Delete'); + options.push({ + name: 'Delete', + title: I18n.t('Delete'), + icon: 'delete', + danger: true, + onPress: () => this.delete(item) + }); } - if (options.size === 0) { + if (options.length === 0) { return; } - showActionSheet({ options: this.options(item, options) }); + showActionSheet({ options }); } renderItem = ({ item }) => { @@ -498,9 +495,10 @@ const mapStateToProps = state => ({ useRealName: state.settings.UI_Use_Real_Name, isMasterDetail: state.app.isMasterDetail, StoreLastMessage: state.settings.Store_Last_Message, - addTeamChannelPermission: state.permissions['add-team-channel'], - removeTeamChannelPermission: state.permissions['remove-team-channel'], - editRoomPermission: state.permissions['edit-room'] + addTeamChannelPermission: state.permissions[PERMISSION_ADD_TEAM_CHANNEL], + editTeamChannelPermission: state.permissions[PERMISSION_EDIT_TEAM_CHANNEL], + deleteCPermission: state.permissions[PERMISSION_DELETE_C], + deletePPermission: state.permissions[PERMISSION_DELETE_P] }); const mapDispatchToProps = dispatch => ({ From 668f7cd562047153a970b9002f662503880363e1 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Tue, 25 May 2021 10:51:57 -0300 Subject: [PATCH 3/4] Added remove team channel permission --- app/views/TeamChannelsView.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/app/views/TeamChannelsView.js b/app/views/TeamChannelsView.js index a79e7dba1b..cbf436ec59 100644 --- a/app/views/TeamChannelsView.js +++ b/app/views/TeamChannelsView.js @@ -35,6 +35,7 @@ const API_FETCH_COUNT = 25; const PERMISSION_DELETE_C = 'delete-c'; const PERMISSION_DELETE_P = 'delete-p'; const PERMISSION_EDIT_TEAM_CHANNEL = 'edit-team-channel'; +const PERMISSION_REMOVE_TEAM_CHANNEL = 'remove-team-channel'; const PERMISSION_ADD_TEAM_CHANNEL = 'add-team-channel'; @@ -57,6 +58,7 @@ class TeamChannelsView extends React.Component { StoreLastMessage: PropTypes.bool, addTeamChannelPermission: PropTypes.array, editTeamChannelPermission: PropTypes.array, + removeTeamChannelPermission: PropTypes.array, deleteCPermission: PropTypes.array, deletePPermission: PropTypes.array, showActionSheet: PropTypes.func, @@ -372,14 +374,14 @@ class TeamChannelsView extends React.Component { showChannelActions = async(item) => { logEvent(events.ROOM_SHOW_BOX_ACTIONS); const { - showActionSheet, editTeamChannelPermission, deleteCPermission, - deletePPermission, theme + showActionSheet, editTeamChannelPermission, deleteCPermission, deletePPermission, theme, removeTeamChannelPermission } = this.props; const isAutoJoinChecked = item.teamDefault; const autoJoinIcon = isAutoJoinChecked ? 'checkbox-checked' : 'checkbox-unchecked'; const autoJoinIconColor = isAutoJoinChecked ? themes[theme].tintActive : themes[theme].auxiliaryTintColor; const options = []; + const permissionsTeam = await RocketChat.hasPermission([editTeamChannelPermission], this.team.rid); if (permissionsTeam[0]) { options.push({ @@ -388,8 +390,12 @@ class TeamChannelsView extends React.Component { icon: item.t === 'p' ? 'channel-private' : 'channel-public', onPress: () => this.toggleAutoJoin(item), right: () => - }, - { + }); + } + + const permissionsRemoveTeam = await RocketChat.hasPermission([removeTeamChannelPermission], this.team.rid); + if (permissionsRemoveTeam[0]) { + options.push({ name: 'Remove_from_Team', title: I18n.t('Remove_from_Team'), icon: 'close', @@ -397,6 +403,7 @@ class TeamChannelsView extends React.Component { onPress: () => this.remove(item) }); } + const permissionsChannel = await RocketChat.hasPermission([item.t === 'c' ? deleteCPermission : deletePPermission], item._id); if (permissionsChannel[0]) { options.push({ @@ -497,6 +504,7 @@ const mapStateToProps = state => ({ StoreLastMessage: state.settings.Store_Last_Message, addTeamChannelPermission: state.permissions[PERMISSION_ADD_TEAM_CHANNEL], editTeamChannelPermission: state.permissions[PERMISSION_EDIT_TEAM_CHANNEL], + removeTeamChannelPermission: state.permissions[PERMISSION_REMOVE_TEAM_CHANNEL], deleteCPermission: state.permissions[PERMISSION_DELETE_C], deletePPermission: state.permissions[PERMISSION_DELETE_P] }); From d0ceb7ab246af56f96ab35295849d485d54a3850 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Thu, 27 May 2021 15:05:33 -0300 Subject: [PATCH 4/4] Cleanup --- app/views/TeamChannelsView.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/views/TeamChannelsView.js b/app/views/TeamChannelsView.js index cbf436ec59..1d4b09246a 100644 --- a/app/views/TeamChannelsView.js +++ b/app/views/TeamChannelsView.js @@ -385,7 +385,6 @@ class TeamChannelsView extends React.Component { const permissionsTeam = await RocketChat.hasPermission([editTeamChannelPermission], this.team.rid); if (permissionsTeam[0]) { options.push({ - name: 'Auto-join', title: I18n.t('Auto-join'), icon: item.t === 'p' ? 'channel-private' : 'channel-public', onPress: () => this.toggleAutoJoin(item), @@ -396,7 +395,6 @@ class TeamChannelsView extends React.Component { const permissionsRemoveTeam = await RocketChat.hasPermission([removeTeamChannelPermission], this.team.rid); if (permissionsRemoveTeam[0]) { options.push({ - name: 'Remove_from_Team', title: I18n.t('Remove_from_Team'), icon: 'close', danger: true, @@ -407,7 +405,6 @@ class TeamChannelsView extends React.Component { const permissionsChannel = await RocketChat.hasPermission([item.t === 'c' ? deleteCPermission : deletePPermission], item._id); if (permissionsChannel[0]) { options.push({ - name: 'Delete', title: I18n.t('Delete'), icon: 'delete', danger: true,