From f5faeb08b6802fc77d24b5aedfff92facdac1f00 Mon Sep 17 00:00:00 2001 From: "marc.sirisak" Date: Thu, 9 Jan 2025 16:38:47 +0100 Subject: [PATCH] TCHAP: hide access settings on DM room --- .../tchap-common/css/_tchap_custom.pcss | 5 ++-- src/components/structures/auth/Login.tsx | 2 +- .../views/rooms/TchapRoomLinkAccess.tsx | 4 +++- .../views/rooms/TchapRoomLinkAccess-test.tsx | 24 +++++++++++++++++++ .../settings/TchapJoinRuleSettings-test.tsx | 6 ++++- 5 files changed, 35 insertions(+), 6 deletions(-) diff --git a/res/themes/tchap-common/css/_tchap_custom.pcss b/res/themes/tchap-common/css/_tchap_custom.pcss index bb1a8bcf43..5226e1bae9 100644 --- a/res/themes/tchap-common/css/_tchap_custom.pcss +++ b/res/themes/tchap-common/css/_tchap_custom.pcss @@ -64,9 +64,8 @@ } /* since we added a header in welcome pages, we need to add this margin for the footer */ -.mx_AuthPage_modal { - margin-bottom: 25px; - margin-top: 40px !important; +.mx_AuthFooter { + margin-top: 25px !important; } .mx_ThreadsActivityCentreButton .mx_ThreadsActivityCentreButton_Icon, diff --git a/src/components/structures/auth/Login.tsx b/src/components/structures/auth/Login.tsx index 2f0dbeec8d..32681375ec 100644 --- a/src/components/structures/auth/Login.tsx +++ b/src/components/structures/auth/Login.tsx @@ -515,7 +515,7 @@ export default class LoginComponent extends React.PureComponent ); */ - if (TchapUIFeature.isSSOFlowActive()) { + if (TchapUIFeature.isSSOFlowActive() && !this.isBusy() && !this.state.busyLoggingIn) { return

{_t("auth|proconnect|or")}

diff --git a/src/tchap/components/views/rooms/TchapRoomLinkAccess.tsx b/src/tchap/components/views/rooms/TchapRoomLinkAccess.tsx index 73105708fd..f2770c9ea2 100644 --- a/src/tchap/components/views/rooms/TchapRoomLinkAccess.tsx +++ b/src/tchap/components/views/rooms/TchapRoomLinkAccess.tsx @@ -15,6 +15,7 @@ import ErrorDialog from "~tchap-web/src/components/views/dialogs/ErrorDialog"; import MatrixToPermalinkConstructor from "~tchap-web/src/utils/permalinks/MatrixToPermalinkConstructor"; import ElementPermalinkConstructor from "~tchap-web/src/utils/permalinks/ElementPermalinkConstructor"; import SdkConfig from "~tchap-web/src/SdkConfig"; +import DMRoomMap from "~tchap-web/src/utils/DMRoomMap"; interface ITchapRoomLinkAccessProps { room: Room, @@ -30,8 +31,9 @@ export default function TchapRoomLinkAccess({room, onUpdateParentView}: ITchapRo // Getting the initial value of the link. We need to check if it was previsouly activated or not const initialLinkSharingValue = () => { + const isDm = DMRoomMap.shared().getUserIdForRoomId(room.roomId); // We disable link sharing if its a forum or user not admin - if (!TchapRoomUtils.isUserAdmin(room) || TchapRoomUtils.getTchapRoomType(room) === TchapRoomType.Forum) { + if (!TchapRoomUtils.isUserAdmin(room) || TchapRoomUtils.getTchapRoomType(room) === TchapRoomType.Forum || isDm) { setDisableLinkSharing(true); } diff --git a/test/unit-tests/tchap/components/views/rooms/TchapRoomLinkAccess-test.tsx b/test/unit-tests/tchap/components/views/rooms/TchapRoomLinkAccess-test.tsx index 95935d6d52..1236bc3768 100644 --- a/test/unit-tests/tchap/components/views/rooms/TchapRoomLinkAccess-test.tsx +++ b/test/unit-tests/tchap/components/views/rooms/TchapRoomLinkAccess-test.tsx @@ -12,6 +12,7 @@ import TchapRoomLinkAccess from "~tchap-web//src/tchap/components/views/rooms/Tc import { TchapRoomType } from "~tchap-web//src/tchap/@types/tchap"; import TchapRoomUtils from "~tchap-web/src/tchap/util/TchapRoomUtils"; import SdkConfig, { ConfigOptions } from "~tchap-web/src/SdkConfig"; +import DMRoomMap from "~tchap-web/src/utils/DMRoomMap"; jest.mock("~tchap-web/src/tchap/util/TchapRoomUtils"); jest.mock("~tchap-web//src/utils/permalinks/Permalinks"); @@ -40,6 +41,8 @@ describe("TchapRoomLinkAccess", () => { mockedMakeRoomPermalink.mockImplementation(() => mockedLinked); client.createAlias = jest.fn().mockResolvedValue("alias"); + DMRoomMap.makeShared(client); + jest.spyOn(DMRoomMap.shared(), "getUserIdForRoomId").mockReturnValue(null); jest.spyOn(client, "sendStateEvent").mockResolvedValue(Promise.resolve({ event_id: "" })); jest.spyOn(client, "sendStateEvent").mockResolvedValue(Promise.resolve({ event_id: "" })); @@ -104,6 +107,27 @@ describe("TchapRoomLinkAccess", () => { expect(switchLink).toHaveAttribute("aria-disabled", "true"); }); + it("should disable link if room is a DM", async () => { + mockedTchapRoomUtils.getRoomJoinRule.mockImplementation(() => JoinRule.Invite); + mockedTchapRoomUtils.isUserAdmin.mockImplementation(() => false); + + jest.spyOn(DMRoomMap.shared(), "getUserIdForRoomId").mockReturnValue("userB"); + + getComponent(); + + await flushPromises(); + + const switchLink = screen.queryByRole("switch"); + + const linkDisplay = screen.queryByText(mockedLinked); + + // linked should not appear because the share link is deactivated + expect(linkDisplay).toBe(null); + + // the user should not be able to click on the button + expect(switchLink).toHaveAttribute("aria-disabled", "true"); + }); + it("should activate link when clicking on the switch", async () => { mockedTchapRoomUtils.getRoomJoinRule.mockImplementation(() => JoinRule.Invite); diff --git a/test/unit-tests/tchap/components/views/settings/TchapJoinRuleSettings-test.tsx b/test/unit-tests/tchap/components/views/settings/TchapJoinRuleSettings-test.tsx index 3e57c7ab07..e2810613fc 100644 --- a/test/unit-tests/tchap/components/views/settings/TchapJoinRuleSettings-test.tsx +++ b/test/unit-tests/tchap/components/views/settings/TchapJoinRuleSettings-test.tsx @@ -11,6 +11,7 @@ import { mockStateEventImplementation, mkEvent, } from "~tchap-web/test/test-utils/test-utils"; +import DMRoomMap from "~tchap-web/src/utils/DMRoomMap"; function mkStubRoomWithInviteRule(roomId: string, name: string, client: MatrixClient, joinRule: JoinRule): Room { const stubRoom: Room = mkStubRoom(roomId, name, client); @@ -44,7 +45,10 @@ function mkStubRoomWithAccessRule( } describe("TchapJoinRule", () => { - beforeEach(() => {}); + beforeEach(() => { + DMRoomMap.makeShared(createTestClient()); + jest.spyOn(DMRoomMap.shared(), "getUserIdForRoomId").mockReturnValue(null); + }); it("should render the tchap join rule with only private option", () => { //build stub private room