[WIP] Whole FE migrated (#2517)
* Wip * WIP * Removed concole log * Add relations to workspace init (#2511) * Add relations to workspace init * remove logs * update prefill * add missing isSystem * comment relation fields * Migrate v2 core models to graphql schema (#2509) * migrate v2 core models to graphql schema * Migrate to new workspace member schema * Continue work * migrated-main * Finished accountOwner nested field integration on companies * Introduce bug * Fix --------- Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com> Co-authored-by: Weiko <corentin@twenty.com>
This commit is contained in:
@ -130,7 +130,6 @@ export class AuthResolver {
|
||||
defaultFields: {
|
||||
User: {
|
||||
id: true,
|
||||
workspaceMember: { select: { allowImpersonation: true } },
|
||||
},
|
||||
},
|
||||
})
|
||||
@ -140,7 +139,6 @@ export class AuthResolver {
|
||||
assert(user.canImpersonate, 'User cannot impersonate', ForbiddenException);
|
||||
const select = prismaSelect.valueOf('user') as Prisma.UserSelect & {
|
||||
id: true;
|
||||
workspaceMember: { select: { allowImpersonation: true } };
|
||||
};
|
||||
|
||||
return this.authService.impersonate(impersonateInput.userId, select);
|
||||
|
||||
@ -63,11 +63,6 @@ export class GoogleAuthController {
|
||||
firstName: firstName ?? '',
|
||||
lastName: lastName ?? '',
|
||||
locale: 'en',
|
||||
settings: {
|
||||
create: {
|
||||
locale: 'en',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
workspaceId,
|
||||
|
||||
@ -88,7 +88,6 @@ export class AuthService {
|
||||
data: {
|
||||
email: signUpInput.email,
|
||||
passwordHash,
|
||||
locale: 'en',
|
||||
},
|
||||
} as Prisma.UserCreateArgs,
|
||||
workspace.id,
|
||||
@ -160,11 +159,6 @@ export class AuthService {
|
||||
userId: string,
|
||||
select: Prisma.UserSelect & {
|
||||
id: true;
|
||||
workspaceMember: {
|
||||
select: {
|
||||
allowImpersonation: true;
|
||||
};
|
||||
};
|
||||
},
|
||||
) {
|
||||
const user = await this.userService.findUnique({
|
||||
@ -175,11 +169,8 @@ export class AuthService {
|
||||
});
|
||||
|
||||
assert(user, "This user doesn't exist", NotFoundException);
|
||||
assert(
|
||||
user.workspaceMember?.allowImpersonation,
|
||||
'Impersonation not allowed',
|
||||
ForbiddenException,
|
||||
);
|
||||
|
||||
// Todo: check if workspace member can be impersonated
|
||||
|
||||
const accessToken = await this.tokenService.generateAccessToken(user.id);
|
||||
const refreshToken = await this.tokenService.generateRefreshToken(user.id);
|
||||
|
||||
@ -33,22 +33,19 @@ export class TokenService {
|
||||
|
||||
const user = await this.prismaService.client.user.findUnique({
|
||||
where: { id: userId },
|
||||
include: {
|
||||
workspaceMember: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
throw new NotFoundException('User is not found');
|
||||
}
|
||||
|
||||
if (!user.workspaceMember) {
|
||||
throw new ForbiddenException('User is not associated to a workspace');
|
||||
if (!user.defaultWorkspaceId) {
|
||||
throw new NotFoundException('User does not have a default workspace');
|
||||
}
|
||||
|
||||
const jwtPayload: JwtPayload = {
|
||||
sub: user.id,
|
||||
workspaceId: user.workspaceMember.workspaceId,
|
||||
workspaceId: user.defaultWorkspaceId,
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
|
||||
import { WebHookModule } from 'src/core/web-hook/web-hook.module';
|
||||
import { UserModule as UserV2Module } from 'src/coreV2/user/user.module';
|
||||
import { RefreshTokenModule as RefreshTokenV2Module } from 'src/coreV2/refresh-token/refresh-token.module';
|
||||
|
||||
import { UserModule } from './user/user.module';
|
||||
import { CommentModule } from './comment/comment.module';
|
||||
@ -34,6 +36,8 @@ import { ApiKeyModule } from './api-key/api-key.module';
|
||||
FavoriteModule,
|
||||
ApiKeyModule,
|
||||
WebHookModule,
|
||||
UserV2Module,
|
||||
RefreshTokenV2Module,
|
||||
],
|
||||
exports: [
|
||||
AuthModule,
|
||||
@ -48,6 +52,8 @@ import { ApiKeyModule } from './api-key/api-key.module';
|
||||
FavoriteModule,
|
||||
ApiKeyModule,
|
||||
WebHookModule,
|
||||
UserV2Module,
|
||||
RefreshTokenV2Module,
|
||||
],
|
||||
})
|
||||
export class CoreModule {}
|
||||
|
||||
@ -66,13 +66,6 @@ export class UserService {
|
||||
: await this.workspaceService.createDefaultWorkspace();
|
||||
|
||||
assert(workspace, 'workspace is missing', BadRequestException);
|
||||
|
||||
const userSettings = await this.prismaService.client.userSettings.create({
|
||||
data: { locale: 'en' },
|
||||
});
|
||||
|
||||
const settings = { connect: { id: userSettings.id } };
|
||||
|
||||
// Create user
|
||||
const user = await this.prismaService.client.user.upsert({
|
||||
where: {
|
||||
@ -80,17 +73,7 @@ export class UserService {
|
||||
},
|
||||
create: {
|
||||
...(args.data as Prisma.UserCreateInput),
|
||||
settings,
|
||||
|
||||
workspaceMember: {
|
||||
create: {
|
||||
workspace: {
|
||||
connect: { id: workspace.id },
|
||||
},
|
||||
settings,
|
||||
},
|
||||
},
|
||||
locale: 'en',
|
||||
defaultWorkspaceId: workspace.id,
|
||||
},
|
||||
update: {},
|
||||
...(args.select ? { select: args.select } : {}),
|
||||
|
||||
Reference in New Issue
Block a user