Skip to content

Commit 42d273f

Browse files
authored
Merge pull request #773 from PROCEED-Labs/iam-fixes
Routing Fixes
2 parents 5924857 + 1542eef commit 42d273f

9 files changed

Lines changed: 38 additions & 21 deletions

File tree

src/management-system-v2/app/(auth)/signin/page.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { getCurrentUser } from '@/components/auth';
33
import { redirect } from 'next/navigation';
44
import SignIn from './signin';
55
import { generateGuestReferenceToken } from '@/lib/reference-guest-user-token';
6-
import { env } from '@/lib/ms-config/env-vars';
76
import db from '@/lib/data/db';
87
import { connection } from 'next/server';
98
import { Suspense } from 'react';
9+
import { getMSConfig } from '@/lib/ms-config/ms-config';
1010

1111
const dayInMS = 1000 * 60 * 60 * 24;
1212

@@ -60,7 +60,8 @@ const Deferred: React.FC<{}> = async ({}) => {
6060
else userType = isGuest ? ('guest' as const) : ('user' as const);
6161

6262
let logoUrl;
63-
if (env.PROCEED_PUBLIC_IAM_ONLY_ONE_ORGANIZATIONAL_SPACE) {
63+
const config = await getMSConfig();
64+
if (config.PROCEED_PUBLIC_IAM_ONLY_ONE_ORGANIZATIONAL_SPACE) {
6465
const org = await db.space.findFirst({
6566
where: {
6667
isOrganization: true,

src/management-system-v2/app/(dashboard)/[environmentId]/layout.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { PropsWithChildren } from 'react';
22
import { getCurrentEnvironment, getCurrentUser, getSystemAdminRules } from '@/components/auth';
33
import { SetAbility } from '@/lib/abilityStore';
44
import Layout, { ExtendedMenuItems } from './layout-client';
5-
import { getUserOrganizationEnvironments } from '@/lib/data/db/iam/memberships';
5+
import { getUserOrganizationEnvironments, isMember } from '@/lib/data/db/iam/memberships';
66
import { MenuProps } from 'antd';
77

88
import {
@@ -49,6 +49,7 @@ import { env } from '@/lib/ms-config/env-vars';
4949
import { getUserPassword } from '@/lib/data/db/iam/users';
5050
import ActiveTasksBadge from '@/components/active-tasks-badge';
5151
import { syncOrganizationUsers } from '@/lib/data/db/machine-config';
52+
import { redirect } from 'next/navigation';
5253

5354
const DashboardLayout = async (
5455
props: PropsWithChildren<{ params: Promise<{ environmentId: string }> }>,
@@ -59,6 +60,14 @@ const DashboardLayout = async (
5960

6061
const { session, userId, systemAdmin, user } = await getCurrentUser();
6162

63+
let spaceId = decodeURIComponent(params.environmentId);
64+
if (spaceId === 'my') spaceId = userId;
65+
const isMemberInSpace = await isMember(spaceId, userId);
66+
67+
if (!isMemberInSpace) {
68+
return redirect('/start');
69+
}
70+
6271
const { activeEnvironment, ability } = await getCurrentEnvironment(params.environmentId);
6372
const can = ability.can.bind(ability);
6473

src/management-system-v2/app/(dashboard)/[environmentId]/machine-config/page.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,21 @@ import {
1313
} from '@/lib/data/db/machine-config';
1414
import ParentConfigList from './parent-config-list';
1515
import { Config } from '@/lib/data/machine-config-schema';
16-
import { env } from '@/lib/ms-config/env-vars';
1716
import UnauthorizedFallback from '@/components/unauthorized-fallback';
17+
import { getMSConfig } from '@/lib/ms-config/ms-config';
1818
export type ListItem = Config;
1919

2020
const MachineConfigPage = async ({
2121
params,
2222
}: {
2323
params: Promise<{ environmentId: string; folderId?: string }>;
2424
}) => {
25-
if (!env.PROCEED_PUBLIC_CONFIG_SERVER_ACTIVE) {
25+
const config = await getMSConfig();
26+
if (!config.PROCEED_PUBLIC_CONFIG_SERVER_ACTIVE) {
2627
return notFound();
2728
}
28-
const { environmentId } = await params;
2929

30+
const { environmentId } = await params;
3031
const { ability, activeEnvironment } = await getCurrentEnvironment(environmentId);
3132

3233
if (!ability.can('view', 'MachineConfig')) return <UnauthorizedFallback />;

src/management-system-v2/app/admin/users/page.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import UserTable from './user-table';
77
import { UserErrorType, userError } from '@/lib/user-error';
88
import Content from '@/components/content';
99
import { UserHasToDeleteOrganizationsError } from '@/lib/data/db/iam/users';
10-
import { env } from '@/lib/ms-config/env-vars';
10+
import { getMSConfig } from '@/lib/ms-config/ms-config';
1111

1212
async function deleteUsers(userIds: string[]) {
1313
'use server';
@@ -27,7 +27,8 @@ async function deleteUsers(userIds: string[]) {
2727
export type deleteUsers = typeof deleteUsers;
2828

2929
export default async function UsersPage() {
30-
if (!env.PROCEED_PUBLIC_IAM_ACTIVE) return notFound();
30+
const msConfig = await getMSConfig();
31+
if (!msConfig.PROCEED_PUBLIC_IAM_ACTIVE) return notFound();
3132

3233
const user = await getCurrentUser();
3334
if (!user.session) redirect('/');

src/management-system-v2/app/api/register-new-user/route.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
import db from '@/lib/data/db';
77
import { addUser, setUserPassword } from '@/lib/data/db/iam/users';
88
import { getTokenHash, notExpired } from '@/lib/email-verification-tokens/utils';
9-
import { env } from '@/lib/ms-config/env-vars';
9+
import { getMSConfig } from '@/lib/ms-config/ms-config';
1010

1111
// TODO: maybe add PRETTIER error handling
1212

@@ -65,12 +65,13 @@ export const GET = async (req: Request) => {
6565

6666
// NOTE: if the id of the email provider is changed, it also has to be changed in the
6767
// signinUrl
68-
const nextAuthEmailRedirect = new URL('/api/auth/callback/email', env.NEXTAUTH_URL!);
68+
const config = await getMSConfig();
69+
const nextAuthEmailRedirect = new URL('/api/auth/callback/email', config.NEXTAUTH_URL!);
6970
nextAuthEmailRedirect.searchParams.set('token', token);
7071
nextAuthEmailRedirect.searchParams.set('email', identifier);
7172
nextAuthEmailRedirect.searchParams.set(
7273
'callbackUrl',
73-
searchParams.get('callbackUrl') ?? env.NEXTAUTH_URL!,
74+
searchParams.get('callbackUrl') ?? config.NEXTAUTH_URL!,
7475
);
7576

7677
redirectUrl = nextAuthEmailRedirect.toString();

src/management-system-v2/app/api/spaces/[spaceId]/route.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import db from '@/lib/data/db';
2-
import { env } from '@/lib/ms-config/env-vars';
2+
import { getMSConfig } from '@/lib/ms-config/ms-config';
33
import { NextRequest, NextResponse } from 'next/server';
44

55
export async function GET(request: NextRequest, props: { params: Promise<{ spaceId: string }> }) {
66
const params = await props.params;
77

88
const { spaceId } = params;
99

10-
if (!env.PROCEED_PUBLIC_IAM_ACTIVE) {
10+
const config = await getMSConfig();
11+
if (!config.PROCEED_PUBLIC_IAM_ACTIVE) {
1112
return NextResponse.json({
1213
id: 'proceed-default-no-iam-user',
1314
type: 'personal',

src/management-system-v2/app/api/spaces/route.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { NextRequest, NextResponse } from 'next/server';
22
import db from '@/lib/data/db';
3-
import { env } from '@/lib/ms-config/env-vars';
3+
import { getMSConfig } from '@/lib/ms-config/ms-config';
44

55
export async function GET(request: NextRequest) {
6-
if (!env.PROCEED_PUBLIC_IAM_ACTIVE) {
6+
const config = await getMSConfig();
7+
if (!config.PROCEED_PUBLIC_IAM_ACTIVE) {
78
return NextResponse.json([
89
{ id: 'proceed-default-no-iam-user', type: 'personal', name: 'Default User' },
910
]);

src/management-system-v2/app/create-organization/page.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { addEnvironment } from '@/lib/data/db/iam/environments';
66
import { getErrorMessage, userError } from '@/lib/user-error';
77
import { getMSConfig } from '@/lib/ms-config/ms-config';
88
import { notFound } from 'next/navigation';
9-
import { env } from '@/lib/ms-config/env-vars';
109

1110
async function createInactiveEnvironment(data: UserOrganizationEnvironmentInput) {
1211
'use server';
@@ -26,9 +25,10 @@ export type createInactiveEnvironment = typeof createInactiveEnvironment;
2625
const unallowedProviders = ['guest-signin', 'development-users'];
2726

2827
const Page = async () => {
28+
const config = await getMSConfig();
2929
if (
30-
!env.PROCEED_PUBLIC_IAM_ACTIVE ||
31-
(await getMSConfig()).PROCEED_PUBLIC_IAM_ONLY_ONE_ORGANIZATIONAL_SPACE
30+
!config.PROCEED_PUBLIC_IAM_ACTIVE ||
31+
config.PROCEED_PUBLIC_IAM_ONLY_ONE_ORGANIZATIONAL_SPACE
3232
) {
3333
return notFound();
3434
}

src/management-system-v2/app/shared-viewer/page.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { getDefinitionsAndProcessIdForEveryCallActivity } from '@proceed/bpmn-he
2020

2121
import { SettingsOption } from './settings-modal';
2222
import { asyncMap } from '@/lib/helpers/javascriptHelpers';
23-
import { env } from '@/lib/ms-config/env-vars';
2423
import { ColorOptions } from '../(dashboard)/[environmentId]/(automation)/executions/[processId]/instance-coloring';
2524
import InstanceDocumentationPage from './instance-documentation-page';
2625
import { Metadata } from 'next';
@@ -30,6 +29,7 @@ import db from '@/lib/data/db';
3029
import { isUserErrorResponse } from '@/lib/user-error';
3130
import { getInstance } from '@/lib/data/instance';
3231
import { refetchDeployments } from '@/lib/executions/deployment-server-actions';
32+
import { getMSConfig } from '@/lib/ms-config/ms-config';
3333

3434
interface PageProps {
3535
searchParams: Promise<{
@@ -152,7 +152,8 @@ export async function generateMetadata(props: PageProps): Promise<Metadata> {
152152
if (typeof token !== 'string') return {};
153153

154154
try {
155-
const key = env.SHARING_ENCRYPTION_SECRET;
155+
const config = await getMSConfig();
156+
const key = config.SHARING_ENCRYPTION_SECRET;
156157
const { processId, timestamp, embeddedMode } = jwt.verify(token, key!) as TokenPayload;
157158
const versionId = version as string | undefined;
158159
const versionLabel = versionId ?? 'Latest';
@@ -221,7 +222,8 @@ const SharedViewer = async (props: PageProps) => {
221222
let activeSpaceId = userId || '';
222223
let activeIsOrg = false;
223224

224-
const key = env.SHARING_ENCRYPTION_SECRET;
225+
const config = await getMSConfig();
226+
const key = config.SHARING_ENCRYPTION_SECRET;
225227
let processData: Process | undefined;
226228
let iframeMode;
227229
let defaultSettings = settings as SettingsOption;

0 commit comments

Comments
 (0)