Workspace creation - fix not found file during avatar picture copy (#12920)

Context :
Sentry error -
https://twenty-v7.sentry.io/issues/6563326453/?environment=prod&project=4507072499810304&query=is%3Aunresolved%20issue.priority%3A%5Bhigh%2C%20medium%5D&referrer=issue-stream&sort=date&stream_index=0

If a userWorkspace loses its default avatar picture (how can this
happen? This was spotted for twenty core team userWorkspaces, so it may
be very specific), the user can't create another workspace.

Test : 
- Create a workspace via a signup with a Google/Microsoft account having
a profile pic.
- Delete the profile pic in storage
- Try to create an other workspace
This commit is contained in:
Etienne
2025-06-27 13:35:42 +02:00
committed by GitHub
parent 3a9663e3e0
commit 8a7a86b3c6

View File

@ -6,6 +6,7 @@ import { APP_LOCALES, SOURCE_LOCALE } from 'twenty-shared/translations';
import { isDefined } from 'twenty-shared/utils';
import { IsNull, Not, Repository } from 'typeorm';
import { FileStorageExceptionCode } from 'src/engine/core-modules/file-storage/interfaces/file-storage-exception';
import { FileFolder } from 'src/engine/core-modules/file/interfaces/file-folder.interface';
import { DatabaseEventAction } from 'src/engine/api/graphql/graphql-query-runner/enums/database-event-action';
@ -368,14 +369,21 @@ export class UserWorkspaceService extends TypeOrmQueryService<UserWorkspace> {
if (!isDefined(userWorkspace?.defaultAvatarUrl)) return;
const [_, subFolder, filename] =
await this.fileService.copyFileFromWorkspaceToWorkspace(
userWorkspace.workspaceId,
userWorkspace.defaultAvatarUrl,
workspaceId,
);
try {
const [_, subFolder, filename] =
await this.fileService.copyFileFromWorkspaceToWorkspace(
userWorkspace.workspaceId,
userWorkspace.defaultAvatarUrl,
workspaceId,
);
return `${subFolder}/${filename}`;
return `${subFolder}/${filename}`;
} catch (error) {
if (error.code === FileStorageExceptionCode.FILE_NOT_FOUND) {
return;
}
throw error;
}
}
if (!isDefined(pictureUrl)) return;