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

Regression: Regular users were not able to leave federated rooms #28148

Merged
merged 3 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
19 changes: 15 additions & 4 deletions apps/meteor/app/federation-v2/server/Federation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const allowedActionsInFederatedRooms: ValueOf<typeof RoomMemberActions>[] = [
RoomMemberActions.LEAVE,
];

const allowedActionsForModerators = allowedActionsInFederatedRooms.filter((action) => action !== RoomMemberActions.SET_AS_OWNER);

const allowedRoomSettingsChangesInFederatedRooms: ValueOf<typeof RoomSettingsEnum>[] = [RoomSettingsEnum.NAME, RoomSettingsEnum.TOPIC];

export class Federation {
Expand All @@ -33,10 +35,19 @@ export class Federation {
return true;
}

return Boolean(
(userSubscription.roles?.includes('owner') || userSubscription.roles?.includes('moderator')) &&
allowedActionsInFederatedRooms.includes(action),
);
if (action === RoomMemberActions.LEAVE) {
return true;
}

if (userSubscription.roles?.includes('owner')) {
return allowedActionsInFederatedRooms.includes(action);
}

if (userSubscription.roles?.includes('moderator')) {
return allowedActionsForModerators.includes(action);
}

return false;
}

public static isAFederatedUsername(username: string): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ describe('Federation[Server] - Federation', () => {
expect(Federation.actionAllowed({ t: 'c', federated: true } as any, RoomMemberActions.INVITE, 'userId')).to.be.true;
});

it('should return true if the action is equal to Leave (since any user can leave a channel)', () => {
findOneByRoomIdAndUserIdStub.returns({});
expect(Federation.actionAllowed({ t: 'c', federated: true } as any, RoomMemberActions.LEAVE, 'userId')).to.be.true;
});

const allowedActions = [
RoomMemberActions.REMOVE_USER,
RoomMemberActions.SET_AS_OWNER,
Expand All @@ -62,11 +67,23 @@ describe('Federation[Server] - Federation', () => {
findOneByRoomIdAndUserIdStub.returns({ roles: ['owner'] });
expect(Federation.actionAllowed({ t: 'c', federated: true } as any, action, 'userId')).to.be.true;
});
});

const allowedActionsForModerators = allowedActions.filter((action) => action !== RoomMemberActions.SET_AS_OWNER);
allowedActionsForModerators.forEach((action) => {
it('should return true if the action is allowed within the federation context for regular channels and the user is a room moderator', () => {
findOneByRoomIdAndUserIdStub.returns({ roles: ['moderator'] });
expect(Federation.actionAllowed({ t: 'c', federated: true } as any, action, 'userId')).to.be.true;
});
it('should return false if the action is allowed within the federation context for regular channels and the user is nor a moderator or owner', () => {
});
it('should return false if the action is equal to set owner and the user is a room moderator', () => {
findOneByRoomIdAndUserIdStub.returns({ roles: ['moderator'] });
expect(Federation.actionAllowed({ t: 'c', federated: true } as any, RoomMemberActions.SET_AS_OWNER, 'userId')).to.be.false;
});

const disallowedActionForRegularUsers = allowedActions.filter((action) => action !== RoomMemberActions.LEAVE);
disallowedActionForRegularUsers.forEach((action) => {
it('should return false if the for all other actions (excluding LEAVE) for regular users', () => {
findOneByRoomIdAndUserIdStub.returns({});
expect(Federation.actionAllowed({ t: 'c', federated: true } as any, action, 'userId')).to.be.false;
});
Expand Down