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:
@ -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()
|
||||
),
|
||||
],
|
||||
};
|
||||
});
|
||||
|
Reference in New Issue
Block a user