Unfurling of Slack links (#487)

* First pass: Unfurling of Slack links

* Add authentication in db

* Call associate on Event correctly

* Add SLACK_APP_ID, remove SLACK_REDIRECT_URI, tidy env sample

* PR feedback

* Comment clarify
This commit is contained in:
Tom Moor
2017-12-18 19:59:29 -08:00
committed by GitHub
parent 938bb3fc31
commit 32ba98bb1a
19 changed files with 219 additions and 48 deletions

View File

@@ -0,0 +1,26 @@
// @flow
import { DataTypes, sequelize, encryptedFields } from '../sequelize';
const Authentication = sequelize.define('authentication', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
serviceId: DataTypes.STRING,
scopes: DataTypes.ARRAY(DataTypes.STRING),
token: encryptedFields.vault('token'),
});
Authentication.associate = models => {
Authentication.belongsTo(models.User, {
as: 'user',
foreignKey: 'userId',
});
Authentication.belongsTo(models.Team, {
as: 'team',
foreignKey: 'teamId',
});
};
export default Authentication;

View File

@@ -2,12 +2,15 @@
import slug from 'slug';
import _ from 'lodash';
import randomstring from 'randomstring';
import MarkdownSerializer from 'slate-md-serializer';
import Plain from 'slate-plain-serializer';
import isUUID from 'validator/lib/isUUID';
import { DataTypes, sequelize } from '../sequelize';
import parseTitle from '../../shared/utils/parseTitle';
import Revision from './Revision';
const Markdown = new MarkdownSerializer();
const URL_REGEX = /^[a-zA-Z0-9-]*-([a-zA-Z0-9]{10,15})$/;
// $FlowIssue invalid flow-typed
@@ -203,6 +206,13 @@ Document.searchForUser = async (
// Instance methods
Document.prototype.getSummary = function() {
const value = Markdown.deserialize(this.text);
const plain = Plain.serialize(value);
const lines = _.compact(plain.split('\n'));
return lines.length >= 1 ? lines[1] : '';
};
Document.prototype.getUrl = function() {
const slugifiedTitle = slugify(this.title);
return `/doc/${slugifiedTitle}-${this.urlId}`;

View File

@@ -9,30 +9,6 @@ const Event = sequelize.define('event', {
},
name: DataTypes.STRING,
data: DataTypes.JSONB,
userId: {
type: 'UUID',
allowNull: true,
references: {
model: 'users',
},
},
collectionId: {
type: 'UUID',
allowNull: true,
references: {
model: 'collections',
},
},
teamId: {
type: 'UUID',
allowNull: true,
references: {
model: 'teams',
},
},
});
Event.associate = models => {

View File

@@ -2,12 +2,11 @@
import crypto from 'crypto';
import bcrypt from 'bcrypt';
import uuid from 'uuid';
import JWT from 'jsonwebtoken';
import { DataTypes, sequelize, encryptedFields } from '../sequelize';
import { uploadToS3FromUrl } from '../utils/s3';
import mailer from '../mailer';
import JWT from 'jsonwebtoken';
const BCRYPT_COST = process.env.NODE_ENV !== 'production' ? 4 : 12;
const User = sequelize.define(

View File

@@ -1,4 +1,6 @@
// @flow
import Authentication from './Authentication';
import Event from './Event';
import User from './User';
import Team from './Team';
import Collection from './Collection';
@@ -9,6 +11,8 @@ import View from './View';
import Star from './Star';
const models = {
Authentication,
Event,
User,
Team,
Collection,
@@ -26,4 +30,15 @@ Object.keys(models).forEach(modelName => {
}
});
export { User, Team, Collection, Document, Revision, ApiKey, View, Star };
export {
Authentication,
Event,
User,
Team,
Collection,
Document,
Revision,
ApiKey,
View,
Star,
};