Skip to content

Commit

Permalink
Replace add-team-channel permission by move-room-to-team
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusbsilva137 committed Jan 2, 2024
1 parent 1663520 commit ae22ef2
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion apps/meteor/app/api/server/v1/teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ API.v1.addRoute(
return API.v1.failure('team-does-not-exist');
}

if (!(await hasPermissionAsync(this.userId, 'add-team-channel', team.roomId))) {
if (!(await hasPermissionAsync(this.userId, 'move-room-to-team', team.roomId))) {
return API.v1.unauthorized('error-no-permission-team-channel');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export const permissions = [
{ _id: 'edit-team', roles: ['admin', 'owner'] },
{ _id: 'add-team-member', roles: ['admin', 'owner', 'moderator'] },
{ _id: 'edit-team-member', roles: ['admin', 'owner', 'moderator'] },
{ _id: 'add-team-channel', roles: ['admin', 'owner', 'moderator'] },
{ _id: 'move-room-to-team', roles: ['admin', 'owner', 'moderator'] },
{ _id: 'create-team-channel', roles: ['admin', 'owner', 'moderator'] },
{ _id: 'create-team-group', roles: ['admin', 'owner', 'moderator'] },
{ _id: 'delete-team-channel', roles: ['admin', 'owner', 'moderator'] },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const TeamsChannels = () => {
setText(event.currentTarget.value);
}, []);

const canAddExistingRoomToTeam = usePermission('add-team-channel', room._id);
const canAddExistingRoomToTeam = usePermission('move-room-to-team', room._id);
const canCreateRoomInTeam = useAtLeastOnePermission(['create-team-channel', 'create-team-group'], room._id);
const addExisting = useReactModal(AddExistingModal, teamId, reload);
const createNew = useReactModal(CreateChannelWithData, teamId, reload);
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,6 @@
"add-oauth-service_description": "Permission to add a new OAuth service",
"bypass-time-limit-edit-and-delete": "Bypass time limit",
"bypass-time-limit-edit-and-delete_description": "Permission to Bypass time limit for editing and deleting messages",
"add-team-channel": "Move room within team",
"add-team-channel_description": "Permission to add an existing room to a team",
"create-team-channel": "Create channel within team",
"create-team-channel_description": "Permission to create a channel in a team (Overrides global permission)",
"create-team-group": "Create group within team",
Expand Down Expand Up @@ -3642,6 +3640,8 @@
"Move_beginning_message": "`%s` - Move to the beginning of the message",
"Move_end_message": "`%s` - Move to the end of the message",
"Move_queue": "Move to the queue",
"move-room-to-team": "Move room within team",
"move-room-to-team_description": "Permission to add an existing room to a team",
"Msgs": "Msgs",
"multi": "multi",
"Multi_line": "Multi line",
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/packages/rocketchat-i18n/i18n/pt-BR.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,6 @@
"add-livechat-department-agents_description": "Permissão para incluir agentes omnichannel aos departamentos",
"add-oauth-service": "Adicionar Serviço OAuth",
"add-oauth-service_description": "Permissão para adicionar um novo serviço OAuth",
"add-team-channel": "Mover sala a um time",
"add-team-channel_description": "Permissão para adicionar uma sala existente a um time",
"create-team-channel": "Criar canal em um time",
"create-team-channel_description": "Permissão para criar um canal em um time (sobrepõe a permissão global)",
"create-team-group": "Criar grupo em um time",
Expand Down Expand Up @@ -3040,6 +3038,8 @@
"Move_beginning_message": "`%s` - Mover para o início da mensagem",
"Move_end_message": "`%s` - Mover para o final da mensagem",
"Move_queue": "Mover para a fila",
"move-room-to-team": "Mover sala a um time",
"move-room-to-team_description": "Permissão para adicionar uma sala existente a um time",
"Msgs": "Msgs",
"multi": "multi",
"Mute": "Silenciar",
Expand Down
6 changes: 4 additions & 2 deletions apps/meteor/server/startup/migrations/v305.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { addMigration } from '../../lib/migrations';

addMigration({
version: 305,
name: 'Copy roles from add-team-channel permission to new create-team-channel and create-team-group permissions',
name: 'Copy roles from add-team-channel permission to new create-team-channel, create-team-group and move-room-to-team permissions',
async up() {
// Calling upsertPermissions on purpose so that the new permissions are added before the migration runs
await upsertPermissions();
Expand All @@ -17,9 +17,11 @@ addMigration({

if (addTeamChannelPermission) {
await Permissions.updateMany(
{ _id: { $in: ['create-team-channel', 'create-team-group'] } },
{ _id: { $in: ['create-team-channel', 'create-team-group', 'move-room-to-team'] } },
{ $set: { roles: addTeamChannelPermission.roles } },
);

await Permissions.deleteOne({ _id: 'add-team-channel' });
}
},
});
10 changes: 5 additions & 5 deletions apps/meteor/tests/end-to-end/api/25-teams.js
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,7 @@ describe('[Teams]', () => {
});

it('should throw an error if no permission', (done) => {
updatePermission('add-team-channel', []).then(() => {
updatePermission('move-room-to-team', []).then(() => {
request
.post(api('teams.addRooms'))
.set(credentials)
Expand All @@ -1241,7 +1241,7 @@ describe('[Teams]', () => {
});

it('should add public and private rooms to team', (done) => {
updatePermission('add-team-channel', ['admin']).then(() => {
updatePermission('move-room-to-team', ['admin']).then(() => {
request
.post(api('teams.addRooms'))
.set(credentials)
Expand Down Expand Up @@ -1270,7 +1270,7 @@ describe('[Teams]', () => {
});

it('should add public room to private team', (done) => {
updatePermission('add-team-channel', ['admin']).then(() => {
updatePermission('move-room-to-team', ['admin']).then(() => {
request
.post(api('teams.addRooms'))
.set(credentials)
Expand All @@ -1291,7 +1291,7 @@ describe('[Teams]', () => {
});

it('should add private room to team', (done) => {
updatePermission('add-team-channel', ['admin']).then(() => {
updatePermission('move-room-to-team', ['admin']).then(() => {
request
.post(api('teams.addRooms'))
.set(credentials)
Expand All @@ -1312,7 +1312,7 @@ describe('[Teams]', () => {
});

it('should fail if the user cannot access the channel', (done) => {
updatePermission('add-team-channel', ['admin', 'user'])
updatePermission('move-room-to-team', ['admin', 'user'])
.then(() => {
request
.post(api('teams.addRooms'))
Expand Down

0 comments on commit ae22ef2

Please sign in to comment.