From 354a68a8b77e52b2792076e3fe8ebf0b30a7544d Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Thu, 25 Aug 2022 21:51:34 +0200 Subject: [PATCH] Remove long-deprecated documents.star/documents.unstar --- .../components/WebhookSubscriptionForm.tsx | 2 - .../queues/processors/WebsocketsProcessor.ts | 7 -- server/queues/tasks/DeliverWebhookTask.ts | 2 - .../api/__snapshots__/documents.test.ts.snap | 18 ----- server/routes/api/documents.test.ts | 74 ------------------- server/routes/api/documents.ts | 70 ------------------ server/types.ts | 4 +- 7 files changed, 1 insertion(+), 176 deletions(-) diff --git a/app/scenes/Settings/components/WebhookSubscriptionForm.tsx b/app/scenes/Settings/components/WebhookSubscriptionForm.tsx index af0cf5cc9..fc58ec498 100644 --- a/app/scenes/Settings/components/WebhookSubscriptionForm.tsx +++ b/app/scenes/Settings/components/WebhookSubscriptionForm.tsx @@ -31,8 +31,6 @@ const WEBHOOK_EVENTS = { "documents.archive", "documents.unarchive", "documents.restore", - "documents.star", - "documents.unstar", "documents.move", "documents.update", "documents.update.delayed", diff --git a/server/queues/processors/WebsocketsProcessor.ts b/server/queues/processors/WebsocketsProcessor.ts index 4aeb13717..2469201ce 100644 --- a/server/queues/processors/WebsocketsProcessor.ts +++ b/server/queues/processors/WebsocketsProcessor.ts @@ -101,13 +101,6 @@ export default class WebsocketsProcessor { }); } - case "documents.star": - case "documents.unstar": { - return socketio.to(`user-${event.actorId}`).emit(event.name, { - documentId: event.documentId, - }); - } - case "documents.move": { const documents = await Document.findAll({ where: { diff --git a/server/queues/tasks/DeliverWebhookTask.ts b/server/queues/tasks/DeliverWebhookTask.ts index b9bd85113..39b103aa0 100644 --- a/server/queues/tasks/DeliverWebhookTask.ts +++ b/server/queues/tasks/DeliverWebhookTask.ts @@ -120,8 +120,6 @@ export default class DeliverWebhookTask extends BaseTask { case "documents.archive": case "documents.unarchive": case "documents.restore": - case "documents.star": - case "documents.unstar": case "documents.move": case "documents.update": case "documents.title_change": diff --git a/server/routes/api/__snapshots__/documents.test.ts.snap b/server/routes/api/__snapshots__/documents.test.ts.snap index 2ac18507a..b9386a3cc 100644 --- a/server/routes/api/__snapshots__/documents.test.ts.snap +++ b/server/routes/api/__snapshots__/documents.test.ts.snap @@ -44,24 +44,6 @@ Object { } `; -exports[`#documents.star should require authentication 1`] = ` -Object { - "error": "authentication_required", - "message": "Authentication required", - "ok": false, - "status": 401, -} -`; - -exports[`#documents.unstar should require authentication 1`] = ` -Object { - "error": "authentication_required", - "message": "Authentication required", - "ok": false, - "status": 401, -} -`; - exports[`#documents.update should fail if document lastRevision does not match 1`] = ` Object { "error": "invalid_request", diff --git a/server/routes/api/documents.test.ts b/server/routes/api/documents.test.ts index 7a8e5717b..4dfe8648e 100644 --- a/server/routes/api/documents.test.ts +++ b/server/routes/api/documents.test.ts @@ -1,7 +1,6 @@ import { Document, View, - Star, Revision, Backlink, CollectionUser, @@ -1819,79 +1818,6 @@ describe("#documents.restore", () => { }); }); -describe("#documents.star", () => { - it("should star the document", async () => { - const { user, document } = await seed(); - const res = await server.post("/api/documents.star", { - body: { - token: user.getJwtToken(), - id: document.id, - }, - }); - const stars = await Star.findAll(); - expect(res.status).toEqual(200); - expect(stars.length).toEqual(1); - expect(stars[0].documentId).toEqual(document.id); - }); - - it("should require authentication", async () => { - const res = await server.post("/api/documents.star"); - const body = await res.json(); - expect(res.status).toEqual(401); - expect(body).toMatchSnapshot(); - }); - - it("should require authorization", async () => { - const { document } = await seed(); - const user = await buildUser(); - const res = await server.post("/api/documents.star", { - body: { - token: user.getJwtToken(), - id: document.id, - }, - }); - expect(res.status).toEqual(403); - }); -}); - -describe("#documents.unstar", () => { - it("should unstar the document", async () => { - const { user, document } = await seed(); - await Star.create({ - documentId: document.id, - userId: user.id, - }); - const res = await server.post("/api/documents.unstar", { - body: { - token: user.getJwtToken(), - id: document.id, - }, - }); - const stars = await Star.findAll(); - expect(res.status).toEqual(200); - expect(stars.length).toEqual(0); - }); - - it("should require authentication", async () => { - const res = await server.post("/api/documents.star"); - const body = await res.json(); - expect(res.status).toEqual(401); - expect(body).toMatchSnapshot(); - }); - - it("should require authorization", async () => { - const { document } = await seed(); - const user = await buildUser(); - const res = await server.post("/api/documents.unstar", { - body: { - token: user.getJwtToken(), - id: document.id, - }, - }); - expect(res.status).toEqual(403); - }); -}); - describe("#documents.import", () => { it("should error if no file is passed", async () => { const user = await buildUser(); diff --git a/server/routes/api/documents.ts b/server/routes/api/documents.ts index cb7abd660..8a11dadf1 100644 --- a/server/routes/api/documents.ts +++ b/server/routes/api/documents.ts @@ -23,7 +23,6 @@ import { Event, Revision, SearchQuery, - Star, User, View, } from "@server/models"; @@ -731,75 +730,6 @@ router.post( } ); -// Deprecated – use stars.create instead -router.post("documents.star", auth(), async (ctx) => { - const { id } = ctx.body; - assertPresent(id, "id is required"); - const { user } = ctx.state; - - const document = await Document.findByPk(id, { - userId: user.id, - }); - authorize(user, "read", document); - - await Star.findOrCreate({ - where: { - documentId: document.id, - userId: user.id, - }, - }); - - await Event.create({ - name: "documents.star", - documentId: document.id, - collectionId: document.collectionId, - teamId: document.teamId, - actorId: user.id, - data: { - title: document.title, - }, - ip: ctx.request.ip, - }); - - ctx.body = { - success: true, - }; -}); - -// Deprecated – use stars.delete instead -router.post("documents.unstar", auth(), async (ctx) => { - const { id } = ctx.body; - assertPresent(id, "id is required"); - const { user } = ctx.state; - - const document = await Document.findByPk(id, { - userId: user.id, - }); - authorize(user, "read", document); - - await Star.destroy({ - where: { - documentId: document.id, - userId: user.id, - }, - }); - await Event.create({ - name: "documents.unstar", - documentId: document.id, - collectionId: document.collectionId, - teamId: document.teamId, - actorId: user.id, - data: { - title: document.title, - }, - ip: ctx.request.ip, - }); - - ctx.body = { - success: true, - }; -}); - router.post("documents.templatize", auth({ member: true }), async (ctx) => { const { id } = ctx.body; assertPresent(id, "id is required"); diff --git a/server/types.ts b/server/types.ts index eb40f2f8c..2f3b7543e 100644 --- a/server/types.ts +++ b/server/types.ts @@ -95,9 +95,7 @@ export type DocumentEvent = BaseEvent & | "documents.permanent_delete" | "documents.archive" | "documents.unarchive" - | "documents.restore" - | "documents.star" - | "documents.unstar"; + | "documents.restore"; documentId: string; collectionId: string; data: {