fix(): avoid undefined workspaces with appToken when load availableWorkspaces (#12712)

This commit is contained in:
Antoine Moreaux
2025-06-18 18:39:06 +02:00
committed by GitHub
parent 3acdf369ab
commit 1bae411e58
4 changed files with 4 additions and 29 deletions

View File

@ -5,7 +5,7 @@ import { Avatar } from 'twenty-ui/display';
import { UndecoratedLink } from 'twenty-ui/navigation';
import { REACT_APP_SERVER_BASE_URL } from '~/config';
import { useRedirectToDefaultDomain } from '~/modules/domain-manager/hooks/useRedirectToDefaultDomain';
import { useReadDefaultDomainFromConfiguration } from '@/domain-manager/hooks/useReadDefaultDomainFromConfiguration';
import { useReadDefaultDomainFromConfiguration } from '~/modules/domain-manager/hooks/useReadDefaultDomainFromConfiguration';
type LogoProps = {
primaryLogo?: string | null;

View File

@ -112,14 +112,6 @@ export class DomainManagerService {
};
};
async getWorkspaceBySubdomainOrDefaultWorkspace(subdomain?: string) {
return subdomain
? await this.workspaceRepository.findOne({
where: { subdomain },
})
: await this.getDefaultWorkspace();
}
isDefaultSubdomain(subdomain: string) {
return subdomain === this.twentyConfigService.get('DEFAULT_SUBDOMAIN');
}

View File

@ -282,11 +282,11 @@ export class UserWorkspaceService extends TypeOrmQueryService<UserWorkspace> {
await this.workspaceInvitationService.findInvitationsByEmail(email)
)
.filter(
({ workspaceId }) =>
({ workspace }) =>
![
...alreadyMemberWorkspacesIds,
...workspacesFromApprovedAccessDomainIds,
].includes(workspaceId),
].includes(workspace.id),
)
.map((appToken) => ({
workspace: appToken.workspace,

View File

@ -85,26 +85,10 @@ export class WorkspaceInvitationService {
}
}
async findInvitationByWorkspaceSubdomainAndUserEmail({
subdomain,
email,
}: {
subdomain: string;
email: string;
}) {
const workspace =
await this.domainManagerService.getWorkspaceBySubdomainOrDefaultWorkspace(
subdomain,
);
if (!workspace) return;
return await this.getOneWorkspaceInvitation(workspace.id, email);
}
async findInvitationsByEmail(email: string) {
return await this.appTokenRepository
.createQueryBuilder('appToken')
.innerJoinAndSelect('appToken.workspace', 'workspace')
.where('"appToken".type = :type', {
type: AppTokenType.InvitationToken,
})
@ -113,7 +97,6 @@ export class WorkspaceInvitationService {
.andWhere('appToken.expiresAt > :now', {
now: new Date(),
})
.leftJoinAndSelect('appToken.workspace', 'workspace')
.getMany();
}