Remove user listing for guests (#13083)

closes #13075
This commit is contained in:
Tom Moor authored and GitHub committed 2026-07-21 18:46:57 -04:00
1 parent 6a09e9cf1d
commit fa2c498786
3 files changed
+9 -25

No files matched your search

+5 -1
View File
@@ -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
/>
+2 -24
View File
@@ -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 });
+2
View File
@@ -40,6 +40,8 @@ router.post(
ctx.input.body;
const actor = ctx.state.auth.user;
authorize(actor, "listUsers", actor.team);
let where: WhereOptions<User> = {
teamId: actor.teamId,
};