Do not show "Forget room" button in Room View header for guest users (#10898)
* Do not show "Forget room" button in Room View header for guest users You can observe this problem by opening this in a new private tab: https://app.element.io/#/room/#matrix:matrix.org This is a public room with guest access enabled and Element will use a guest account to display it. Showing a "Forget room" button in the header for guest users is pointless. Clicking on it leads to a `M_GUEST_ACCESS_FORBIDDEN` error. Signed-off-by: Slavi Pantaleev <slavi@devture.com> * Iterate --------- Signed-off-by: Slavi Pantaleev <slavi@devture.com> Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
d268cc1b75
commit
4316ebae29
2 changed files with 34 additions and 1 deletions
|
@ -2449,6 +2449,10 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
|
||||||
viewingCall = true;
|
viewingCall = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const myMember = this.state.room!.getMember(this.context.client!.getSafeUserId());
|
||||||
|
const showForgetButton =
|
||||||
|
!this.context.client.isGuest() && (["leave", "ban"].includes(myMembership) || myMember?.isKicked());
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RoomContext.Provider value={this.state}>
|
<RoomContext.Provider value={this.state}>
|
||||||
<main className={mainClasses} ref={this.roomView} onKeyDown={this.onReactKeyDown}>
|
<main className={mainClasses} ref={this.roomView} onKeyDown={this.onReactKeyDown}>
|
||||||
|
@ -2463,7 +2467,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
|
||||||
inRoom={myMembership === "join"}
|
inRoom={myMembership === "join"}
|
||||||
onSearchClick={onSearchClick}
|
onSearchClick={onSearchClick}
|
||||||
onInviteClick={onInviteClick}
|
onInviteClick={onInviteClick}
|
||||||
onForgetClick={myMembership === "leave" ? onForgetClick : null}
|
onForgetClick={showForgetButton ? onForgetClick : null}
|
||||||
e2eStatus={this.state.e2eStatus}
|
e2eStatus={this.state.e2eStatus}
|
||||||
onAppsClick={this.state.hasPinnedWidgets ? onAppsClick : null}
|
onAppsClick={this.state.hasPinnedWidgets ? onAppsClick : null}
|
||||||
appsShown={this.state.showApps}
|
appsShown={this.state.showApps}
|
||||||
|
|
|
@ -515,4 +515,33 @@ describe("RoomView", () => {
|
||||||
await findByText("Are you sure you're at the right place?");
|
await findByText("Are you sure you're at the right place?");
|
||||||
expect(asFragment()).toMatchSnapshot();
|
expect(asFragment()).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("Peeking", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
// Make room peekable
|
||||||
|
room.currentState.setStateEvents([
|
||||||
|
new MatrixEvent({
|
||||||
|
type: "m.room.history_visibility",
|
||||||
|
state_key: "",
|
||||||
|
content: {
|
||||||
|
history_visibility: "world_readable",
|
||||||
|
},
|
||||||
|
room_id: room.roomId,
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should show forget room button for non-guests", async () => {
|
||||||
|
mocked(cli.isGuest).mockReturnValue(false);
|
||||||
|
await mountRoomView();
|
||||||
|
|
||||||
|
expect(screen.getByLabelText("Forget room")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should not show forget room button for guests", async () => {
|
||||||
|
mocked(cli.isGuest).mockReturnValue(true);
|
||||||
|
await mountRoomView();
|
||||||
|
expect(screen.queryByLabelText("Forget room")).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue