Skip to content

Commit 4b390e8

Browse files
committed
Decouple tables workspace user assignment from Openops organization user assignment
1 parent 5194d4e commit 4b390e8

3 files changed

Lines changed: 15 additions & 14 deletions

File tree

packages/server/api/src/app/authentication/basic/authentication-service.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import { AuthenticationResponse } from '@openops/shared';
33
import { userService } from '../../user/user-service';
44
import { getProjectAndToken } from '../context/create-project-auth-context';
55
import { createUser } from '../new-user/create-user';
6-
import { assignDefaultOrganization } from '../new-user/organization-assignment';
6+
import {
7+
addUserToDefaultWorkspace,
8+
assignDefaultOrganization,
9+
} from '../new-user/organization-assignment';
710
import { SignInParams, SignUpParams } from '../types';
811
import {
912
assertPasswordMatches,
@@ -17,6 +20,8 @@ export const authenticationService = {
1720

1821
await assignDefaultOrganization(user);
1922

23+
await addUserToDefaultWorkspace(user);
24+
2025
const projectContext = await getProjectAndToken(user, tablesRefreshToken);
2126
return buildAuthResponse(projectContext);
2227
},

packages/server/api/src/app/authentication/new-user/organization-assignment.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ export async function assignDefaultOrganization(user: User): Promise<void> {
3030
id: user.id,
3131
organizationId: organization.id,
3232
});
33+
}
3334

34-
const updatedUser = await userService.getOneOrThrow({ id: user.id });
35-
const project = await projectService.getOneForUser(updatedUser);
35+
export async function addUserToDefaultWorkspace(user: User): Promise<void> {
36+
const project = await projectService.getOneForUser(user);
3637

3738
if (isNil(project)) {
3839
throw new ApplicationError({
@@ -43,19 +44,10 @@ export async function assignDefaultOrganization(user: User): Promise<void> {
4344
});
4445
}
4546

46-
await addUserToDefaultWorkspace({
47-
email: user.email,
48-
workspaceId: project.tablesWorkspaceId,
49-
});
50-
}
51-
52-
async function addUserToDefaultWorkspace(values: {
53-
email: string;
54-
workspaceId: number;
55-
}): Promise<void> {
5647
const { token: defaultToken } = await authenticateAdminUserInOpenOpsTables();
5748

5849
await openopsTables.addUserToWorkspace(defaultToken, {
59-
...values,
50+
email: user.email,
51+
workspaceId: project.tablesWorkspaceId,
6052
});
6153
}

packages/shared/src/lib/user/user.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ export const User = Type.Object({
4242

4343
export type User = Static<typeof User>;
4444

45+
export type UserWithOrganization = User & {
46+
organizationId: OpenOpsId;
47+
};
48+
4549
export const UserMeta = Type.Object({
4650
id: Type.String(),
4751
email: Type.String(),

0 commit comments

Comments
 (0)