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
This commit is contained in:
Tom Moor
2021-05-01 16:35:00 -07:00
committed by GitHub
parent 77d6adb73b
commit 49ffcda8e0

View File

@ -8,7 +8,6 @@ import {
Document, Document,
User, User,
Team, Team,
Collection,
SearchQuery, SearchQuery,
Integration, Integration,
IntegrationAuthentication, IntegrationAuthentication,
@ -79,49 +78,27 @@ router.post("hooks.interactive", async (ctx) => {
throw new AuthenticationError("Invalid verification token"); throw new AuthenticationError("Invalid verification token");
} }
const authProvider = await AuthenticationProvider.findOne({ // we find the document based on the users teamId to ensure access
where: { const document = await Document.scope("withCollection").findByPk(
name: "slack", data.callback_id
providerId: data.team.id, );
}, if (!document) {
include: [ throw new InvalidRequestError("Invalid callback_id");
{
model: Team,
as: "team",
required: true,
},
],
});
if (!authProvider) {
ctx.body = {
text:
"Sorry, we couldnt find an integration for your team. Head to your Outline settings to set one up.",
response_type: "ephemeral",
replace_original: false,
};
return;
} }
const { team } = authProvider; const team = await Team.findByPk(document.teamId);
// 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);
// respond with a public message that will be posted in the original channel // respond with a public message that will be posted in the original channel
ctx.body = { ctx.body = {
response_type: "in_channel", response_type: "in_channel",
replace_original: false, replace_original: false,
attachments: [ attachments: [
presentSlackAttachment(document, collection, team, document.getSummary()), presentSlackAttachment(
document,
document.collection,
team,
document.getSummary()
),
], ],
}; };
}); });