From 49ffcda8e051abf9429a74782f3ce6af417253ec Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sat, 1 May 2021 16:35:00 -0700 Subject: [PATCH] fix: 'Post to channel' functionality does not work unless Slack SSO used (#2099) * fix: 'Post to channel' functionality does not work unless Slack SSO used * test: And this is why we have tests --- server/api/hooks.js | 49 ++++++++++++--------------------------------- 1 file changed, 13 insertions(+), 36 deletions(-) diff --git a/server/api/hooks.js b/server/api/hooks.js index 716b0f5f..376e4259 100644 --- a/server/api/hooks.js +++ b/server/api/hooks.js @@ -8,7 +8,6 @@ import { Document, User, Team, - Collection, SearchQuery, Integration, IntegrationAuthentication, @@ -79,49 +78,27 @@ router.post("hooks.interactive", async (ctx) => { throw new AuthenticationError("Invalid verification token"); } - const authProvider = await AuthenticationProvider.findOne({ - where: { - name: "slack", - providerId: data.team.id, - }, - include: [ - { - model: Team, - as: "team", - required: true, - }, - ], - }); - - if (!authProvider) { - ctx.body = { - text: - "Sorry, we couldn’t find an integration for your team. Head to your Outline settings to set one up.", - response_type: "ephemeral", - replace_original: false, - }; - return; + // we find the document based on the users teamId to ensure access + const document = await Document.scope("withCollection").findByPk( + data.callback_id + ); + if (!document) { + throw new InvalidRequestError("Invalid callback_id"); } - const { team } = authProvider; - - // we find the document based on the users teamId to ensure access - const document = await Document.findOne({ - where: { - id: data.callback_id, - teamId: team.id, - }, - }); - if (!document) throw new InvalidRequestError("Invalid document"); - - const collection = await Collection.findByPk(document.collectionId); + const team = await Team.findByPk(document.teamId); // respond with a public message that will be posted in the original channel ctx.body = { response_type: "in_channel", replace_original: false, attachments: [ - presentSlackAttachment(document, collection, team, document.getSummary()), + presentSlackAttachment( + document, + document.collection, + team, + document.getSummary() + ), ], }; });