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 52b5859
Show file tree
Hide file tree
Showing 4 changed files with 29 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);

Check failure on line 34 in src/tchap/components/views/rooms/TchapRoomLinkAccess.tsx

View workflow job for this annotation

GitHub Actions / Jest

TchapJoinRule › should render the tchap join rule with only private option

TypeError: Cannot read properties of undefined (reading 'getUserIdForRoomId') at initialLinkSharingValue (src/tchap/components/views/rooms/TchapRoomLinkAccess.tsx:34:40) at initialLinkSharingValue (src/tchap/components/views/rooms/TchapRoomLinkAccess.tsx:52:9) at commitHookEffectListMount (node_modules/react-dom/cjs/react-dom.development.js:23189:26) at commitPassiveMountOnFiber (node_modules/react-dom/cjs/react-dom.development.js:24970:11) at commitPassiveMountEffects_complete (node_modules/react-dom/cjs/react-dom.development.js:24930:9) at commitPassiveMountEffects_begin (node_modules/react-dom/cjs/react-dom.development.js:24917:7) at commitPassiveMountEffects (node_modules/react-dom/cjs/react-dom.development.js:24905:3) at flushPassiveEffectsImpl (node_modules/react-dom/cjs/react-dom.development.js:27078:3) at flushPassiveEffects (node_modules/react-dom/cjs/react-dom.development.js:27023:14) at node_modules/react-dom/cjs/react-dom.development.js:26808:9 at flushActQueue (node_modules/react/cjs/react.development.js:2667:24) at act (node_modules/react/cjs/react.development.js:2582:11) at node_modules/@testing-library/react/dist/act-compat.js:47:25 at renderRoot (node_modules/@testing-library/react/dist/pure.js:180:26) at render (node_modules/@testing-library/react/dist/pure.js:271:10) at customRender (test/test-utils/jest-matrix-react.tsx:29:18) at Object.<anonymous> (test/unit-tests/tchap/components/views/settings/TchapJoinRuleSettings-test.tsx:58:15)

Check failure on line 34 in src/tchap/components/views/rooms/TchapRoomLinkAccess.tsx

View workflow job for this annotation

GitHub Actions / Jest

TchapJoinRule › should render the tchap join rule with only private option with restricted access rules

TypeError: Cannot read properties of undefined (reading 'getUserIdForRoomId') at initialLinkSharingValue (src/tchap/components/views/rooms/TchapRoomLinkAccess.tsx:34:40) at initialLinkSharingValue (src/tchap/components/views/rooms/TchapRoomLinkAccess.tsx:52:9) at commitHookEffectListMount (node_modules/react-dom/cjs/react-dom.development.js:23189:26) at commitPassiveMountOnFiber (node_modules/react-dom/cjs/react-dom.development.js:24970:11) at commitPassiveMountEffects_complete (node_modules/react-dom/cjs/react-dom.development.js:24930:9) at commitPassiveMountEffects_begin (node_modules/react-dom/cjs/react-dom.development.js:24917:7) at commitPassiveMountEffects (node_modules/react-dom/cjs/react-dom.development.js:24905:3) at flushPassiveEffectsImpl (node_modules/react-dom/cjs/react-dom.development.js:27078:3) at flushPassiveEffects (node_modules/react-dom/cjs/react-dom.development.js:27023:14) at node_modules/react-dom/cjs/react-dom.development.js:26808:9 at flushActQueue (node_modules/react/cjs/react.development.js:2667:24) at act (node_modules/react/cjs/react.development.js:2582:11) at node_modules/@testing-library/react/dist/act-compat.js:47:25 at renderRoot (node_modules/@testing-library/react/dist/pure.js:180:26) at render (node_modules/@testing-library/react/dist/pure.js:271:10) at customRender (test/test-utils/jest-matrix-react.tsx:29:18) at Object.<anonymous> (test/unit-tests/tchap/components/views/settings/TchapJoinRuleSettings-test.tsx:87:15)
// 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,7 +41,7 @@ describe("TchapRoomLinkAccess", () => {
mockedMakeRoomPermalink.mockImplementation(() => mockedLinked);

client.createAlias = jest.fn().mockResolvedValue("alias");

DMRoomMap.makeShared(client);
jest.spyOn(client, "sendStateEvent").mockResolvedValue(Promise.resolve({ event_id: "" }));
jest.spyOn(client, "sendStateEvent").mockResolvedValue(Promise.resolve({ event_id: "" }));
});
Expand Down Expand Up @@ -104,6 +105,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

0 comments on commit 52b5859

Please sign in to comment.