diff --git a/src/components/profile/ProfileManageTab.tsx b/src/components/profile/ProfileManageTab.tsx index 82725501..0502481f 100644 --- a/src/components/profile/ProfileManageTab.tsx +++ b/src/components/profile/ProfileManageTab.tsx @@ -13,6 +13,7 @@ import type { PublicUser } from "../../../shared/user.ts"; import { expectOk } from "../../utils/shared/api.ts"; import { deserializePublicUser } from "../../utils/shared/deserialize.ts"; import { useAuth } from "../../hooks/auth/useAuth.ts"; +import { homeHost } from "../../utils/auth/home.ts"; import { ProfileSection } from "./ProfileSection.tsx"; import { RoleSwitcher } from "./RoleSwitcher.tsx"; import { SettingRow } from "./SettingRow.tsx"; @@ -30,7 +31,8 @@ export interface ProfileManageTabProps { /** * Renders the user's role and name. A rename here has no rate limit, and the - * profile's URL then takes the new name. + * profile's URL then takes the new name. A user from another instance is + * named there, so their name is only shown. */ export function ProfileManageTab( { user, onUserSaved }: ProfileManageTabProps, @@ -59,11 +61,15 @@ export function ProfileManageTab( onSaved={(role) => onUserSaved({ ...user, role })} /> Username}> - + {homeHost(user.username) + ? {user.username} + : ( + + )} diff --git a/src/test/pages/Settings.test.tsx b/src/test/pages/Settings.test.tsx index 126a884a..a4a0190b 100644 --- a/src/test/pages/Settings.test.tsx +++ b/src/test/pages/Settings.test.tsx @@ -7,6 +7,7 @@ import { calls, fail, route } from "../fetch.ts"; import { makeSession, makeToken } from "../fixtures.ts"; import { renderApp } from "../render.tsx"; import { AUTH_STORAGE_KEY } from "../../utils/auth/storage.ts"; +import { API_URL } from "../../config/api.ts"; const instance = vi.hoisted(() => ({ emailEnabled: false, @@ -217,9 +218,10 @@ describe("Settings", () => { const link = await screen.findByRole("link", { name: "Change it on home.example", }); + // Through the API, which redirects to the home's pages. expect(link).toHaveAttribute( "href", - `${location.protocol}//home.example/settings`, + `${API_URL}/api/users/@alice%40home.example/home?path=%2Fsettings`, ); expect(screen.queryByText("Other instances")).not.toBeInTheDocument(); expect(calls("GET /api/me/grants")).toHaveLength(0); diff --git a/src/test/pages/UserPublicProfile.test.tsx b/src/test/pages/UserPublicProfile.test.tsx index fc769827..146d939b 100644 --- a/src/test/pages/UserPublicProfile.test.tsx +++ b/src/test/pages/UserPublicProfile.test.tsx @@ -1,3 +1,4 @@ +import { API_URL } from "../../config/api.ts"; import { describe, expect, test, vi } from "vitest"; import { act, screen, waitFor, within } from "@testing-library/react"; import { userEvent } from "@testing-library/user-event"; @@ -65,9 +66,10 @@ describe("UserPublicProfile", () => { }); expect(await screen.findByRole("heading", { name: "alice@home.example" })) .toBeInTheDocument(); + // Through the API, which redirects to the home's pages. expect(screen.getByRole("link", { name: "home.example" })).toHaveAttribute( "href", - `${location.protocol}//home.example/@alice`, + `${API_URL}/api/users/@alice%40home.example/home`, ); expect(screen.queryByTitle("Change avatar")).not.toBeInTheDocument(); expect(screen.queryByTitle("Edit email")).not.toBeInTheDocument(); @@ -617,6 +619,20 @@ describe("UserPublicProfile", () => { ); }); + test("a user from another instance is named there, not here", async () => { + open({ + session: makeSession({ id: "admin", role: "admin" }), + user: { ...ann, username: "ann@home.example" }, + url: "/@ann@home.example/manage", + }); + expect( + await screen.findByText("ann@home.example", { + selector: ".profile-appearance-value", + }), + ).toBeInTheDocument(); + expect(screen.queryByRole("textbox", { name: "Username" })).toBeNull(); + }); + test("non-admins get no manage tab, nor its page", async () => { open({ session: makeSession({ id: "mod", role: "moderator" }),