Fixes #831 - Link from Slack notification does not work for teams with subdomains
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import Router from 'koa-router';
|
import Router from 'koa-router';
|
||||||
import { AuthenticationError, InvalidRequestError } from '../errors';
|
import { AuthenticationError, InvalidRequestError } from '../errors';
|
||||||
import { Authentication, Document, User } from '../models';
|
import { Authentication, Document, User, Team } from '../models';
|
||||||
import { presentSlackAttachment } from '../presenters';
|
import { presentSlackAttachment } from '../presenters';
|
||||||
import * as Slack from '../slack';
|
import * as Slack from '../slack';
|
||||||
const router = new Router();
|
const router = new Router();
|
||||||
@@ -64,6 +64,8 @@ router.post('hooks.slack', async ctx => {
|
|||||||
|
|
||||||
if (!user) throw new InvalidRequestError('Invalid user');
|
if (!user) throw new InvalidRequestError('Invalid user');
|
||||||
|
|
||||||
|
const team = await Team.findById(user.teamId);
|
||||||
|
|
||||||
const results = await Document.searchForUser(user, text, {
|
const results = await Document.searchForUser(user, text, {
|
||||||
limit: 5,
|
limit: 5,
|
||||||
});
|
});
|
||||||
@@ -78,6 +80,7 @@ router.post('hooks.slack', async ctx => {
|
|||||||
attachments.push(
|
attachments.push(
|
||||||
presentSlackAttachment(
|
presentSlackAttachment(
|
||||||
result.document,
|
result.document,
|
||||||
|
team,
|
||||||
queryIsInTitle ? undefined : result.context
|
queryIsInTitle ? undefined : result.context
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import { Document } from '../models';
|
import { Document, Team } from '../models';
|
||||||
|
|
||||||
function present(document: Document, context?: string) {
|
function present(document: Document, team: Team, context?: string) {
|
||||||
// the context contains <b> tags around search terms, we convert them here
|
// the context contains <b> tags around search terms, we convert them here
|
||||||
// to the markdown format that slack expects to receive.
|
// to the markdown format that slack expects to receive.
|
||||||
const text = context
|
const text = context
|
||||||
@@ -11,7 +11,7 @@ function present(document: Document, context?: string) {
|
|||||||
return {
|
return {
|
||||||
color: document.collection.color,
|
color: document.collection.color,
|
||||||
title: document.title,
|
title: document.title,
|
||||||
title_link: `${process.env.URL}${document.url}`,
|
title_link: `${team.url}${document.url}`,
|
||||||
footer: document.collection.name,
|
footer: document.collection.name,
|
||||||
text,
|
text,
|
||||||
ts: document.getTimestamp(),
|
ts: document.getTimestamp(),
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import type { Event } from '../events';
|
import type { Event } from '../events';
|
||||||
import { Document, Integration, Collection } from '../models';
|
import { Document, Integration, Collection, Team } from '../models';
|
||||||
import { presentSlackAttachment } from '../presenters';
|
import { presentSlackAttachment } from '../presenters';
|
||||||
|
|
||||||
export default class Slack {
|
export default class Slack {
|
||||||
@@ -70,6 +70,8 @@ export default class Slack {
|
|||||||
});
|
});
|
||||||
if (!integration) return;
|
if (!integration) return;
|
||||||
|
|
||||||
|
const team = await Team.findById(document.teamId);
|
||||||
|
|
||||||
let text = `${document.createdBy.name} published a new document`;
|
let text = `${document.createdBy.name} published a new document`;
|
||||||
|
|
||||||
if (event.name === 'documents.update') {
|
if (event.name === 'documents.update') {
|
||||||
@@ -83,7 +85,7 @@ export default class Slack {
|
|||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
text,
|
text,
|
||||||
attachments: [presentSlackAttachment(document)],
|
attachments: [presentSlackAttachment(document, team)],
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user