Merge pull request #511 from outline/jori/fix-unfurl
Fix Slack unfurling
This commit is contained in:
@@ -8,9 +8,8 @@ import { presentApiKey } from '../presenters';
|
||||
import { ApiKey } from '../models';
|
||||
|
||||
const router = new Router();
|
||||
router.use(auth());
|
||||
|
||||
router.post('apiKeys.create', async ctx => {
|
||||
router.post('apiKeys.create', auth(), async ctx => {
|
||||
const { name } = ctx.body;
|
||||
ctx.assertPresent(name, 'name is required');
|
||||
|
||||
@@ -26,7 +25,7 @@ router.post('apiKeys.create', async ctx => {
|
||||
};
|
||||
});
|
||||
|
||||
router.post('apiKeys.list', pagination(), async ctx => {
|
||||
router.post('apiKeys.list', auth(), pagination(), async ctx => {
|
||||
const user = ctx.state.user;
|
||||
const keys = await ApiKey.findAll({
|
||||
where: {
|
||||
@@ -47,7 +46,7 @@ router.post('apiKeys.list', pagination(), async ctx => {
|
||||
};
|
||||
});
|
||||
|
||||
router.post('apiKeys.delete', async ctx => {
|
||||
router.post('apiKeys.delete', auth(), async ctx => {
|
||||
const { id } = ctx.body;
|
||||
ctx.assertPresent(id, 'id is required');
|
||||
|
||||
|
||||
49
server/api/hooks.test.js
Normal file
49
server/api/hooks.test.js
Normal file
@@ -0,0 +1,49 @@
|
||||
/* eslint-disable flowtype/require-valid-file-annotation */
|
||||
import TestServer from 'fetch-test-server';
|
||||
import app from '..';
|
||||
import Authentication from '../models/Authentication';
|
||||
import { flushdb, seed } from '../test/support';
|
||||
import * as Slack from '../slack';
|
||||
|
||||
const server = new TestServer(app.callback());
|
||||
|
||||
beforeEach(flushdb);
|
||||
afterAll(server.close);
|
||||
|
||||
jest.mock('../slack', () => ({
|
||||
post: jest.fn(),
|
||||
}));
|
||||
|
||||
describe('#hooks.unfurl', async () => {
|
||||
it('should return documents', async () => {
|
||||
const { user, document } = await seed();
|
||||
await Authentication.create({
|
||||
serviceId: 'slack',
|
||||
userId: user.id,
|
||||
teamId: user.teamId,
|
||||
token: '',
|
||||
});
|
||||
|
||||
const res = await server.post('/api/hooks.unfurl', {
|
||||
body: {
|
||||
token: process.env.SLACK_VERIFICATION_TOKEN,
|
||||
team_id: 'TXXXXXXXX',
|
||||
api_app_id: 'AXXXXXXXXX',
|
||||
event: {
|
||||
type: 'link_shared',
|
||||
channel: 'Cxxxxxx',
|
||||
user: user.slackId,
|
||||
message_ts: '123456789.9875',
|
||||
links: [
|
||||
{
|
||||
domain: 'getoutline.com',
|
||||
url: document.getUrl(),
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(res.status).toEqual(200);
|
||||
expect(Slack.post).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -7,13 +7,12 @@ import auth from './middlewares/authentication';
|
||||
import { presentUser } from '../presenters';
|
||||
|
||||
const router = new Router();
|
||||
router.use(auth());
|
||||
|
||||
router.post('user.info', async ctx => {
|
||||
router.post('user.info', auth(), async ctx => {
|
||||
ctx.body = { data: await presentUser(ctx, ctx.state.user) };
|
||||
});
|
||||
|
||||
router.post('user.update', async ctx => {
|
||||
router.post('user.update', auth(), async ctx => {
|
||||
const { user } = ctx.state;
|
||||
const { name, avatarUrl } = ctx.body;
|
||||
const endpoint = publicS3Endpoint();
|
||||
@@ -29,7 +28,7 @@ router.post('user.update', async ctx => {
|
||||
ctx.body = { data: await presentUser(ctx, user) };
|
||||
});
|
||||
|
||||
router.post('user.s3Upload', async ctx => {
|
||||
router.post('user.s3Upload', auth(), async ctx => {
|
||||
const { filename, kind, size } = ctx.body;
|
||||
ctx.assertPresent(filename, 'filename is required');
|
||||
ctx.assertPresent(kind, 'kind is required');
|
||||
|
||||
@@ -6,9 +6,8 @@ import { presentView } from '../presenters';
|
||||
import { View, Document } from '../models';
|
||||
|
||||
const router = new Router();
|
||||
router.use(auth());
|
||||
|
||||
router.post('views.list', async ctx => {
|
||||
router.post('views.list', auth(), async ctx => {
|
||||
const { id } = ctx.body;
|
||||
ctx.assertPresent(id, 'id is required');
|
||||
|
||||
@@ -37,7 +36,7 @@ router.post('views.list', async ctx => {
|
||||
};
|
||||
});
|
||||
|
||||
router.post('views.create', async ctx => {
|
||||
router.post('views.create', auth(), async ctx => {
|
||||
const { id } = ctx.body;
|
||||
ctx.assertPresent(id, 'id is required');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user