Fix wrong path used by backend (#14352)

After moving a section on the frontend, this broke the path that was
sent by email on the backend.
This kind of error comes back every ~2-3 month under different forms so
we need a more robust solution: I moved routes to the shared folder,
that way we will share one common source of truth between the frontend
and the backend.

Fixes #14343
This commit is contained in:
Félix Malfait
2025-09-08 16:07:13 +02:00
committed by GitHub
parent 894db2645a
commit 502bd07db9
243 changed files with 495 additions and 467 deletions
@@ -1,6 +1,8 @@
import { BadRequestException, Injectable } from '@nestjs/common';
import { type Request } from 'express';
import { SettingsPath } from 'twenty-shared/types';
import { getSettingsPath } from 'twenty-shared/utils';
import { CreateManyQueryFactory } from 'src/engine/api/rest/core/query-builder/factories/create-many-query.factory';
import { CreateVariablesFactory } from 'src/engine/api/rest/core/query-builder/factories/create-variables.factory';
@@ -70,7 +72,7 @@ export class CoreQueryBuilderFactory {
`No object was found for the workspace associated with this API key. You may generate a new one here ${this.domainManagerService
.buildWorkspaceURL({
workspace,
pathname: '/settings/apis',
pathname: getSettingsPath(SettingsPath.ApiWebhooks),
})
.toString()}`,
);
@@ -6,6 +6,8 @@ import crypto from 'crypto';
import { t } from '@lingui/core/macro';
import { render } from '@react-email/render';
import { SendApprovedAccessDomainValidation } from 'twenty-emails';
import { SettingsPath } from 'twenty-shared/types';
import { getSettingsPath } from 'twenty-shared/utils';
import { Repository } from 'typeorm';
import { ApprovedAccessDomain as ApprovedAccessDomainEntity } from 'src/engine/core-modules/approved-access-domain/approved-access-domain.entity';
@@ -59,7 +61,7 @@ export class ApprovedAccessDomainService {
const link = this.domainManagerService.buildWorkspaceURL({
workspace,
pathname: `settings/security`,
pathname: getSettingsPath(SettingsPath.Domains),
searchParams: {
wtdId: approvedAccessDomain.id,
validationToken: this.generateUniqueHash(approvedAccessDomain),
@@ -1,6 +1,8 @@
import { Test, type TestingModule } from '@nestjs/testing';
import { getRepositoryToken } from '@nestjs/typeorm';
import { SettingsPath } from 'twenty-shared/types';
import { getSettingsPath } from 'twenty-shared/utils';
import { type DeleteResult, type Repository } from 'typeorm';
import { ApprovedAccessDomain } from 'src/engine/core-modules/approved-access-domain/approved-access-domain.entity';
@@ -282,7 +284,7 @@ describe('ApprovedAccessDomainService', () => {
expect(domainManagerService.buildWorkspaceURL).toHaveBeenCalledWith({
workspace: workspace,
pathname: 'settings/security',
pathname: getSettingsPath(SettingsPath.Domains),
searchParams: { validationToken: expect.any(String) },
});
@@ -9,6 +9,8 @@ import {
import { InjectRepository } from '@nestjs/typeorm';
import { Response } from 'express';
import { SettingsPath } from 'twenty-shared/types';
import { getSettingsPath } from 'twenty-shared/utils';
import { Repository } from 'typeorm';
import {
@@ -115,7 +117,8 @@ export class GoogleAPIsAuthController {
this.domainManagerService
.buildWorkspaceURL({
workspace,
pathname: redirectLocation || '/settings/accounts',
pathname:
redirectLocation || getSettingsPath(SettingsPath.Accounts),
})
.toString(),
);
@@ -127,7 +130,7 @@ export class GoogleAPIsAuthController {
subdomain: this.twentyConfigService.get('DEFAULT_SUBDOMAIN'),
customDomain: null,
},
pathname: '/settings/accounts',
pathname: getSettingsPath(SettingsPath.Accounts),
}),
);
}
@@ -9,6 +9,8 @@ import {
import { InjectRepository } from '@nestjs/typeorm';
import { Response } from 'express';
import { AppPath, SettingsPath } from 'twenty-shared/types';
import { getSettingsPath } from 'twenty-shared/utils';
import { Repository } from 'typeorm';
import {
@@ -122,7 +124,8 @@ export class MicrosoftAPIsAuthController {
this.domainManagerService
.buildWorkspaceURL({
workspace,
pathname: redirectLocation || '/settings/accounts',
pathname:
redirectLocation || getSettingsPath(SettingsPath.Accounts),
})
.toString(),
);
@@ -134,7 +137,7 @@ export class MicrosoftAPIsAuthController {
subdomain: this.twentyConfigService.get('DEFAULT_SUBDOMAIN'),
customDomain: null,
},
pathname: '/verify',
pathname: AppPath.Verify,
}),
);
}
@@ -13,6 +13,7 @@ import { InjectRepository } from '@nestjs/typeorm';
import { generateServiceProviderMetadata } from '@node-saml/node-saml';
import { Response } from 'express';
import { AppPath } from 'twenty-shared/types';
import { Repository } from 'typeorm';
import {
@@ -162,7 +163,7 @@ export class SSOAuthController {
this.domainManagerService.getSubdomainAndCustomDomainFromWorkspaceFallbackOnDefaultSubdomain(
workspaceIdentityProvider?.workspace,
),
pathname: '/verify',
pathname: AppPath.Verify,
}),
);
}
@@ -9,6 +9,7 @@ import { render } from '@react-email/render';
import { addMilliseconds } from 'date-fns';
import ms from 'ms';
import { PasswordUpdateNotifyEmail } from 'twenty-emails';
import { AppPath } from 'twenty-shared/types';
import { isDefined } from 'twenty-shared/utils';
import { Repository } from 'typeorm';
@@ -527,7 +528,7 @@ export class AuthService {
}) {
const url = this.domainManagerService.buildWorkspaceURL({
workspace,
pathname: '/verify',
pathname: AppPath.Verify,
searchParams: {
loginToken,
...(billingCheckoutSessionState ? { billingCheckoutSessionState } : {}),
@@ -739,7 +740,7 @@ export class AuthService {
));
const url = this.domainManagerService.buildBaseUrl({
pathname: '/welcome',
pathname: AppPath.SignInUp,
searchParams: {
tokenPair: JSON.stringify({
accessOrWorkspaceAgnosticToken:
@@ -827,7 +828,7 @@ export class AuthService {
this.domainManagerService.getSubdomainAndCustomDomainFromWorkspaceFallbackOnDefaultSubdomain(
currentWorkspace,
),
pathname: '/verify',
pathname: AppPath.Verify,
});
}
}
@@ -10,6 +10,8 @@ import { addMilliseconds, differenceInMilliseconds } from 'date-fns';
import ms from 'ms';
import { PasswordResetLinkEmail } from 'twenty-emails';
import { type APP_LOCALES } from 'twenty-shared/translations';
import { AppPath } from 'twenty-shared/types';
import { getAppPath } from 'twenty-shared/utils';
import { IsNull, MoreThan, Repository } from 'typeorm';
import {
@@ -139,7 +141,9 @@ export class ResetPasswordService {
const link = this.domainManagerService.buildWorkspaceURL({
workspace,
pathname: `/reset-password/${resetToken.passwordResetToken}`,
pathname: getAppPath(AppPath.ResetPassword, {
passwordResetToken: resetToken.passwordResetToken,
}),
});
const emailData = {
@@ -8,6 +8,7 @@ import { addMilliseconds, differenceInMilliseconds } from 'date-fns';
import ms from 'ms';
import { SendEmailVerificationLinkEmail } from 'twenty-emails';
import { type APP_LOCALES } from 'twenty-shared/translations';
import { AppPath } from 'twenty-shared/types';
import { isDefined } from 'twenty-shared/utils';
import { Repository } from 'typeorm';
@@ -55,7 +56,7 @@ export class EmailVerificationService {
await this.emailVerificationTokenService.generateToken(userId, email);
const linkPathnameAndSearchParams = {
pathname: 'verify-email',
pathname: AppPath.VerifyEmail,
searchParams: {
emailVerificationToken,
email,
@@ -1,6 +1,7 @@
import { type ExecutionContext, Injectable } from '@nestjs/common';
import { type Request } from 'express';
import { AppPath } from 'twenty-shared/types';
import {
AuthException,
@@ -28,7 +29,7 @@ export class GuardRedirectService {
customDomain: string | null;
isCustomDomainEnabled?: boolean;
},
pathname = '/verify',
pathname = AppPath.Verify,
) {
if ('contextType' in context && context.contextType === 'graphql') {
throw error;
@@ -9,6 +9,8 @@ import { render } from '@react-email/render';
import { addMilliseconds } from 'date-fns';
import ms from 'ms';
import { SendInviteLinkEmail } from 'twenty-emails';
import { AppPath } from 'twenty-shared/types';
import { getAppPath } from 'twenty-shared/utils';
import { IsNull, Repository } from 'typeorm';
import {
@@ -278,7 +280,9 @@ export class WorkspaceInvitationService {
if (invitation.status === 'fulfilled') {
const link = this.domainManagerService.buildWorkspaceURL({
workspace,
pathname: `invite/${workspace?.inviteHash}`,
pathname: getAppPath(AppPath.Invite, {
workspaceInviteHash: workspace?.inviteHash,
}),
searchParams: invitation.value.isPersonalInvitation
? {
inviteToken: invitation.value.appToken.value,
@@ -12,8 +12,11 @@ import {
ToolSet,
type UserContent,
} from 'ai';
import { AppPath } from 'twenty-shared/types';
import { getAppPath } from 'twenty-shared/utils';
import { In, Repository } from 'typeorm';
import { AIBillingService } from 'src/engine/core-modules/ai/services/ai-billing.service';
import { AiModelRegistryService } from 'src/engine/core-modules/ai/services/ai-model-registry.service';
import { DomainManagerService } from 'src/engine/core-modules/domain-manager/services/domain-manager.service';
import { FileEntity } from 'src/engine/core-modules/file/entities/file.entity';
@@ -31,7 +34,6 @@ import { type RecordIdsByObjectMetadataNameSingularType } from 'src/engine/metad
import { WorkspacePermissionsCacheService } from 'src/engine/metadata-modules/workspace-permissions-cache/workspace-permissions-cache.service';
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
import { streamToBuffer } from 'src/utils/stream-to-buffer';
import { AIBillingService } from 'src/engine/core-modules/ai/services/ai-billing.service';
import { AgentToolGeneratorService } from './agent-tool-generator.service';
import { AgentEntity } from './agent.entity';
@@ -204,7 +206,11 @@ export class AgentExecutionService {
...record,
resourceUrl: this.domainManagerService.buildWorkspaceURL({
workspace,
pathname: `object/${recordsWithObjectMetadataNameSingular.objectMetadataNameSingular}/${record.id}`,
pathname: getAppPath(AppPath.RecordShowPage, {
objectNameSingular:
recordsWithObjectMetadataNameSingular.objectMetadataNameSingular,
objectRecordId: record.id,
}),
}),
};
});