fix: Mentions do not show any options in public collections (#5150)
* Mentions do not show any options in public collections * Avoid reset data while loading
This commit is contained in:
@@ -42,7 +42,7 @@ function MentionMenu({ search, isActive, ...rest }: Props) {
|
|||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const documentId = parseDocumentSlug(location.pathname);
|
const documentId = parseDocumentSlug(location.pathname);
|
||||||
const { view } = useEditor();
|
const { view } = useEditor();
|
||||||
const { data, request } = useRequest(
|
const { data, loading, request } = useRequest(
|
||||||
React.useCallback(
|
React.useCallback(
|
||||||
() =>
|
() =>
|
||||||
documentId
|
documentId
|
||||||
@@ -59,24 +59,24 @@ function MentionMenu({ search, isActive, ...rest }: Props) {
|
|||||||
}, [request, isActive]);
|
}, [request, isActive]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (data) {
|
if (data && !loading) {
|
||||||
setItems(
|
const items = data.map((user) => ({
|
||||||
data.map((user) => ({
|
name: "mention",
|
||||||
name: "mention",
|
user,
|
||||||
user,
|
title: user.name,
|
||||||
title: user.name,
|
appendSpace: true,
|
||||||
appendSpace: true,
|
attrs: {
|
||||||
attrs: {
|
id: v4(),
|
||||||
id: v4(),
|
type: MentionType.User,
|
||||||
type: MentionType.User,
|
modelId: user.id,
|
||||||
modelId: user.id,
|
actorId: auth.user?.id,
|
||||||
actorId: auth.user?.id,
|
label: user.name,
|
||||||
label: user.name,
|
},
|
||||||
},
|
}));
|
||||||
}))
|
|
||||||
);
|
setItems(items);
|
||||||
}
|
}
|
||||||
}, [auth.user?.id, data]);
|
}, [auth.user?.id, loading, data]);
|
||||||
|
|
||||||
const clearSearch = () => {
|
const clearSearch = () => {
|
||||||
const { state, dispatch } = view;
|
const { state, dispatch } = view;
|
||||||
|
|||||||
@@ -3082,15 +3082,15 @@ describe("#documents.unpublish", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("#documents.users", () => {
|
describe("#documents.users", () => {
|
||||||
it("should return document users", async () => {
|
it("should return all users when collection is not private", async () => {
|
||||||
const user = await buildUser();
|
const user = await buildUser();
|
||||||
const collection = await buildCollection({
|
const collection = await buildCollection({
|
||||||
teamId: user.teamId,
|
teamId: user.teamId,
|
||||||
createdById: user.id,
|
userId: user.id,
|
||||||
});
|
});
|
||||||
const document = await buildDocument({
|
const document = await buildDocument({
|
||||||
collectionId: collection.id,
|
collectionId: collection.id,
|
||||||
createdById: user.id,
|
userId: user.id,
|
||||||
teamId: user.teamId,
|
teamId: user.teamId,
|
||||||
});
|
});
|
||||||
const [alan, bret, ken] = await Promise.all([
|
const [alan, bret, ken] = await Promise.all([
|
||||||
@@ -3108,28 +3108,6 @@ describe("#documents.users", () => {
|
|||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// add people to collection
|
|
||||||
await Promise.all([
|
|
||||||
CollectionUser.create({
|
|
||||||
collectionId: collection.id,
|
|
||||||
userId: alan.id,
|
|
||||||
permission: CollectionPermission.Read,
|
|
||||||
createdById: user.id,
|
|
||||||
}),
|
|
||||||
CollectionUser.create({
|
|
||||||
collectionId: collection.id,
|
|
||||||
userId: bret.id,
|
|
||||||
permission: CollectionPermission.Read,
|
|
||||||
createdById: user.id,
|
|
||||||
}),
|
|
||||||
CollectionUser.create({
|
|
||||||
collectionId: collection.id,
|
|
||||||
userId: ken.id,
|
|
||||||
permission: CollectionPermission.Read,
|
|
||||||
createdById: user.id,
|
|
||||||
}),
|
|
||||||
]);
|
|
||||||
|
|
||||||
const res = await server.post("/api/documents.users", {
|
const res = await server.post("/api/documents.users", {
|
||||||
body: {
|
body: {
|
||||||
token: user.getJwtToken(),
|
token: user.getJwtToken(),
|
||||||
@@ -3139,23 +3117,25 @@ describe("#documents.users", () => {
|
|||||||
const body = await res.json();
|
const body = await res.json();
|
||||||
|
|
||||||
expect(res.status).toBe(200);
|
expect(res.status).toBe(200);
|
||||||
expect(body.data.length).toBe(3);
|
expect(body.data.length).toBe(4);
|
||||||
|
|
||||||
const memberIds = body.data.map((u: User) => u.id);
|
const memberIds = body.data.map((u: User) => u.id);
|
||||||
expect(memberIds).toContain(alan.id);
|
expect(memberIds).toContain(alan.id);
|
||||||
expect(memberIds).toContain(bret.id);
|
expect(memberIds).toContain(bret.id);
|
||||||
expect(memberIds).toContain(ken.id);
|
expect(memberIds).toContain(ken.id);
|
||||||
|
expect(memberIds).toContain(user.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should return document users with names matching the search query", async () => {
|
it("should return document users with names matching the search query", async () => {
|
||||||
const user = await buildUser();
|
const user = await buildUser();
|
||||||
const collection = await buildCollection({
|
const collection = await buildCollection({
|
||||||
teamId: user.teamId,
|
teamId: user.teamId,
|
||||||
createdById: user.id,
|
userId: user.id,
|
||||||
|
permission: null,
|
||||||
});
|
});
|
||||||
const document = await buildDocument({
|
const document = await buildDocument({
|
||||||
collectionId: collection.id,
|
collectionId: collection.id,
|
||||||
createdById: user.id,
|
userId: user.id,
|
||||||
teamId: user.teamId,
|
teamId: user.teamId,
|
||||||
});
|
});
|
||||||
const [alan, bret, ken, jamie] = await Promise.all([
|
const [alan, bret, ken, jamie] = await Promise.all([
|
||||||
@@ -3248,7 +3228,7 @@ describe("#documents.users", () => {
|
|||||||
expect(body.data[0].name).toBe(alan.name);
|
expect(body.data[0].name).toBe(alan.name);
|
||||||
|
|
||||||
expect(anotherRes.status).toBe(200);
|
expect(anotherRes.status).toBe(200);
|
||||||
expect(anotherBody.data.length).toBe(3);
|
expect(anotherBody.data.length).toBe(4);
|
||||||
const memberIds = anotherBody.data.map((u: User) => u.id);
|
const memberIds = anotherBody.data.map((u: User) => u.id);
|
||||||
const memberNames = anotherBody.data.map((u: User) => u.name);
|
const memberNames = anotherBody.data.map((u: User) => u.name);
|
||||||
expect(memberIds).toContain(bret.id);
|
expect(memberIds).toContain(bret.id);
|
||||||
@@ -3263,11 +3243,12 @@ describe("#documents.users", () => {
|
|||||||
const user = await buildUser();
|
const user = await buildUser();
|
||||||
const collection = await buildCollection({
|
const collection = await buildCollection({
|
||||||
teamId: user.teamId,
|
teamId: user.teamId,
|
||||||
createdById: user.id,
|
userId: user.id,
|
||||||
|
permission: null,
|
||||||
});
|
});
|
||||||
const document = await buildDocument({
|
const document = await buildDocument({
|
||||||
collectionId: collection.id,
|
collectionId: collection.id,
|
||||||
createdById: user.id,
|
userId: user.id,
|
||||||
teamId: user.teamId,
|
teamId: user.teamId,
|
||||||
});
|
});
|
||||||
const [alan, bret, ken] = await Promise.all([
|
const [alan, bret, ken] = await Promise.all([
|
||||||
@@ -3320,7 +3301,7 @@ describe("#documents.users", () => {
|
|||||||
const body = await res.json();
|
const body = await res.json();
|
||||||
|
|
||||||
expect(res.status).toBe(200);
|
expect(res.status).toBe(200);
|
||||||
expect(body.data.length).toBe(2);
|
expect(body.data.length).toBe(3);
|
||||||
|
|
||||||
const memberIds = body.data.map((u: User) => u.id);
|
const memberIds = body.data.map((u: User) => u.id);
|
||||||
expect(memberIds).not.toContain(alan.id);
|
expect(memberIds).not.toContain(alan.id);
|
||||||
|
|||||||
@@ -452,20 +452,28 @@ router.post(
|
|||||||
|
|
||||||
let users: User[] = [];
|
let users: User[] = [];
|
||||||
let total = 0;
|
let total = 0;
|
||||||
|
let where: WhereOptions<User> = {
|
||||||
|
teamId: document.teamId,
|
||||||
|
suspendedAt: {
|
||||||
|
[Op.is]: null,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
if (document.collectionId) {
|
if (document.collectionId) {
|
||||||
const memberIds = await Collection.membershipUserIds(
|
const collection = await document.$get("collection");
|
||||||
document.collectionId
|
|
||||||
);
|
if (!collection?.permission) {
|
||||||
|
const memberIds = await Collection.membershipUserIds(
|
||||||
|
document.collectionId
|
||||||
|
);
|
||||||
|
where = {
|
||||||
|
...where,
|
||||||
|
id: {
|
||||||
|
[Op.in]: memberIds,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
let where: WhereOptions<User> = {
|
|
||||||
id: {
|
|
||||||
[Op.in]: memberIds,
|
|
||||||
},
|
|
||||||
suspendedAt: {
|
|
||||||
[Op.is]: null,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
if (query) {
|
if (query) {
|
||||||
where = {
|
where = {
|
||||||
...where,
|
...where,
|
||||||
|
|||||||
Reference in New Issue
Block a user