From fa2c49878677eb51a144904532ef2c6f9c754cdb Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Tue, 21 Jul 2026 18:46:57 -0400 Subject: [PATCH] Remove user listing for guests (#13083) closes #13075 --- app/scenes/Search/components/UserFilter.tsx | 6 ++++- server/routes/api/users/users.test.ts | 26 ++------------------- server/routes/api/users/users.ts | 2 ++ 3 files changed, 9 insertions(+), 25 deletions(-) diff --git a/app/scenes/Search/components/UserFilter.tsx b/app/scenes/Search/components/UserFilter.tsx index e0df2d910a..d0667c7904 100644 --- a/app/scenes/Search/components/UserFilter.tsx +++ b/app/scenes/Search/components/UserFilter.tsx @@ -5,6 +5,8 @@ import { useTranslation } from "react-i18next"; import styled from "styled-components"; import { Avatar, AvatarSize } from "~/components/Avatar"; import FilterOptions from "~/components/FilterOptions"; +import useCurrentTeam from "~/hooks/useCurrentTeam"; +import usePolicy from "~/hooks/usePolicy"; import useStores from "~/hooks/useStores"; type Props = { @@ -20,6 +22,8 @@ function UserFilter(props: Props) { const { onSelect, userId } = props; const { t } = useTranslation(); const { users } = useStores(); + const team = useCurrentTeam(); + const can = usePolicy(team); const options = useMemo(() => { const userOptions = users.all.map((user) => ({ @@ -43,7 +47,7 @@ function UserFilter(props: Props) { selectedKeys={[userId]} onSelect={onSelect} defaultLabel={t("Any author")} - fetchQuery={users.fetchPage} + fetchQuery={can.listUsers ? users.fetchPage : undefined} fetchQueryOptions={fetchQueryOptions} showFilter /> diff --git a/server/routes/api/users/users.test.ts b/server/routes/api/users/users.test.ts index 3ecbeaa929..b1d269fecb 100644 --- a/server/routes/api/users/users.test.ts +++ b/server/routes/api/users/users.test.ts @@ -235,16 +235,12 @@ describe("#users.list", () => { expect(body2.data[0].id).toEqual(user.id); }); - it("should restrict guest from viewing other user's email", async () => { + it("should not allow guests to list users", async () => { const team = await buildTeam(); await buildUser({ teamId: team.id }); const guest = await buildUser({ teamId: team.id, role: UserRole.Guest }); const res = await server.post("/api/users.list", guest); - const body = await res.json(); - expect(res.status).toEqual(200); - expect(body.data).toHaveLength(2); - expect(body.data[0].email).toEqual(undefined); - expect(body.data[1].email).toEqual(guest.email); + expect(res.status).toEqual(403); }); it("should restrict viewer from viewing other user's email", async () => { @@ -271,24 +267,6 @@ describe("#users.list", () => { expect(body.data[1].email).toEqual(member.email); }); - it("should restrict guest from viewing other user's details", async () => { - const team = await buildTeam(); - await buildUser({ teamId: team.id }); - const guest = await buildUser({ teamId: team.id, role: UserRole.Guest }); - const res = await server.post("/api/users.list", guest); - const body = await res.json(); - expect(res.status).toEqual(200); - expect(body.data).toHaveLength(2); - expect(body.data[0].language).toEqual(undefined); - expect(body.data[0].preferences).toEqual(undefined); - expect(body.data[0].notificationSettings).toEqual(undefined); - expect(body.data[1].language).toEqual(guest.language); - expect(body.data[1].preferences).toEqual(guest.preferences); - expect(body.data[1].notificationSettings).toEqual( - guest.notificationSettings - ); - }); - it("should restrict viewer from viewing other user's details", async () => { const team = await buildTeam(); await buildUser({ teamId: team.id }); diff --git a/server/routes/api/users/users.ts b/server/routes/api/users/users.ts index 238dd050c9..1ea3489ceb 100644 --- a/server/routes/api/users/users.ts +++ b/server/routes/api/users/users.ts @@ -40,6 +40,8 @@ router.post( ctx.input.body; const actor = ctx.state.auth.user; + authorize(actor, "listUsers", actor.team); + let where: WhereOptions = { teamId: actor.teamId, };