fix(): avoid undefined workspaces with appToken when load availableWorkspaces (#12712)
This commit is contained in:
@ -5,7 +5,7 @@ import { Avatar } from 'twenty-ui/display';
|
|||||||
import { UndecoratedLink } from 'twenty-ui/navigation';
|
import { UndecoratedLink } from 'twenty-ui/navigation';
|
||||||
import { REACT_APP_SERVER_BASE_URL } from '~/config';
|
import { REACT_APP_SERVER_BASE_URL } from '~/config';
|
||||||
import { useRedirectToDefaultDomain } from '~/modules/domain-manager/hooks/useRedirectToDefaultDomain';
|
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 = {
|
type LogoProps = {
|
||||||
primaryLogo?: string | null;
|
primaryLogo?: string | null;
|
||||||
|
|||||||
@ -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) {
|
isDefaultSubdomain(subdomain: string) {
|
||||||
return subdomain === this.twentyConfigService.get('DEFAULT_SUBDOMAIN');
|
return subdomain === this.twentyConfigService.get('DEFAULT_SUBDOMAIN');
|
||||||
}
|
}
|
||||||
|
|||||||
@ -282,11 +282,11 @@ export class UserWorkspaceService extends TypeOrmQueryService<UserWorkspace> {
|
|||||||
await this.workspaceInvitationService.findInvitationsByEmail(email)
|
await this.workspaceInvitationService.findInvitationsByEmail(email)
|
||||||
)
|
)
|
||||||
.filter(
|
.filter(
|
||||||
({ workspaceId }) =>
|
({ workspace }) =>
|
||||||
![
|
![
|
||||||
...alreadyMemberWorkspacesIds,
|
...alreadyMemberWorkspacesIds,
|
||||||
...workspacesFromApprovedAccessDomainIds,
|
...workspacesFromApprovedAccessDomainIds,
|
||||||
].includes(workspaceId),
|
].includes(workspace.id),
|
||||||
)
|
)
|
||||||
.map((appToken) => ({
|
.map((appToken) => ({
|
||||||
workspace: appToken.workspace,
|
workspace: appToken.workspace,
|
||||||
|
|||||||
@ -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) {
|
async findInvitationsByEmail(email: string) {
|
||||||
return await this.appTokenRepository
|
return await this.appTokenRepository
|
||||||
.createQueryBuilder('appToken')
|
.createQueryBuilder('appToken')
|
||||||
|
.innerJoinAndSelect('appToken.workspace', 'workspace')
|
||||||
.where('"appToken".type = :type', {
|
.where('"appToken".type = :type', {
|
||||||
type: AppTokenType.InvitationToken,
|
type: AppTokenType.InvitationToken,
|
||||||
})
|
})
|
||||||
@ -113,7 +97,6 @@ export class WorkspaceInvitationService {
|
|||||||
.andWhere('appToken.expiresAt > :now', {
|
.andWhere('appToken.expiresAt > :now', {
|
||||||
now: new Date(),
|
now: new Date(),
|
||||||
})
|
})
|
||||||
.leftJoinAndSelect('appToken.workspace', 'workspace')
|
|
||||||
.getMany();
|
.getMany();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user