Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMPROVE] Convert Team to Channel #3249

Merged
merged 20 commits into from
Jul 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
86e1f99
[IMPROVE] Add convert team to a channel
reinaldonetof Jul 1, 2021
9873a40
Action to SelectListView and new words to i18n
reinaldonetof Jul 1, 2021
5a0cda9
Implemented the post and it's working with selected channels or not
reinaldonetof Jul 2, 2021
236c906
Fixed the Convert Team Warning at english i18n and changed the functi…
reinaldonetof Jul 2, 2021
8d69978
E2E test completed in sequence the convert/move teams
reinaldonetof Jul 2, 2021
31be26b
[IMPROVE] Add convert team to a channel
reinaldonetof Jul 1, 2021
d82c681
Action to SelectListView and new words to i18n
reinaldonetof Jul 1, 2021
a230309
Implemented the post and it's working with selected channels or not
reinaldonetof Jul 2, 2021
b3d7e74
Fixed the Convert Team Warning at english i18n and changed the functi…
reinaldonetof Jul 2, 2021
cde48fd
rebase develop into this branch
reinaldonetof Jul 2, 2021
3ab9b52
rebase develop into improve.team-conver-to-channel
reinaldonetof Jul 2, 2021
e1dd1e2
[IMPROVE] Add convert team to a channel
reinaldonetof Jul 1, 2021
b073c06
Action to SelectListView and new words to i18n
reinaldonetof Jul 1, 2021
6fb98e7
Implemented the post and it's working with selected channels or not
reinaldonetof Jul 2, 2021
8726342
Fixed the Convert Team Warning at english i18n and changed the functi…
reinaldonetof Jul 2, 2021
c0ec2aa
rebase develop into this branch
reinaldonetof Jul 2, 2021
f2f18fb
Merge branch 'develop' into improve.team-convert-to-channel
reinaldonetof Jul 8, 2021
b353519
Merge branch 'improve.team-convert-to-channel' of https://github.com/…
reinaldonetof Jul 8, 2021
59204dc
Merge branch 'improve.team-convert-to-channel' of https://github.com/…
reinaldonetof Jul 8, 2021
4f83114
Merge branch 'develop' into improve.team-convert-to-channel
diegolmello Jul 9, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions app/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@
"member-does-not-exist": "Member does not exist",
"Convert": "Convert",
"Convert_to_Team": "Convert to Team",
"Convert_to_Team_Warning": "This can't be undone. Once you convert a channel to a team, you can not turn it back to a channel.",
"Convert_to_Team_Warning": "You are converting this Channel to a Team. All Members will be kept.",
"Move_to_Team": "Move to Team",
"Move_Channel_Paragraph": "Moving a channel inside a team means that this channel will be added in the team’s context, however, all channel’s members, which are not members of the respective team, will still have access to this channel, but will not be added as team’s members. \n\nAll channel’s management will still be made by the owners of this channel.\n\nTeam’s members and even team’s owners, if not a member of this channel, can not have access to the channel’s content. \n\nPlease notice that the Team’s owner will be able remove members from the Channel.",
"Move_to_Team_Warning": "After reading the previous intructions about this behavior, do you still want to move this channel to the selected team?",
Expand All @@ -765,5 +765,9 @@
"Load_Older": "Load Older",
"Left_The_Room_Successfully": "Left the room successfully",
"Deleted_The_Team_Successfully": "Team deleted successfully",
"Deleted_The_Room_Successfully": "Room deleted successfully"
"Deleted_The_Room_Successfully": "Room deleted successfully",
"Convert_to_Channel": "Convert to Channel",
"Converting_Team_To_Channel": "Converting Team to Channel",
"Select_Team_Channels_To_Delete": "Select the Team’s Channels you would like to delete, the ones you do not select will be moved to the Workspace. \n\nNotice that public Channels will be public and visible to everyone.",
"You_are_converting_the_team": "You are converting this Team to a Channel"
}
3 changes: 2 additions & 1 deletion app/i18n/locales/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -669,5 +669,6 @@
"invalid-room": "Sala inválida",
"Left_The_Room_Successfully": "Saiu da sala com sucesso",
"Deleted_The_Team_Successfully": "Time deletado com sucesso",
"Deleted_The_Room_Successfully": "Sala deletada com sucesso"
"Deleted_The_Room_Successfully": "Sala deletada com sucesso",
"Convert_to_Channel": "Converter para um Canal"
}
3 changes: 2 additions & 1 deletion app/lib/methods/getPermissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ const PERMISSIONS = [
'view-statistics',
'view-user-administration',
'view-all-teams',
'view-all-team-channels'
'view-all-team-channels',
'convert-team'
];

export async function setPermissions() {
Expand Down
7 changes: 7 additions & 0 deletions app/lib/rocketchat.js
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,13 @@ const RocketChat = {
};
return this.sdk.post(type === 'c' ? 'channels.convertToTeam' : 'groups.convertToTeam', params);
},
convertTeamToChannel({ teamId, selected }) {
const params = {
teamId,
...(selected.length && { roomsToRemove: selected })
};
return this.sdk.post('teams.convertToChannel', params);
},
joinRoom(roomId, joinCode, type) {
// TODO: join code
// RC 0.48.0
Expand Down
2 changes: 2 additions & 0 deletions app/utils/log/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ export default {
RA_LEAVE_TEAM_F: 'ra_leave_team_f',
RA_CONVERT_TO_TEAM: 'ra_convert_to_team',
RA_CONVERT_TO_TEAM_F: 'ra_convert_to_team_f',
RA_CONVERT_TEAM_TO_CHANNEL: 'ra_convert_team_to_channel',
RA_CONVERT_TEAM_TO_CHANNEL_F: 'ra_convert_team_to_channel_f',
RA_MOVE_TO_TEAM: 'ra_move_to_team',
RA_MOVE_TO_TEAM_F: 'ra_move_to_team_f',
RA_SEARCH_TEAM: 'ra_search_team',
Expand Down
103 changes: 99 additions & 4 deletions app/views/RoomActionsView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ class RoomActionsView extends React.Component {
viewBroadcastMemberListPermission: PropTypes.array,
transferLivechatGuestPermission: PropTypes.array,
createTeamPermission: PropTypes.array,
addTeamChannelPermission: PropTypes.array
addTeamChannelPermission: PropTypes.array,
convertTeamPermission: PropTypes.array
}

constructor(props) {
Expand All @@ -91,7 +92,8 @@ class RoomActionsView extends React.Component {
canEdit: false,
canToggleEncryption: false,
canCreateTeam: false,
canAddChannelToTeam: false
canAddChannelToTeam: false,
canConvertTeam: false
};
if (room && room.observe && room.rid) {
this.roomObservable = room.observe();
Expand Down Expand Up @@ -142,9 +144,10 @@ class RoomActionsView extends React.Component {
const canViewMembers = await this.canViewMembers();
const canCreateTeam = await this.canCreateTeam();
const canAddChannelToTeam = await this.canAddChannelToTeam();
const canConvertTeam = await this.canConvertTeam();

this.setState({
canAutoTranslate, canAddUser, canInviteUser, canEdit, canToggleEncryption, canViewMembers, canCreateTeam, canAddChannelToTeam
canAutoTranslate, canAddUser, canInviteUser, canEdit, canToggleEncryption, canViewMembers, canCreateTeam, canAddChannelToTeam, canConvertTeam
});

// livechat permissions
Expand Down Expand Up @@ -240,6 +243,16 @@ class RoomActionsView extends React.Component {
return canAddChannelToTeam;
}

canConvertTeam = async() => {
const { room } = this.state;
const { convertTeamPermission } = this.props;
const { rid } = room;
const permissions = await RocketChat.hasPermission([convertTeamPermission], rid);

const canConvertTeam = permissions[0];
return canConvertTeam;
}

canToggleEncryption = async() => {
const { room } = this.state;
const { toggleRoomE2EEncryptionPermission } = this.props;
Expand Down Expand Up @@ -433,6 +446,59 @@ class RoomActionsView extends React.Component {
});
}

convertTeamToChannel = async() => {
const { room } = this.state;
const { navigation } = this.props;

try {
const result = await RocketChat.teamListRoomsOfUser({ teamId: room.teamId, userId: room.u._id });

if (result.rooms?.length) {
const teamChannels = result.rooms.map(r => ({
rid: r._id,
name: r.name,
teamId: r.teamId
}));
navigation.navigate('SelectListView', {
title: 'Converting_Team_To_Channel',
data: teamChannels,
infoText: 'Select_Team_Channels_To_Delete',
nextAction: data => this.convertTeamToChannelConfirmation(data)
});
} else {
this.convertTeamToChannelConfirmation();
}
} catch (e) {
this.convertTeamToChannelConfirmation();
}
}

handleConvertTeamToChannel = async(selected) => {
logEvent(events.RA_CONVERT_TEAM_TO_CHANNEL);
try {
const { room } = this.state;
const { navigation } = this.props;

const result = await RocketChat.convertTeamToChannel({ teamId: room.teamId, selected });

if (result.success) {
navigation.navigate('RoomView');
}
} catch (e) {
logEvent(events.RA_CONVERT_TEAM_TO_CHANNEL_F);
log(e);
}
}

convertTeamToChannelConfirmation = (selected = []) => {
showConfirmationAlert({
title: I18n.t('Confirmation'),
message: I18n.t('You_are_converting_the_team'),
confirmationText: I18n.t('Convert'),
onPress: () => this.handleConvertTeamToChannel(selected)
});
}

leaveTeam = async() => {
const { room } = this.state;
const { navigation, leaveRoom } = this.props;
Expand Down Expand Up @@ -806,6 +872,32 @@ class RoomActionsView extends React.Component {
);
}

teamToChannelActions = (t, room) => {
const { canEdit, canConvertTeam } = this.state;
const canConvertTeamToChannel = canEdit && canConvertTeam && !!room?.teamMain;

return (
<>
{['c', 'p'].includes(t) && canConvertTeamToChannel
? (
<>
<List.Item
title='Convert_to_Channel'
onPress={() => this.onPressTouchable({
event: this.convertTeamToChannel
})}
testID='room-actions-convert-channel-to-team'
left={() => <List.Icon name='channel-public' />}
showActionIndicator
/>
<List.Separator />
</>
)
: null}
</>
);
}

render() {
const {
room, membersCount, canViewMembers, canAddUser, canInviteUser, joined, canAutoTranslate, canForwardGuest, canReturnQueue
Expand Down Expand Up @@ -1007,7 +1099,9 @@ class RoomActionsView extends React.Component {
)
: null}


{ this.teamChannelActions(t, room) }
{this.teamToChannelActions(t, room)}

{['l'].includes(t) && !this.isOmnichannelPreview
? (
Expand Down Expand Up @@ -1099,7 +1193,8 @@ const mapStateToProps = state => ({
viewBroadcastMemberListPermission: state.permissions['view-broadcast-member-list'],
transferLivechatGuestPermission: state.permissions['transfer-livechat-guest'],
createTeamPermission: state.permissions['create-team'],
addTeamChannelPermission: state.permissions['add-team-channel']
addTeamChannelPermission: state.permissions['add-team-channel'],
convertTeamPermission: state.permissions['convert-team']
});

const mapDispatchToProps = dispatch => ({
Expand Down
29 changes: 28 additions & 1 deletion e2e/tests/team/03-moveconvert.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('Move/Convert Team', () => {
await element(by.id('room-actions-scrollview')).scrollTo('bottom');
await waitFor(element(by.id('room-actions-convert-to-team'))).toExist().withTimeout(2000);
await element(by.id('room-actions-convert-to-team')).tap();
await waitFor(element(by.label('This can\'t be undone. Once you convert a channel to a team, you can not turn it back to a channel.'))).toExist().withTimeout(2000);
await waitFor(element(by.label('You are converting this Channel to a Team. All Members will be kept.'))).toExist().withTimeout(2000);
await element(by.text('Convert')).tap();
await waitFor(element(by.id('room-view'))).toExist().withTimeout(20000);
await waitFor(element(by.id(`room-view-title-${ toBeConverted }`))).toExist().withTimeout(6000);
Expand Down Expand Up @@ -84,5 +84,32 @@ describe('Move/Convert Team', () => {
await element(by.text('Yes, move it!')).tap();
await waitFor(element(by.id('room-view-header-team-channels'))).toExist().withTimeout(10000);
});

after(async() => {
await tapBack();
await waitFor(element(by.id('rooms-list-view'))).toExist().withTimeout(2000);
});
});

describe('Convert Team to Channel and Delete toBeMoved channel within the Converted', () => {
it('should convert a team to a channel', async() => {
await navigateToRoomActions(toBeConverted);
await element(by.id('room-actions-scrollview')).scrollTo('bottom');
await waitFor(element(by.id('room-actions-convert-channel-to-team'))).toExist().withTimeout(2000);
await element(by.id('room-actions-convert-channel-to-team')).tap();
await sleep(2000);
await waitFor(element(by.id('select-list-view'))).toExist().withTimeout(2000);
await waitFor(element(by.id(`select-list-view-item-${ toBeMoved }`))).toExist().withTimeout(2000);
await element(by.id(`select-list-view-item-${ toBeMoved }`)).tap();
await waitFor(element(by.id('select-list-view-submit'))).toExist().withTimeout(2000);
await element(by.id('select-list-view-submit')).tap();
await waitFor(element(by.label('You are converting this Team to a Channel'))).toExist().withTimeout(2000);
await element(by.text('Convert')).tap();
await waitFor(element(by.id('room-view'))).toExist().withTimeout(20000);
await waitFor(element(by.id(`room-view-title-${ toBeConverted }`))).toExist().withTimeout(6000);
await tapBack();
await waitFor(element(by.id('rooms-list-view'))).toExist().withTimeout(2000);
await waitFor(element(by.id(`rooms-list-view-item-${ toBeMoved }`))).toBeNotVisible().withTimeout(60000);
});
});
});