fix: Two restore options when an archived document is deleted (#2194)
* Merge two menu items * Add deletedAt guard condition in document unarchive policy * Make the parentDocumentId null * Update test
This commit is contained in:
@ -218,12 +218,7 @@ function DocumentMenu({
|
|||||||
items={[
|
items={[
|
||||||
{
|
{
|
||||||
title: t("Restore"),
|
title: t("Restore"),
|
||||||
visible: !!can.unarchive,
|
visible: (!!collection && can.restore) || can.unarchive,
|
||||||
onClick: handleRestore,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: t("Restore"),
|
|
||||||
visible: !!(collection && can.restore),
|
|
||||||
onClick: handleRestore,
|
onClick: handleRestore,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -1588,7 +1588,7 @@ describe("#documents.restore", () => {
|
|||||||
const body = await res.json();
|
const body = await res.json();
|
||||||
|
|
||||||
expect(res.status).toEqual(200);
|
expect(res.status).toEqual(200);
|
||||||
expect(body.data.parentDocumentId).toEqual(undefined);
|
expect(body.data.parentDocumentId).toEqual(null);
|
||||||
expect(body.data.archivedAt).toEqual(null);
|
expect(body.data.archivedAt).toEqual(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -637,7 +637,7 @@ Document.prototype.unarchive = async function (userId: string) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (!parent) this.parentDocumentId = undefined;
|
if (!parent) this.parentDocumentId = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.template) {
|
if (!this.template) {
|
||||||
|
@ -149,6 +149,7 @@ allow(User, "unarchive", Document, (user, document) => {
|
|||||||
if (cannot(user, "update", document.collection)) return false;
|
if (cannot(user, "update", document.collection)) return false;
|
||||||
|
|
||||||
if (!document.archivedAt) return false;
|
if (!document.archivedAt) return false;
|
||||||
|
if (document.deletedAt) return false;
|
||||||
|
|
||||||
return user.teamId === document.teamId;
|
return user.teamId === document.teamId;
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user