mirror of
https://github.com/outline/outline.git
synced 2026-11-25 23:24:06 +03:00
ts: middlewares, emails, commands
This commit is contained in:
1 parent
d67d1e3f9b
commit
e81605fb9d
28 files changed
+106
-90
No files matched your search
@@ -1,4 +1,3 @@
|
||||
// @flow
|
||||
import path from "path";
|
||||
import File from "formidable/lib/file";
|
||||
import { Attachment } from "../models";
|
||||
@@ -1,4 +1,3 @@
|
||||
// @flow
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import File from "formidable/lib/file";
|
||||
@@ -36,7 +35,7 @@ turndownService
|
||||
|
||||
interface ImportableFile {
|
||||
type: string;
|
||||
getMarkdown: (file: any) => Promise<string>;
|
||||
getMarkdown: ((file: any) => Promise<string>);
|
||||
}
|
||||
|
||||
const importMapping: ImportableFile[] = [
|
||||
@@ -131,15 +130,20 @@ async function confluenceToMarkdown(file): Promise<string> {
|
||||
return html.replace(/<br>/g, " \\n ");
|
||||
}
|
||||
|
||||
export default async function documentImporter({
|
||||
file,
|
||||
user,
|
||||
ip,
|
||||
}: {
|
||||
user: User,
|
||||
file: File,
|
||||
ip: string,
|
||||
}): Promise<{ text: string, title: string }> {
|
||||
export default async function documentImporter(
|
||||
{
|
||||
file,
|
||||
user,
|
||||
ip
|
||||
}: {
|
||||
user: User,
|
||||
file: File,
|
||||
ip: string
|
||||
}
|
||||
): Promise<{
|
||||
text: string,
|
||||
title: string
|
||||
}> {
|
||||
const fileInfo = importMapping.filter((item) => {
|
||||
if (item.type === file.type) {
|
||||
return true;
|
||||
File renamed without changes.
@@ -1,4 +1,3 @@
|
||||
// @flow
|
||||
import { Document, Collection, User, Event } from "../models";
|
||||
import { sequelize } from "../sequelize";
|
||||
|
||||
@@ -8,14 +7,14 @@ export default async function documentMover({
|
||||
collectionId,
|
||||
parentDocumentId,
|
||||
index,
|
||||
ip,
|
||||
ip
|
||||
}: {
|
||||
user: User,
|
||||
document: Document,
|
||||
collectionId: string,
|
||||
parentDocumentId?: string,
|
||||
index?: number,
|
||||
ip: string,
|
||||
ip: string
|
||||
}) {
|
||||
let transaction;
|
||||
const result = { collections: [], documents: [] };
|
||||
File renamed without changes.
@@ -1,19 +1,26 @@
|
||||
// @flow
|
||||
import { uniqBy } from "lodash";
|
||||
import mailer from "../mailer";
|
||||
import { User, Event, Team } from "../models";
|
||||
|
||||
type Invite = { name: string, email: string };
|
||||
type Invite = {
|
||||
name: string,
|
||||
email: string
|
||||
};
|
||||
|
||||
export default async function userInviter({
|
||||
user,
|
||||
invites,
|
||||
ip,
|
||||
}: {
|
||||
user: User,
|
||||
invites: Invite[],
|
||||
ip: string,
|
||||
}): Promise<{ sent: Invite[], users: User[] }> {
|
||||
export default async function userInviter(
|
||||
{
|
||||
user,
|
||||
invites,
|
||||
ip
|
||||
}: {
|
||||
user: User,
|
||||
invites: Invite[],
|
||||
ip: string
|
||||
}
|
||||
): Promise<{
|
||||
sent: Invite[],
|
||||
users: User[]
|
||||
}> {
|
||||
const team = await Team.findByPk(user.teamId);
|
||||
|
||||
// filter out empties and obvious non-emails
|
||||
File renamed without changes.
@@ -1,18 +1,19 @@
|
||||
// @flow
|
||||
import { Transaction } from "sequelize";
|
||||
import { ValidationError } from "../errors";
|
||||
import { User, Event, GroupUser } from "../models";
|
||||
import { sequelize } from "../sequelize";
|
||||
|
||||
export default async function userSuspender({
|
||||
user,
|
||||
actorId,
|
||||
ip,
|
||||
}: {
|
||||
user: User,
|
||||
actorId: string,
|
||||
ip: string,
|
||||
}): Promise<void> {
|
||||
export default async function userSuspender(
|
||||
{
|
||||
user,
|
||||
actorId,
|
||||
ip
|
||||
}: {
|
||||
user: User,
|
||||
actorId: string,
|
||||
ip: string
|
||||
}
|
||||
): Promise<void> {
|
||||
if (user.id === actorId) {
|
||||
throw new ValidationError("Unable to suspend the current user");
|
||||
}
|
||||
+3
-4
@@ -1,4 +1,3 @@
|
||||
// @flow
|
||||
import * as React from "react";
|
||||
import { User, Collection } from "../models";
|
||||
import Body from "./components/Body";
|
||||
@@ -13,13 +12,13 @@ export type Props = {
|
||||
actor: User,
|
||||
collection: Collection,
|
||||
eventName: string,
|
||||
unsubscribeUrl: string,
|
||||
unsubscribeUrl: string
|
||||
};
|
||||
|
||||
export const collectionNotificationEmailText = ({
|
||||
actor,
|
||||
collection,
|
||||
eventName = "created",
|
||||
eventName = "created"
|
||||
}: Props) => `
|
||||
${collection.name}
|
||||
|
||||
@@ -32,7 +31,7 @@ export const CollectionNotificationEmail = ({
|
||||
actor,
|
||||
collection,
|
||||
eventName = "created",
|
||||
unsubscribeUrl,
|
||||
unsubscribeUrl
|
||||
}: Props) => {
|
||||
return (
|
||||
<EmailTemplate>
|
||||
+3
-4
@@ -1,4 +1,3 @@
|
||||
// @flow
|
||||
import * as React from "react";
|
||||
import { User, Document, Team, Collection } from "../models";
|
||||
import Body from "./components/Body";
|
||||
@@ -15,7 +14,7 @@ export type Props = {
|
||||
document: Document,
|
||||
collection: Collection,
|
||||
eventName: string,
|
||||
unsubscribeUrl: string,
|
||||
unsubscribeUrl: string
|
||||
};
|
||||
|
||||
export const documentNotificationEmailText = ({
|
||||
@@ -23,7 +22,7 @@ export const documentNotificationEmailText = ({
|
||||
team,
|
||||
document,
|
||||
collection,
|
||||
eventName = "published",
|
||||
eventName = "published"
|
||||
}: Props) => `
|
||||
"${document.title}" ${eventName}
|
||||
|
||||
@@ -38,7 +37,7 @@ export const DocumentNotificationEmail = ({
|
||||
document,
|
||||
collection,
|
||||
eventName = "published",
|
||||
unsubscribeUrl,
|
||||
unsubscribeUrl
|
||||
}: Props) => {
|
||||
return (
|
||||
<EmailTemplate>
|
||||
@@ -1,4 +1,3 @@
|
||||
// @flow
|
||||
import * as React from "react";
|
||||
import Body from "./components/Body";
|
||||
import Button from "./components/Button";
|
||||
@@ -1,4 +1,3 @@
|
||||
// @flow
|
||||
import * as React from "react";
|
||||
import Body from "./components/Body";
|
||||
import Button from "./components/Button";
|
||||
@@ -13,14 +12,14 @@ export type Props = {
|
||||
actorName: string,
|
||||
actorEmail: string,
|
||||
teamName: string,
|
||||
teamUrl: string,
|
||||
teamUrl: string
|
||||
};
|
||||
|
||||
export const inviteEmailText = ({
|
||||
teamName,
|
||||
actorName,
|
||||
actorEmail,
|
||||
teamUrl,
|
||||
teamUrl
|
||||
}: Props) => `
|
||||
Join ${teamName} on Outline
|
||||
|
||||
@@ -33,7 +32,7 @@ export const InviteEmail = ({
|
||||
teamName,
|
||||
actorName,
|
||||
actorEmail,
|
||||
teamUrl,
|
||||
teamUrl
|
||||
}: Props) => {
|
||||
return (
|
||||
<EmailTemplate>
|
||||
@@ -1,4 +1,3 @@
|
||||
// @flow
|
||||
import * as React from "react";
|
||||
import Body from "./components/Body";
|
||||
import Button from "./components/Button";
|
||||
@@ -10,10 +9,13 @@ import Heading from "./components/Heading";
|
||||
|
||||
export type Props = {
|
||||
token: string,
|
||||
teamUrl: string,
|
||||
teamUrl: string
|
||||
};
|
||||
|
||||
export const signinEmailText = ({ token, teamUrl }: Props) => `
|
||||
export const signinEmailText = ({
|
||||
token,
|
||||
teamUrl
|
||||
}: Props) => `
|
||||
Use the link below to signin to Outline:
|
||||
|
||||
${process.env.URL}/auth/email.callback?token=${token}
|
||||
@@ -22,7 +24,10 @@ If your magic link expired you can request a new one from your team’s
|
||||
signin page at: ${teamUrl}
|
||||
`;
|
||||
|
||||
export const SigninEmail = ({ token, teamUrl }: Props) => {
|
||||
export const SigninEmail = ({
|
||||
token,
|
||||
teamUrl
|
||||
}: Props) => {
|
||||
return (
|
||||
<EmailTemplate>
|
||||
<Header />
|
||||
@@ -1,4 +1,3 @@
|
||||
// @flow
|
||||
import * as React from "react";
|
||||
import Body from "./components/Body";
|
||||
import Button from "./components/Button";
|
||||
@@ -9,10 +8,12 @@ import Header from "./components/Header";
|
||||
import Heading from "./components/Heading";
|
||||
|
||||
export type Props = {
|
||||
teamUrl: string,
|
||||
teamUrl: string
|
||||
};
|
||||
|
||||
export const welcomeEmailText = ({ teamUrl }: Props) => `
|
||||
export const welcomeEmailText = ({
|
||||
teamUrl
|
||||
}: Props) => `
|
||||
Welcome to Outline!
|
||||
|
||||
Outline is a place for your team to build and share knowledge.
|
||||
@@ -24,7 +25,9 @@ You can also import existing Markdown documents by dragging and dropping them to
|
||||
${teamUrl}/home
|
||||
`;
|
||||
|
||||
export const WelcomeEmail = ({ teamUrl }: Props) => {
|
||||
export const WelcomeEmail = ({
|
||||
teamUrl
|
||||
}: Props) => {
|
||||
return (
|
||||
<EmailTemplate>
|
||||
<Header />
|
||||
@@ -1,14 +1,15 @@
|
||||
// @flow
|
||||
import { Table, TBody, TR, TD } from "oy-vey";
|
||||
import * as React from "react";
|
||||
|
||||
import EmptySpace from "./EmptySpace";
|
||||
|
||||
type Props = {
|
||||
children: React.Node,
|
||||
children: React.ReactNode
|
||||
};
|
||||
|
||||
export default ({ children }: Props) => {
|
||||
export default ({
|
||||
children
|
||||
}: Props) => {
|
||||
return (
|
||||
<Table width="100%">
|
||||
<TBody>
|
||||
@@ -1,7 +1,9 @@
|
||||
// @flow
|
||||
import * as React from "react";
|
||||
|
||||
type Props = { href: string, children: React.Node };
|
||||
type Props = {
|
||||
href: string,
|
||||
children: React.ReactNode
|
||||
};
|
||||
|
||||
export default (props: Props) => {
|
||||
const style = {
|
||||
@@ -1,10 +1,9 @@
|
||||
// @flow
|
||||
import { Table, TBody, TR, TD } from "oy-vey";
|
||||
import * as React from "react";
|
||||
import theme from "../../../shared/styles/theme";
|
||||
|
||||
type Props = {
|
||||
children: React.Node,
|
||||
children: React.ReactNode
|
||||
};
|
||||
|
||||
export default (props: Props) => (
|
||||
@@ -1,8 +1,11 @@
|
||||
// @flow
|
||||
import { Table, TBody, TR, TD } from "oy-vey";
|
||||
import * as React from "react";
|
||||
|
||||
const EmptySpace = ({ height }: { height?: number }) => {
|
||||
const EmptySpace = ({
|
||||
height
|
||||
}: {
|
||||
height?: number
|
||||
}) => {
|
||||
height = height || 16;
|
||||
const style = {
|
||||
lineHeight: `${height}px`,
|
||||
@@ -1,14 +1,15 @@
|
||||
// @flow
|
||||
import { Table, TBody, TR, TD } from "oy-vey";
|
||||
import * as React from "react";
|
||||
import theme from "../../../shared/styles/theme";
|
||||
import { twitterUrl } from "../../../shared/utils/routeHelpers";
|
||||
|
||||
type Props = {
|
||||
unsubscribeUrl?: string,
|
||||
unsubscribeUrl?: string
|
||||
};
|
||||
|
||||
export default ({ unsubscribeUrl }: Props) => {
|
||||
export default ({
|
||||
unsubscribeUrl
|
||||
}: Props) => {
|
||||
const footerStyle = {
|
||||
padding: "20px 0",
|
||||
borderTop: `1px solid ${theme.smokeDark}`,
|
||||
@@ -1,4 +1,3 @@
|
||||
// @flow
|
||||
import { Table, TBody, TR, TD } from "oy-vey";
|
||||
import * as React from "react";
|
||||
import EmptySpace from "./EmptySpace";
|
||||
@@ -1,4 +1,3 @@
|
||||
// @flow
|
||||
import * as React from "react";
|
||||
|
||||
const style = {
|
||||
@@ -7,10 +6,12 @@ const style = {
|
||||
};
|
||||
|
||||
type Props = {
|
||||
children: React.Node,
|
||||
children: React.ReactNode
|
||||
};
|
||||
|
||||
export default ({ children }: Props) => (
|
||||
export default ({
|
||||
children
|
||||
}: Props) => (
|
||||
<p>
|
||||
<span style={style}>{children}</span>
|
||||
</p>
|
||||
@@ -1,4 +1,3 @@
|
||||
// @flow
|
||||
import Koa from "koa";
|
||||
import Router from "koa-router";
|
||||
import { NotFoundError } from "../errors";
|
||||
@@ -1,10 +1,9 @@
|
||||
// @flow
|
||||
import type { Context } from "koa";
|
||||
import { Context } from "koa";
|
||||
|
||||
export default function apexRedirect() {
|
||||
return async function apexRedirectMiddleware(
|
||||
ctx: Context,
|
||||
next: () => Promise<*>
|
||||
next: (() => Promise<unknown>)
|
||||
) {
|
||||
if (ctx.headers.host === "getoutline.com") {
|
||||
ctx.redirect(`https://www.${ctx.headers.host}${ctx.path}`);
|
||||
File renamed without changes.
@@ -1,16 +1,17 @@
|
||||
// @flow
|
||||
import addMonths from "date-fns/add_months";
|
||||
import JWT from "jsonwebtoken";
|
||||
import { AuthenticationError, UserSuspendedError } from "../errors";
|
||||
import { User, Event, Team, ApiKey } from "../models";
|
||||
import type { ContextWithState } from "../types";
|
||||
import { ContextWithState } from "../types";
|
||||
import { getCookieDomain } from "../utils/domains";
|
||||
import { getUserForJWT } from "../utils/jwt";
|
||||
|
||||
export default function auth(options?: { required?: boolean } = {}) {
|
||||
export default function auth(options?: {
|
||||
required?: boolean
|
||||
} = {}) {
|
||||
return async function authMiddleware(
|
||||
ctx: ContextWithState,
|
||||
next: () => Promise<mixed>
|
||||
next: (() => Promise<unknown>)
|
||||
) {
|
||||
let token;
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
// @flow
|
||||
import { type Context } from "koa";
|
||||
import { Context } from "koa";
|
||||
import { snakeCase } from "lodash";
|
||||
import Sequelize from "sequelize";
|
||||
|
||||
export default function errorHandling() {
|
||||
return async function errorHandlingMiddleware(
|
||||
ctx: Context,
|
||||
next: () => Promise<*>
|
||||
next: (() => Promise<unknown>)
|
||||
) {
|
||||
try {
|
||||
await next();
|
||||
@@ -1,11 +1,10 @@
|
||||
// @flow
|
||||
import { type Context } from "koa";
|
||||
import { Context } from "koa";
|
||||
import queryString from "query-string";
|
||||
|
||||
export default function methodOverride() {
|
||||
return async function methodOverrideMiddleware(
|
||||
ctx: Context,
|
||||
next: () => Promise<*>
|
||||
next: (() => Promise<unknown>)
|
||||
) {
|
||||
if (ctx.method === "POST") {
|
||||
// $FlowFixMe
|
||||
@@ -1,11 +1,10 @@
|
||||
// @flow
|
||||
import { type Context } from "koa";
|
||||
import { Context } from "koa";
|
||||
import validator from "validator";
|
||||
import { validateColorHex } from "../../shared/utils/color";
|
||||
import { ParamRequiredError, ValidationError } from "../errors";
|
||||
|
||||
export default function validation() {
|
||||
return function validationMiddleware(ctx: Context, next: () => Promise<*>) {
|
||||
return function validationMiddleware(ctx: Context, next: (() => Promise<unknown>)) {
|
||||
ctx.assertPresent = (value, message) => {
|
||||
if (value === undefined || value === null || value === "") {
|
||||
throw new ParamRequiredError(message);
|
||||
Reference in new issue
Block a user