fix: Invited users should not appear as option in @mention, closes #5006

This commit is contained in:
Tom Moor
2023-03-07 20:44:41 -05:00
parent d3b099819d
commit 58f2b9aa2b
3 changed files with 43 additions and 2 deletions

View File

@@ -34,7 +34,10 @@ function MentionMenu({ search, ...rest }: MentionMenuProps) {
const { t } = useTranslation();
const { users, auth } = useStores();
const { data, request } = useRequest(
React.useCallback(() => users.fetchPage({ query: search }), [users, search])
React.useCallback(
() => users.fetchPage({ query: search, filter: "active" }),
[users, search]
)
);
React.useEffect(() => {

View File

@@ -1,4 +1,9 @@
import { buildTeam, buildAdmin, buildUser } from "@server/test/factories";
import {
buildTeam,
buildAdmin,
buildUser,
buildInvite,
} from "@server/test/factories";
import { seed, getTestServer } from "@server/test/support";
const server = getTestServer();
@@ -70,6 +75,26 @@ describe("#users.list", () => {
expect(body.data.length).toEqual(0);
});
it("should allow filtering to active", async () => {
const user = await buildUser({
name: "Tester",
});
await buildInvite({
name: "Tester",
teamId: user.teamId,
});
const res = await server.post("/api/users.list", {
body: {
query: "test",
filter: "active",
token: user.getJwtToken(),
},
});
const body = await res.json();
expect(res.status).toEqual(200);
expect(body.data.length).toEqual(1);
});
it("should allow filtering to invited", async () => {
const user = await buildUser({
name: "Tester",

View File

@@ -101,6 +101,19 @@ router.post("users.list", auth(), pagination(), async (ctx: APIContext) => {
break;
}
case "active": {
where = {
...where,
lastActiveAt: {
[Op.ne]: null,
},
suspendedAt: {
[Op.is]: null,
},
};
break;
}
case "all": {
break;
}