refacto(*): rename hostname to custom domain (#10100)
This commit is contained in:
@ -99,7 +99,7 @@ describe('AdminPanelService', () => {
|
||||
{
|
||||
provide: DomainManagerService,
|
||||
useValue: {
|
||||
getworkspaceUrls: jest.fn().mockReturnValue({
|
||||
getWorkspaceUrls: jest.fn().mockReturnValue({
|
||||
customUrl: undefined,
|
||||
subdomainUrl: 'https://twenty.twenty.com',
|
||||
}),
|
||||
|
||||
@ -74,7 +74,7 @@ export class AdminPanelService {
|
||||
return {
|
||||
workspace: {
|
||||
id: user.workspaces[0].workspace.id,
|
||||
workspaceUrls: this.domainManagerService.getworkspaceUrls(
|
||||
workspaceUrls: this.domainManagerService.getWorkspaceUrls(
|
||||
user.workspaces[0].workspace,
|
||||
),
|
||||
},
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
import { Field, ObjectType } from '@nestjs/graphql';
|
||||
|
||||
import { AuthToken } from 'src/engine/core-modules/auth/dto/token.entity';
|
||||
import { workspaceUrlsAndId } from 'src/engine/core-modules/workspace/dtos/workspace-subdomain-id.dto';
|
||||
import { WorkspaceUrlsAndId } from 'src/engine/core-modules/workspace/dtos/workspace-subdomain-id.dto';
|
||||
|
||||
@ObjectType()
|
||||
export class ImpersonateOutput {
|
||||
@Field(() => AuthToken)
|
||||
loginToken: AuthToken;
|
||||
|
||||
@Field(() => workspaceUrlsAndId)
|
||||
workspace: workspaceUrlsAndId;
|
||||
@Field(() => WorkspaceUrlsAndId)
|
||||
workspace: WorkspaceUrlsAndId;
|
||||
}
|
||||
|
||||
@ -234,7 +234,7 @@ export class AuthResolver {
|
||||
loginToken,
|
||||
workspace: {
|
||||
id: workspace.id,
|
||||
workspaceUrls: this.domainManagerService.getworkspaceUrls(workspace),
|
||||
workspaceUrls: this.domainManagerService.getWorkspaceUrls(workspace),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@ -118,7 +118,7 @@ export class GoogleAuthController {
|
||||
return res.redirect(
|
||||
this.guardRedirectService.getRedirectErrorUrlAndCaptureExceptions(
|
||||
err,
|
||||
this.guardRedirectService.getSubdomainAndHostnameFromWorkspace(
|
||||
this.guardRedirectService.getSubdomainAndCustomDomainFromWorkspace(
|
||||
currentWorkspace,
|
||||
),
|
||||
),
|
||||
|
||||
@ -119,7 +119,7 @@ export class MicrosoftAuthController {
|
||||
return res.redirect(
|
||||
this.guardRedirectService.getRedirectErrorUrlAndCaptureExceptions(
|
||||
err,
|
||||
this.guardRedirectService.getSubdomainAndHostnameFromWorkspace(
|
||||
this.guardRedirectService.getSubdomainAndCustomDomainFromWorkspace(
|
||||
currentWorkspace,
|
||||
),
|
||||
),
|
||||
|
||||
@ -157,7 +157,7 @@ export class SSOAuthController {
|
||||
return res.redirect(
|
||||
this.guardRedirectService.getRedirectErrorUrlAndCaptureExceptions(
|
||||
err,
|
||||
this.guardRedirectService.getSubdomainAndHostnameFromWorkspace(
|
||||
this.guardRedirectService.getSubdomainAndCustomDomainFromWorkspace(
|
||||
workspaceIdentityProvider?.workspace,
|
||||
),
|
||||
),
|
||||
|
||||
@ -7,7 +7,7 @@ import {
|
||||
IdentityProviderType,
|
||||
SSOIdentityProviderStatus,
|
||||
} from 'src/engine/core-modules/sso/workspace-sso-identity-provider.entity';
|
||||
import { workspaceUrls } from 'src/engine/core-modules/workspace/dtos/workspace-endpoints.dto';
|
||||
import { workspaceUrls } from 'src/engine/core-modules/workspace/dtos/workspace-urls.dto';
|
||||
|
||||
@ObjectType()
|
||||
class SSOConnection {
|
||||
@ -38,9 +38,6 @@ export class AvailableWorkspaceOutput {
|
||||
@Field(() => workspaceUrls)
|
||||
workspaceUrls: workspaceUrls;
|
||||
|
||||
@Field(() => String, { nullable: true })
|
||||
hostname?: string;
|
||||
|
||||
@Field(() => String, { nullable: true })
|
||||
logo?: string;
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { Field, ObjectType } from '@nestjs/graphql';
|
||||
|
||||
import { workspaceUrlsAndId } from 'src/engine/core-modules/workspace/dtos/workspace-subdomain-id.dto';
|
||||
import { WorkspaceUrlsAndId } from 'src/engine/core-modules/workspace/dtos/workspace-subdomain-id.dto';
|
||||
|
||||
import { AuthToken } from './token.entity';
|
||||
|
||||
@ -9,6 +9,6 @@ export class SignUpOutput {
|
||||
@Field(() => AuthToken)
|
||||
loginToken: AuthToken;
|
||||
|
||||
@Field(() => workspaceUrlsAndId)
|
||||
workspace: workspaceUrlsAndId;
|
||||
@Field(() => WorkspaceUrlsAndId)
|
||||
workspace: WorkspaceUrlsAndId;
|
||||
}
|
||||
|
||||
@ -30,7 +30,9 @@ export class EnterpriseFeaturesEnabledGuard implements CanActivate {
|
||||
this.guardRedirectService.dispatchErrorFromGuard(
|
||||
context,
|
||||
err,
|
||||
this.guardRedirectService.getSubdomainAndHostnameFromContext(context),
|
||||
this.guardRedirectService.getSubdomainAndCustomDomainFromContext(
|
||||
context,
|
||||
),
|
||||
);
|
||||
|
||||
return false;
|
||||
|
||||
@ -53,7 +53,9 @@ export class GoogleAPIsOauthExchangeCodeForTokenGuard extends AuthGuard(
|
||||
this.guardRedirectService.dispatchErrorFromGuard(
|
||||
context,
|
||||
err,
|
||||
this.guardRedirectService.getSubdomainAndHostnameFromContext(context),
|
||||
this.guardRedirectService.getSubdomainAndCustomDomainFromContext(
|
||||
context,
|
||||
),
|
||||
);
|
||||
|
||||
return false;
|
||||
|
||||
@ -71,7 +71,7 @@ export class GoogleAPIsOauthRequestCodeGuard extends AuthGuard('google-apis') {
|
||||
this.guardRedirectService.dispatchErrorFromGuard(
|
||||
context,
|
||||
err,
|
||||
this.guardRedirectService.getSubdomainAndHostnameFromWorkspace(
|
||||
this.guardRedirectService.getSubdomainAndCustomDomainFromWorkspace(
|
||||
workspace,
|
||||
),
|
||||
);
|
||||
|
||||
@ -51,7 +51,7 @@ export class GoogleOauthGuard extends AuthGuard('google') {
|
||||
this.guardRedirectService.dispatchErrorFromGuard(
|
||||
context,
|
||||
err,
|
||||
this.guardRedirectService.getSubdomainAndHostnameFromWorkspace(
|
||||
this.guardRedirectService.getSubdomainAndCustomDomainFromWorkspace(
|
||||
workspace,
|
||||
),
|
||||
);
|
||||
|
||||
@ -31,7 +31,9 @@ export class GoogleProviderEnabledGuard implements CanActivate {
|
||||
this.guardRedirectService.dispatchErrorFromGuard(
|
||||
context,
|
||||
err,
|
||||
this.guardRedirectService.getSubdomainAndHostnameFromContext(context),
|
||||
this.guardRedirectService.getSubdomainAndCustomDomainFromContext(
|
||||
context,
|
||||
),
|
||||
);
|
||||
|
||||
return false;
|
||||
|
||||
@ -57,7 +57,9 @@ export class MicrosoftAPIsOauthExchangeCodeForTokenGuard extends AuthGuard(
|
||||
AuthExceptionCode.INSUFFICIENT_SCOPES,
|
||||
)
|
||||
: error,
|
||||
this.guardRedirectService.getSubdomainAndHostnameFromContext(context),
|
||||
this.guardRedirectService.getSubdomainAndCustomDomainFromContext(
|
||||
context,
|
||||
),
|
||||
);
|
||||
|
||||
return false;
|
||||
|
||||
@ -72,7 +72,7 @@ export class MicrosoftAPIsOauthRequestCodeGuard extends AuthGuard(
|
||||
this.guardRedirectService.dispatchErrorFromGuard(
|
||||
context,
|
||||
err,
|
||||
this.guardRedirectService.getSubdomainAndHostnameFromWorkspace(
|
||||
this.guardRedirectService.getSubdomainAndCustomDomainFromWorkspace(
|
||||
workspace,
|
||||
),
|
||||
);
|
||||
|
||||
@ -39,7 +39,7 @@ export class MicrosoftOAuthGuard extends AuthGuard('microsoft') {
|
||||
this.guardRedirectService.dispatchErrorFromGuard(
|
||||
context,
|
||||
err,
|
||||
this.guardRedirectService.getSubdomainAndHostnameFromWorkspace(
|
||||
this.guardRedirectService.getSubdomainAndCustomDomainFromWorkspace(
|
||||
workspace,
|
||||
),
|
||||
);
|
||||
|
||||
@ -31,7 +31,9 @@ export class MicrosoftProviderEnabledGuard implements CanActivate {
|
||||
this.guardRedirectService.dispatchErrorFromGuard(
|
||||
context,
|
||||
err,
|
||||
this.guardRedirectService.getSubdomainAndHostnameFromContext(context),
|
||||
this.guardRedirectService.getSubdomainAndCustomDomainFromContext(
|
||||
context,
|
||||
),
|
||||
);
|
||||
|
||||
return false;
|
||||
|
||||
@ -80,7 +80,7 @@ export class OIDCAuthGuard extends AuthGuard('openidconnect') {
|
||||
this.guardRedirectService.dispatchErrorFromGuard(
|
||||
context,
|
||||
err,
|
||||
this.guardRedirectService.getSubdomainAndHostnameFromWorkspace(
|
||||
this.guardRedirectService.getSubdomainAndCustomDomainFromWorkspace(
|
||||
identityProvider?.workspace,
|
||||
),
|
||||
);
|
||||
|
||||
@ -14,30 +14,16 @@ import { SSOService } from 'src/engine/core-modules/sso/services/sso.service';
|
||||
import { GuardRedirectService } from 'src/engine/core-modules/guard-redirect/services/guard-redirect.service';
|
||||
import { SSOConfiguration } from 'src/engine/core-modules/sso/types/SSOConfigurations.type';
|
||||
import { WorkspaceSSOIdentityProvider } from 'src/engine/core-modules/sso/workspace-sso-identity-provider.entity';
|
||||
import { ExceptionHandlerService } from 'src/engine/core-modules/exception-handler/exception-handler.service';
|
||||
|
||||
@Injectable()
|
||||
export class SAMLAuthGuard extends AuthGuard('saml') {
|
||||
constructor(
|
||||
private readonly sSOService: SSOService,
|
||||
private readonly guardRedirectService: GuardRedirectService,
|
||||
private readonly exceptionHandlerService: ExceptionHandlerService,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
private getRelayStateByRequest(request: Request) {
|
||||
try {
|
||||
const relayStateRaw = request.body.RelayState || request.query.RelayState;
|
||||
|
||||
if (relayStateRaw) {
|
||||
return JSON.parse(relayStateRaw);
|
||||
}
|
||||
} catch (error) {
|
||||
this.exceptionHandlerService.captureExceptions(error);
|
||||
}
|
||||
}
|
||||
|
||||
async canActivate(context: ExecutionContext) {
|
||||
const request = context.switchToHttp().getRequest<Request>();
|
||||
|
||||
@ -63,7 +49,7 @@ export class SAMLAuthGuard extends AuthGuard('saml') {
|
||||
this.guardRedirectService.dispatchErrorFromGuard(
|
||||
context,
|
||||
err,
|
||||
this.guardRedirectService.getSubdomainAndHostnameFromWorkspace(
|
||||
this.guardRedirectService.getSubdomainAndCustomDomainFromWorkspace(
|
||||
identityProvider?.workspace,
|
||||
),
|
||||
);
|
||||
|
||||
@ -459,7 +459,7 @@ export class AuthService {
|
||||
billingCheckoutSessionState,
|
||||
}: {
|
||||
loginToken: string;
|
||||
workspace: Pick<Workspace, 'subdomain' | 'hostname'>;
|
||||
workspace: Pick<Workspace, 'subdomain' | 'customDomain'>;
|
||||
billingCheckoutSessionState?: string;
|
||||
}) {
|
||||
const url = this.domainManagerService.buildWorkspaceURL({
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { Field, ObjectType } from '@nestjs/graphql';
|
||||
|
||||
@ObjectType()
|
||||
class CustomHostnameVerification {
|
||||
class CustomDomainVerification {
|
||||
@Field(() => String)
|
||||
validationType: 'ownership' | 'ssl' | 'redirection';
|
||||
|
||||
@ -19,13 +19,13 @@ class CustomHostnameVerification {
|
||||
}
|
||||
|
||||
@ObjectType()
|
||||
export class CustomHostnameDetails {
|
||||
export class CustomDomainDetails {
|
||||
@Field(() => String)
|
||||
id: string;
|
||||
|
||||
@Field(() => String)
|
||||
hostname: string;
|
||||
customDomain: string;
|
||||
|
||||
@Field(() => [CustomHostnameVerification])
|
||||
records: Array<CustomHostnameVerification>;
|
||||
@Field(() => [CustomDomainVerification])
|
||||
records: Array<CustomDomainVerification>;
|
||||
}
|
||||
@ -9,8 +9,8 @@ import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
|
||||
import { DomainManagerService } from './domain-manager.service';
|
||||
|
||||
describe('DomainManagerService', () => {
|
||||
describe('getworkspaceUrls', () => {
|
||||
it('should return a URL containing the correct hostname if hostname is provided', () => {
|
||||
describe('getWorkspaceUrls', () => {
|
||||
it('should return a URL containing the correct customDomain if customDomain is provided', () => {
|
||||
jest
|
||||
.spyOn(environmentService, 'get')
|
||||
.mockImplementation((key: string) => {
|
||||
@ -22,9 +22,9 @@ describe('DomainManagerService', () => {
|
||||
return env[key];
|
||||
});
|
||||
|
||||
const result = domainManagerService.getworkspaceUrls({
|
||||
const result = domainManagerService.getWorkspaceUrls({
|
||||
subdomain: 'subdomain',
|
||||
hostname: 'custom-host.com',
|
||||
customDomain: 'custom-host.com',
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
@ -33,7 +33,7 @@ describe('DomainManagerService', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should return a URL containing the correct subdomain if hostname is not provided but subdomain is', () => {
|
||||
it('should return a URL containing the correct subdomain if customDomain is not provided but subdomain is', () => {
|
||||
jest
|
||||
.spyOn(environmentService, 'get')
|
||||
.mockImplementation((key: string) => {
|
||||
@ -45,9 +45,9 @@ describe('DomainManagerService', () => {
|
||||
return env[key];
|
||||
});
|
||||
|
||||
const result = domainManagerService.getworkspaceUrls({
|
||||
const result = domainManagerService.getWorkspaceUrls({
|
||||
subdomain: 'subdomain',
|
||||
hostname: undefined,
|
||||
customDomain: undefined,
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
@ -155,7 +155,7 @@ describe('DomainManagerService', () => {
|
||||
const result = domainManagerService.buildWorkspaceURL({
|
||||
workspace: {
|
||||
subdomain: 'test',
|
||||
hostname: undefined,
|
||||
customDomain: undefined,
|
||||
},
|
||||
});
|
||||
|
||||
@ -177,7 +177,7 @@ describe('DomainManagerService', () => {
|
||||
const result = domainManagerService.buildWorkspaceURL({
|
||||
workspace: {
|
||||
subdomain: 'test',
|
||||
hostname: undefined,
|
||||
customDomain: undefined,
|
||||
},
|
||||
pathname: '/path/to/resource',
|
||||
});
|
||||
@ -200,7 +200,7 @@ describe('DomainManagerService', () => {
|
||||
const result = domainManagerService.buildWorkspaceURL({
|
||||
workspace: {
|
||||
subdomain: 'test',
|
||||
hostname: undefined,
|
||||
customDomain: undefined,
|
||||
},
|
||||
searchParams: {
|
||||
foo: 'bar',
|
||||
|
||||
@ -9,7 +9,7 @@ import {
|
||||
DomainManagerException,
|
||||
DomainManagerExceptionCode,
|
||||
} from 'src/engine/core-modules/domain-manager/domain-manager.exception';
|
||||
import { CustomHostnameDetails } from 'src/engine/core-modules/domain-manager/dtos/custom-hostname-details';
|
||||
import { CustomDomainDetails } from 'src/engine/core-modules/domain-manager/dtos/custom-domain-details';
|
||||
import { generateRandomSubdomain } from 'src/engine/core-modules/domain-manager/utils/generate-random-subdomain';
|
||||
import { getSubdomainFromEmail } from 'src/engine/core-modules/domain-manager/utils/get-subdomain-from-email';
|
||||
import { getSubdomainNameFromDisplayName } from 'src/engine/core-modules/domain-manager/utils/get-subdomain-name-from-display-name';
|
||||
@ -78,7 +78,7 @@ export class DomainManagerService {
|
||||
}: {
|
||||
emailVerificationToken: string;
|
||||
email: string;
|
||||
workspace: Pick<Workspace, 'subdomain' | 'hostname'>;
|
||||
workspace: Pick<Workspace, 'subdomain' | 'customDomain'>;
|
||||
}) {
|
||||
return this.buildWorkspaceURL({
|
||||
workspace,
|
||||
@ -92,11 +92,11 @@ export class DomainManagerService {
|
||||
pathname,
|
||||
searchParams,
|
||||
}: {
|
||||
workspace: Pick<Workspace, 'subdomain' | 'hostname'>;
|
||||
workspace: Pick<Workspace, 'subdomain' | 'customDomain'>;
|
||||
pathname?: string;
|
||||
searchParams?: Record<string, string | number>;
|
||||
}) {
|
||||
const workspaceUrls = this.getworkspaceUrls(workspace);
|
||||
const workspaceUrls = this.getWorkspaceUrls(workspace);
|
||||
|
||||
const url = new URL(workspaceUrls.customUrl ?? workspaceUrls.subdomainUrl);
|
||||
|
||||
@ -115,7 +115,7 @@ export class DomainManagerService {
|
||||
return url;
|
||||
}
|
||||
|
||||
getSubdomainAndHostnameFromUrl = (url: string) => {
|
||||
getSubdomainAndCustomDomainFromUrl = (url: string) => {
|
||||
const { hostname: originHostname } = new URL(url);
|
||||
|
||||
const frontDomain = this.getFrontUrl().hostname;
|
||||
@ -129,7 +129,7 @@ export class DomainManagerService {
|
||||
isFrontdomain && !this.isDefaultSubdomain(subdomain)
|
||||
? subdomain
|
||||
: undefined,
|
||||
hostname: isFrontdomain ? undefined : originHostname,
|
||||
customDomain: isFrontdomain ? undefined : originHostname,
|
||||
};
|
||||
};
|
||||
|
||||
@ -147,7 +147,7 @@ export class DomainManagerService {
|
||||
|
||||
computeRedirectErrorUrl(
|
||||
errorMessage: string,
|
||||
workspace: Pick<Workspace, 'subdomain' | 'hostname'>,
|
||||
workspace: Pick<Workspace, 'subdomain' | 'customDomain'>,
|
||||
) {
|
||||
const url = this.buildWorkspaceURL({
|
||||
workspace,
|
||||
@ -201,11 +201,12 @@ export class DomainManagerService {
|
||||
return this.getDefaultWorkspace();
|
||||
}
|
||||
|
||||
const { subdomain, hostname } = this.getSubdomainAndHostnameFromUrl(origin);
|
||||
const { subdomain, customDomain } =
|
||||
this.getSubdomainAndCustomDomainFromUrl(origin);
|
||||
|
||||
if (!hostname && !subdomain) return;
|
||||
if (!customDomain && !subdomain) return;
|
||||
|
||||
const where = isDefined(hostname) ? { hostname } : { subdomain };
|
||||
const where = isDefined(customDomain) ? { customDomain } : { subdomain };
|
||||
|
||||
return (
|
||||
(await this.workspaceRepository.findOne({
|
||||
@ -236,10 +237,10 @@ export class DomainManagerService {
|
||||
return `${subdomain}${existingWorkspaceCount > 0 ? `-${Math.random().toString(36).substring(2, 10)}` : ''}`;
|
||||
}
|
||||
|
||||
async registerCustomHostname(hostname: string) {
|
||||
async registerCustomDomain(customDomain: string) {
|
||||
domainManagerValidator.isCloudflareInstanceDefined(this.cloudflareClient);
|
||||
|
||||
if (await this.getCustomHostnameDetails(hostname)) {
|
||||
if (await this.getCustomDomainDetails(customDomain)) {
|
||||
throw new DomainManagerException(
|
||||
'Hostname already registered',
|
||||
DomainManagerExceptionCode.HOSTNAME_ALREADY_REGISTERED,
|
||||
@ -248,7 +249,7 @@ export class DomainManagerService {
|
||||
|
||||
return await this.cloudflareClient.customHostnames.create({
|
||||
zone_id: this.environmentService.get('CLOUDFLARE_ZONE_ID'),
|
||||
hostname,
|
||||
hostname: customDomain,
|
||||
ssl: {
|
||||
method: 'txt',
|
||||
type: 'dv',
|
||||
@ -265,14 +266,14 @@ export class DomainManagerService {
|
||||
});
|
||||
}
|
||||
|
||||
async getCustomHostnameDetails(
|
||||
hostname: string,
|
||||
): Promise<CustomHostnameDetails | undefined> {
|
||||
async getCustomDomainDetails(
|
||||
customDomain: string,
|
||||
): Promise<CustomDomainDetails | undefined> {
|
||||
domainManagerValidator.isCloudflareInstanceDefined(this.cloudflareClient);
|
||||
|
||||
const response = await this.cloudflareClient.customHostnames.list({
|
||||
zone_id: this.environmentService.get('CLOUDFLARE_ZONE_ID'),
|
||||
hostname,
|
||||
hostname: customDomain,
|
||||
});
|
||||
|
||||
if (response.result.length === 0) {
|
||||
@ -282,12 +283,12 @@ export class DomainManagerService {
|
||||
if (response.result.length === 1) {
|
||||
return {
|
||||
id: response.result[0].id,
|
||||
hostname: response.result[0].hostname,
|
||||
customDomain: response.result[0].hostname,
|
||||
records: [
|
||||
response.result[0].ownership_verification,
|
||||
...(response.result[0].ssl?.validation_records ?? []),
|
||||
]
|
||||
.map<CustomHostnameDetails['records'][0] | undefined>(
|
||||
.map<CustomDomainDetails['records'][0] | undefined>(
|
||||
(record: Record<string, string>) => {
|
||||
if (!record) return;
|
||||
|
||||
@ -343,24 +344,23 @@ export class DomainManagerService {
|
||||
throw new Error('More than one custom hostname found in cloudflare');
|
||||
}
|
||||
|
||||
async updateCustomHostname(fromHostname: string, toHostname: string) {
|
||||
async updateCustomDomain(fromHostname: string, toHostname: string) {
|
||||
domainManagerValidator.isCloudflareInstanceDefined(this.cloudflareClient);
|
||||
|
||||
const fromCustomHostname =
|
||||
await this.getCustomHostnameDetails(fromHostname);
|
||||
const fromCustomHostname = await this.getCustomDomainDetails(fromHostname);
|
||||
|
||||
if (fromCustomHostname) {
|
||||
await this.deleteCustomHostname(fromCustomHostname.id);
|
||||
}
|
||||
|
||||
return this.registerCustomHostname(toHostname);
|
||||
return this.registerCustomDomain(toHostname);
|
||||
}
|
||||
|
||||
async deleteCustomHostnameByHostnameSilently(hostname: string) {
|
||||
async deleteCustomHostnameByHostnameSilently(customDomain: string) {
|
||||
domainManagerValidator.isCloudflareInstanceDefined(this.cloudflareClient);
|
||||
|
||||
try {
|
||||
const customHostname = await this.getCustomHostnameDetails(hostname);
|
||||
const customHostname = await this.getCustomDomainDetails(customDomain);
|
||||
|
||||
if (customHostname) {
|
||||
await this.cloudflareClient.customHostnames.delete(customHostname.id, {
|
||||
@ -380,15 +380,15 @@ export class DomainManagerService {
|
||||
});
|
||||
}
|
||||
|
||||
private getCustomWorkspaceEndpoint(hostname: string) {
|
||||
private getCustomWorkspaceUrl(customDomain: string) {
|
||||
const url = this.getFrontUrl();
|
||||
|
||||
url.hostname = hostname;
|
||||
url.hostname = customDomain;
|
||||
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
private getTwentyWorkspaceEndpoint(subdomain: string) {
|
||||
private getTwentyWorkspaceUrl(subdomain: string) {
|
||||
const url = this.getFrontUrl();
|
||||
|
||||
url.hostname = `${subdomain}.${url.hostname}`;
|
||||
@ -396,15 +396,15 @@ export class DomainManagerService {
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
getworkspaceUrls({
|
||||
getWorkspaceUrls({
|
||||
subdomain,
|
||||
hostname,
|
||||
}: Pick<Workspace, 'subdomain' | 'hostname'>) {
|
||||
customDomain,
|
||||
}: Pick<Workspace, 'subdomain' | 'customDomain'>) {
|
||||
return {
|
||||
customUrl: hostname
|
||||
? this.getCustomWorkspaceEndpoint(hostname)
|
||||
customUrl: customDomain
|
||||
? this.getCustomWorkspaceUrl(customDomain)
|
||||
: undefined,
|
||||
subdomainUrl: this.getTwentyWorkspaceEndpoint(subdomain),
|
||||
subdomainUrl: this.getTwentyWorkspaceUrl(subdomain),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ export class EmailVerificationService {
|
||||
async sendVerificationEmail(
|
||||
userId: string,
|
||||
email: string,
|
||||
workspace: Pick<Workspace, 'subdomain' | 'hostname'>,
|
||||
workspace: Pick<Workspace, 'subdomain' | 'customDomain'>,
|
||||
) {
|
||||
if (!this.environmentService.get('IS_EMAIL_VERIFICATION_REQUIRED')) {
|
||||
return { success: false };
|
||||
@ -83,7 +83,7 @@ export class EmailVerificationService {
|
||||
|
||||
async resendEmailVerificationToken(
|
||||
email: string,
|
||||
workspace: Pick<Workspace, 'subdomain' | 'hostname'>,
|
||||
workspace: Pick<Workspace, 'subdomain' | 'customDomain'>,
|
||||
) {
|
||||
if (!this.environmentService.get('IS_EMAIL_VERIFICATION_REQUIRED')) {
|
||||
throw new EmailVerificationException(
|
||||
|
||||
@ -20,7 +20,7 @@ export class GuardRedirectService {
|
||||
dispatchErrorFromGuard(
|
||||
context: ExecutionContext,
|
||||
error: Error | CustomException,
|
||||
workspace: { id?: string; subdomain: string; hostname?: string },
|
||||
workspace: { id?: string; subdomain: string; customDomain?: string },
|
||||
) {
|
||||
if ('contextType' in context && context.contextType === 'graphql') {
|
||||
throw error;
|
||||
@ -32,8 +32,8 @@ export class GuardRedirectService {
|
||||
.redirect(this.getRedirectErrorUrlAndCaptureExceptions(error, workspace));
|
||||
}
|
||||
|
||||
getSubdomainAndHostnameFromWorkspace(
|
||||
workspace?: Pick<Workspace, 'subdomain' | 'hostname'> | null,
|
||||
getSubdomainAndCustomDomainFromWorkspace(
|
||||
workspace?: Pick<Workspace, 'subdomain' | 'customDomain'> | null,
|
||||
) {
|
||||
if (!workspace) {
|
||||
return {
|
||||
@ -44,23 +44,23 @@ export class GuardRedirectService {
|
||||
return workspace;
|
||||
}
|
||||
|
||||
getSubdomainAndHostnameFromContext(context: ExecutionContext): {
|
||||
getSubdomainAndCustomDomainFromContext(context: ExecutionContext): {
|
||||
subdomain: string;
|
||||
hostname?: string;
|
||||
customDomain?: string;
|
||||
} {
|
||||
const request = context.switchToHttp().getRequest<Request>();
|
||||
|
||||
const subdomainAndHostnameFromReferer = request.headers.referer
|
||||
? this.domainManagerService.getSubdomainAndHostnameFromUrl(
|
||||
const subdomainAndCustomDomainFromReferer = request.headers.referer
|
||||
? this.domainManagerService.getSubdomainAndCustomDomainFromUrl(
|
||||
request.headers.referer,
|
||||
)
|
||||
: null;
|
||||
|
||||
return {
|
||||
subdomain:
|
||||
subdomainAndHostnameFromReferer?.subdomain ??
|
||||
subdomainAndCustomDomainFromReferer?.subdomain ??
|
||||
this.environmentService.get('DEFAULT_SUBDOMAIN'),
|
||||
hostname: subdomainAndHostnameFromReferer?.hostname,
|
||||
customDomain: subdomainAndCustomDomainFromReferer?.customDomain,
|
||||
};
|
||||
}
|
||||
|
||||
@ -76,7 +76,7 @@ export class GuardRedirectService {
|
||||
|
||||
getRedirectErrorUrlAndCaptureExceptions(
|
||||
err: Error | CustomException,
|
||||
workspace: { id?: string; subdomain: string; hostname?: string },
|
||||
workspace: { id?: string; subdomain: string; customDomain?: string },
|
||||
) {
|
||||
this.captureException(err, workspace.id);
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -182,7 +182,7 @@ export class UserWorkspaceService extends TypeOrmQueryService<UserWorkspace> {
|
||||
return user.workspaces.map<AvailableWorkspaceOutput>((userWorkspace) => ({
|
||||
id: userWorkspace.workspaceId,
|
||||
displayName: userWorkspace.workspace.displayName,
|
||||
workspaceUrls: this.domainManagerService.getworkspaceUrls(
|
||||
workspaceUrls: this.domainManagerService.getWorkspaceUrls(
|
||||
userWorkspace.workspace,
|
||||
),
|
||||
logo: userWorkspace.workspace.logo,
|
||||
|
||||
@ -5,7 +5,7 @@ import {
|
||||
IdentityProviderType,
|
||||
SSOIdentityProviderStatus,
|
||||
} from 'src/engine/core-modules/sso/workspace-sso-identity-provider.entity';
|
||||
import { workspaceUrls } from 'src/engine/core-modules/workspace/dtos/workspace-endpoints.dto';
|
||||
import { workspaceUrls } from 'src/engine/core-modules/workspace/dtos/workspace-urls.dto';
|
||||
|
||||
@ObjectType()
|
||||
export class SSOIdentityProvider {
|
||||
|
||||
@ -143,7 +143,7 @@ export class UpdateWorkspaceInput {
|
||||
@Matches(
|
||||
/^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9])$/,
|
||||
)
|
||||
hostname?: string;
|
||||
customDomain?: string;
|
||||
|
||||
@Field({ nullable: true })
|
||||
@IsString()
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import { Field, ObjectType } from '@nestjs/graphql';
|
||||
|
||||
import { workspaceUrls } from 'src/engine/core-modules/workspace/dtos/workspace-endpoints.dto';
|
||||
import { workspaceUrls } from 'src/engine/core-modules/workspace/dtos/workspace-urls.dto';
|
||||
|
||||
@ObjectType()
|
||||
export class workspaceUrlsAndId {
|
||||
export class WorkspaceUrlsAndId {
|
||||
@Field(() => workspaceUrls)
|
||||
workspaceUrls: workspaceUrls;
|
||||
|
||||
|
||||
@ -80,11 +80,11 @@ export class WorkspaceService extends TypeOrmQueryService<Workspace> {
|
||||
}
|
||||
}
|
||||
|
||||
private async setCustomDomain(workspace: Workspace, hostname: string) {
|
||||
private async setCustomDomain(workspace: Workspace, customDomain: string) {
|
||||
await this.isCustomDomainEnabled(workspace.id);
|
||||
|
||||
const existingWorkspace = await this.workspaceRepository.findOne({
|
||||
where: { hostname },
|
||||
where: { customDomain },
|
||||
});
|
||||
|
||||
if (existingWorkspace && existingWorkspace.id !== workspace.id) {
|
||||
@ -95,22 +95,22 @@ export class WorkspaceService extends TypeOrmQueryService<Workspace> {
|
||||
}
|
||||
|
||||
if (
|
||||
hostname &&
|
||||
workspace.hostname !== hostname &&
|
||||
isDefined(workspace.hostname)
|
||||
customDomain &&
|
||||
workspace.customDomain !== customDomain &&
|
||||
isDefined(workspace.customDomain)
|
||||
) {
|
||||
await this.domainManagerService.updateCustomHostname(
|
||||
workspace.hostname,
|
||||
hostname,
|
||||
await this.domainManagerService.updateCustomDomain(
|
||||
workspace.customDomain,
|
||||
customDomain,
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
hostname &&
|
||||
workspace.hostname !== hostname &&
|
||||
!isDefined(workspace.hostname)
|
||||
customDomain &&
|
||||
workspace.customDomain !== customDomain &&
|
||||
!isDefined(workspace.customDomain)
|
||||
) {
|
||||
await this.domainManagerService.registerCustomHostname(hostname);
|
||||
await this.domainManagerService.registerCustomDomain(customDomain);
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,14 +127,17 @@ export class WorkspaceService extends TypeOrmQueryService<Workspace> {
|
||||
|
||||
let customDomainRegistered = false;
|
||||
|
||||
if (payload.hostname === null && isDefined(workspace.hostname)) {
|
||||
if (payload.customDomain === null && isDefined(workspace.customDomain)) {
|
||||
await this.domainManagerService.deleteCustomHostnameByHostnameSilently(
|
||||
workspace.hostname,
|
||||
workspace.customDomain,
|
||||
);
|
||||
}
|
||||
|
||||
if (payload.hostname && workspace.hostname !== payload.hostname) {
|
||||
await this.setCustomDomain(workspace, payload.hostname);
|
||||
if (
|
||||
payload.customDomain &&
|
||||
workspace.customDomain !== payload.customDomain
|
||||
) {
|
||||
await this.setCustomDomain(workspace, payload.customDomain);
|
||||
customDomainRegistered = true;
|
||||
}
|
||||
|
||||
@ -145,9 +148,9 @@ export class WorkspaceService extends TypeOrmQueryService<Workspace> {
|
||||
});
|
||||
} catch (error) {
|
||||
// revert custom domain registration on error
|
||||
if (payload.hostname && customDomainRegistered) {
|
||||
if (payload.customDomain && customDomainRegistered) {
|
||||
this.domainManagerService
|
||||
.deleteCustomHostnameByHostnameSilently(payload.hostname)
|
||||
.deleteCustomHostnameByHostnameSilently(payload.customDomain)
|
||||
.catch((err) => {
|
||||
this.exceptionHandlerService.captureExceptions([err]);
|
||||
});
|
||||
|
||||
@ -124,7 +124,7 @@ export class Workspace {
|
||||
|
||||
@Field({ nullable: true })
|
||||
@Column({ unique: true, nullable: true })
|
||||
hostname?: string;
|
||||
customDomain?: string;
|
||||
|
||||
@Field()
|
||||
@Column({ default: true })
|
||||
|
||||
@ -43,8 +43,8 @@ import { WorkspaceAuthGuard } from 'src/engine/guards/workspace-auth.guard';
|
||||
import { GraphqlValidationExceptionFilter } from 'src/filters/graphql-validation-exception.filter';
|
||||
import { assert } from 'src/utils/assert';
|
||||
import { streamToBuffer } from 'src/utils/stream-to-buffer';
|
||||
import { CustomHostnameDetails } from 'src/engine/core-modules/domain-manager/dtos/custom-hostname-details';
|
||||
import { workspaceUrls } from 'src/engine/core-modules/workspace/dtos/workspace-endpoints.dto';
|
||||
import { CustomDomainDetails } from 'src/engine/core-modules/domain-manager/dtos/custom-domain-details';
|
||||
import { workspaceUrls } from 'src/engine/core-modules/workspace/dtos/workspace-urls.dto';
|
||||
|
||||
import { Workspace } from './workspace.entity';
|
||||
|
||||
@ -217,17 +217,17 @@ export class WorkspaceResolver {
|
||||
|
||||
@ResolveField(() => workspaceUrls)
|
||||
workspaceUrls(@Parent() workspace: Workspace) {
|
||||
return this.domainManagerService.getworkspaceUrls(workspace);
|
||||
return this.domainManagerService.getWorkspaceUrls(workspace);
|
||||
}
|
||||
|
||||
@Query(() => CustomHostnameDetails, { nullable: true })
|
||||
@Query(() => CustomDomainDetails, { nullable: true })
|
||||
@UseGuards(WorkspaceAuthGuard)
|
||||
async getCustomHostnameDetails(
|
||||
@AuthWorkspace() { hostname }: Workspace,
|
||||
): Promise<CustomHostnameDetails | undefined> {
|
||||
if (!hostname) return undefined;
|
||||
async getCustomDomainDetails(
|
||||
@AuthWorkspace() { customDomain }: Workspace,
|
||||
): Promise<CustomDomainDetails | undefined> {
|
||||
if (!customDomain) return undefined;
|
||||
|
||||
return await this.domainManagerService.getCustomHostnameDetails(hostname);
|
||||
return await this.domainManagerService.getCustomDomainDetails(customDomain);
|
||||
}
|
||||
|
||||
@Query(() => PublicWorkspaceDataOutput)
|
||||
@ -268,7 +268,7 @@ export class WorkspaceResolver {
|
||||
id: workspace.id,
|
||||
logo: workspaceLogoWithToken,
|
||||
displayName: workspace.displayName,
|
||||
workspaceUrls: this.domainManagerService.getworkspaceUrls(workspace),
|
||||
workspaceUrls: this.domainManagerService.getWorkspaceUrls(workspace),
|
||||
authProviders: getAuthProvidersByWorkspace({
|
||||
workspace,
|
||||
systemEnabledProviders,
|
||||
|
||||
Reference in New Issue
Block a user