Skip to content

Commit

Permalink
TCHAP: hide access settings on DM room
Browse files Browse the repository at this point in the history
  • Loading branch information
marc.sirisak committed Jan 13, 2025
1 parent ed8104c commit f5faeb0
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
5 changes: 2 additions & 3 deletions res/themes/tchap-common/css/_tchap_custom.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/components/structures/auth/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ export default class LoginComponent extends React.PureComponent<IProps, IState>
);
*/

if (TchapUIFeature.isSSOFlowActive()) {
if (TchapUIFeature.isSSOFlowActive() && !this.isBusy() && !this.state.busyLoggingIn) {
return <div style={{marginBottom: "25px", position: "relative", top: "-15px"}}>
<p style={{textAlign: "center", fontWeight: "bold"}}>{_t("auth|proconnect|or")}</p>
<ProconnectButton />
Expand Down
4 changes: 3 additions & 1 deletion src/tchap/components/views/rooms/TchapRoomLinkAccess.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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: "" }));
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f5faeb0

Please sign in to comment.