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 { 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;
|
||||
|
||||
@ -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');
|
||||
}
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user