mirror of
https://github.com/outline/outline.git
synced 2026-12-03 10:00:13 +03:00
* chore: Rename APIContext to Context and flatten its fields Auth and transaction now live directly on the context instead of in ctx.state and a nested ctx.context, and model helpers read them directly. APIContext remains as a deprecated alias. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016MJXFeUxvU46KyvKnP8sXf * chore: Remove deprecated APIContext alias Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016MJXFeUxvU46KyvKnP8sXf * fix: Read auth from context in OAuth provider callbacks Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016MJXFeUxvU46KyvKnP8sXf * chore: Add withUser and withTransaction context helpers Replaces manual createContext rebuilds that copy fields from an existing context. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016MJXFeUxvU46KyvKnP8sXf * chore: Remove arbitrary property access from Koa context types AppContext and Context no longer inherit the any index signature from Koa's DefaultContext, custom fields are declared explicitly, and importing Koa's loose Context type is disallowed by lint. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016MJXFeUxvU46KyvKnP8sXf --------- Co-authored-by: Claude <noreply@anthropic.com>
96 lines
2.5 KiB
TypeScript
96 lines
2.5 KiB
TypeScript
import { TeamPreference } from "@shared/types";
|
|
import { parseDomain } from "@shared/utils/domains";
|
|
import env from "@server/env";
|
|
import { Integration, type Team } from "@server/models";
|
|
import { getSessionRedirectUrl } from "@server/utils/authentication";
|
|
import { SessionsCookieHelper } from "@server/utils/SessionsCookieHelper";
|
|
import type { AppRenderOptions } from "./app";
|
|
import type { AppContext } from "@server/types";
|
|
|
|
/**
|
|
* Returns the URL to redirect an app request to when the request did not
|
|
* arrive on the canonical host of a usable workspace. When no workspace is
|
|
* found, the sessions cookie is reconciled.
|
|
*
|
|
* @param ctx the request context.
|
|
* @param team the workspace for the request host, if any.
|
|
* @returns the URL to redirect to, or undefined to render the app.
|
|
*/
|
|
export async function getWorkspaceRedirectUrl(
|
|
ctx: AppContext,
|
|
team: Team | null | undefined
|
|
): Promise<string | undefined> {
|
|
if (!env.isCloudHosted) {
|
|
return;
|
|
}
|
|
|
|
if (team && !team.isSuspended) {
|
|
if (team.isTeamUrl(ctx.href)) {
|
|
return;
|
|
}
|
|
|
|
const url = new URL(team.url);
|
|
url.pathname = ctx.path;
|
|
url.search = ctx.search;
|
|
return url.toString();
|
|
}
|
|
|
|
if (env.isProduction && ctx.hostname !== parseDomain(env.URL).host) {
|
|
return env.URL;
|
|
}
|
|
|
|
if (team) {
|
|
return;
|
|
}
|
|
|
|
const teams = await SessionsCookieHelper.reconcile(ctx);
|
|
|
|
// Links to app paths on the root domain, such as those in emails, are sent
|
|
// on to the workspace the browser is signed in to.
|
|
if (isPublicAppPath(ctx.path)) {
|
|
return;
|
|
}
|
|
|
|
return getSessionRedirectUrl(ctx, teams);
|
|
}
|
|
|
|
/**
|
|
* Returns the options used to render the app shell for a workspace.
|
|
*
|
|
* @param team the workspace for the request host, if any.
|
|
* @returns the render options.
|
|
*/
|
|
export async function getWorkspaceRenderOptions(
|
|
team: Team | null | undefined
|
|
): Promise<AppRenderOptions> {
|
|
const analytics = await Integration.findAnalyticsIntegrationsForTeam(
|
|
team?.id
|
|
);
|
|
|
|
if (!team?.getPreference(TeamPreference.PublicBranding)) {
|
|
return { analytics };
|
|
}
|
|
|
|
return {
|
|
analytics,
|
|
title: team.name || undefined,
|
|
description: team.description || undefined,
|
|
shortcutIcon: team.avatarUrl
|
|
? ((await team.publicAvatarUrl()) ?? undefined)
|
|
: undefined,
|
|
};
|
|
}
|
|
|
|
// Client routes that render without an authenticated session.
|
|
const publicAppPaths = [
|
|
"/",
|
|
"/create",
|
|
"/logout",
|
|
"/desktop-redirect",
|
|
"/oauth/authorize",
|
|
];
|
|
|
|
function isPublicAppPath(pathname: string) {
|
|
return publicAppPaths.includes(pathname.replace(/\/+$/, "") || "/");
|
|
}
|