fix: Organizations Admin improvements (#13656)
* Admin improvements * chore: improve spacing --------- Co-authored-by: Udit Takkar <[email protected]> Co-authored-by: Udit Takkar <[email protected]>
This commit is contained in:
5 files changed
+38
-16
No files matched your search
@@ -80,9 +80,13 @@ export const deleteDnsRecord = async (domain: string) => {
|
||||
assertCloudflareEnvVars(process.env);
|
||||
|
||||
const dnsRecordToDelete = await getDnsRecordToDelete();
|
||||
await deleteDnsRecord(dnsRecordToDelete);
|
||||
if (dnsRecordToDelete) {
|
||||
await deleteDnsRecord(dnsRecordToDelete);
|
||||
log.info(`Deleted dns-record in Cloudflare: ${domain}`);
|
||||
} else {
|
||||
log.info(`CNAME not found in Cloudflare: ${domain}. Nothing to delete`);
|
||||
}
|
||||
|
||||
log.info(`Deleted dns-record in Cloudflare: ${domain}`);
|
||||
return true;
|
||||
|
||||
async function getDnsRecordToDelete() {
|
||||
@@ -134,7 +138,7 @@ export const deleteDnsRecord = async (domain: string) => {
|
||||
});
|
||||
}
|
||||
|
||||
return searchResult.result[0];
|
||||
return searchResult.result[0] as (typeof searchResult.result)[0] | null;
|
||||
}
|
||||
|
||||
async function deleteDnsRecord(dnsRecordToDelete: { id: string }) {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { subdomainSuffix } from "@calcom/ee/organizations/lib/orgDomains";
|
||||
import logger from "@calcom/lib/logger";
|
||||
|
||||
import { deleteDnsRecord, addDnsRecord } from "./deploymentServices/cloudflare";
|
||||
import {
|
||||
@@ -6,6 +7,7 @@ import {
|
||||
createDomain as createVercelDomain,
|
||||
} from "./deploymentServices/vercel";
|
||||
|
||||
const log = logger.getSubLogger({ prefix: ["domainManager/organization"] });
|
||||
export const deleteDomain = async (slug: string) => {
|
||||
const domain = `${slug}.${subdomainSuffix()}`;
|
||||
// We must have some domain deleted
|
||||
@@ -22,6 +24,7 @@ export const deleteDomain = async (slug: string) => {
|
||||
isDnsRecordDeleted = await deleteDnsRecord(domain);
|
||||
}
|
||||
return isDomainDeleted && isDnsRecordDeleted;
|
||||
return false;
|
||||
};
|
||||
|
||||
export const createDomain = async (slug: string) => {
|
||||
@@ -48,6 +51,10 @@ export const renameDomain = async (oldSlug: string | null, newSlug: string) => {
|
||||
// First create new domain so that if it fails we still have the old domain
|
||||
await createDomain(newSlug);
|
||||
if (oldSlug) {
|
||||
await deleteDomain(oldSlug);
|
||||
try {
|
||||
await deleteDomain(oldSlug);
|
||||
} catch (e) {
|
||||
log.error(`renameDomain: Failed to delete old domain ${oldSlug}. Do a manual deletion if needed`);
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user