Skip to content

Commit

Permalink
fix(fdr): add support for transferring domain ownership (#1703)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi authored Oct 24, 2024
1 parent 8673464 commit 5c3e64b
Show file tree
Hide file tree
Showing 15 changed files with 276 additions and 1 deletion.
2 changes: 1 addition & 1 deletion fern/apis/fdr/definition/docs/v2/read/__package__.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ service:
indexSegmentId: string
response: GetSearchApiKeyForIndexSegmentResponse
errors:
- IndexSegmentNotFoundError
- IndexSegmentNotFoundError

types:
GetDocsConfigByIdResponse:
Expand Down
15 changes: 15 additions & 0 deletions fern/apis/fdr/definition/docs/v2/write/__package__.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,21 @@ service:
errors:
- DocsNotFoundError
- ReindexNotAllowedError

transferOwnershipOfDomain:
auth: true
method: POST
path: /transfer-ownership
request:
name: TransferDomainOwnershipRequest
body:
properties:
domain: string
toOrgId: string
errors:
- DocsNotFoundError
- rootCommons.UnauthorizedError

types:
ImageFilePath:
properties:
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions servers/fdr/src/__test__/local/services/ownership.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { DocsV1Write, FdrAPI } from "@fern-api/fdr-sdk";
import { inject } from "vitest";
import { getClient } from "../util";

it("change domain ownership", async () => {
const fdr = getClient({ authed: true, url: inject("url") });

const domain = `docs-${Math.random()}.fern.com`;

// register docs
await fdr.docs.v1.write.startDocsRegister({
orgId: FdrAPI.OrgId("fern"),
domain,
filepaths: [DocsV1Write.FilePath("logo.png"), DocsV1Write.FilePath("guides/guide.mdx")],
});

const response = await fdr.docs.v2.write.transferOwnershipOfDomain({
domain,
toOrgId: FdrAPI.OrgId("acme"),
});

if (!response.ok) {
throw new Error(`Failed to transfer ownership of domain: ${response.error}`);
}
expect(response.ok).toBe(true);

// verify ownership
const registerResponse = await fdr.docs.v1.write.startDocsRegister({
orgId: FdrAPI.OrgId("acme"),
domain,
filepaths: [DocsV1Write.FilePath("logo.png"), DocsV1Write.FilePath("guides/guide.mdx")],
});
if (!registerResponse.ok) {
throw new Error(`Failed to reregister domain: ${registerResponse.error}`);
}
});

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions servers/fdr/src/controllers/docs/v2/getDocsWriteV2Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,22 @@ export function getDocsWriteV2Service(app: FdrApplication): DocsV2WriteService {

res.send();
},
transferOwnershipOfDomain: async (req, res) => {
// only fern users can transfer domain ownership
await app.services.auth.checkUserBelongsToOrg({
authHeader: req.headers.authorization,
orgId: "fern",
});

const parsedUrl = ParsedBaseUrl.parse(req.body.domain);

await app.dao.docsV2().transferDomainOwner({
domain: parsedUrl.getFullUrl(),
toOrgId: req.body.toOrgId,
});

return res.send();
},
});
}

Expand Down
14 changes: 14 additions & 0 deletions servers/fdr/src/db/docs/DocsV2Dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,24 @@ export interface DocsV2Dao {
customOnly?: boolean;
domainSuffix: string;
}): Promise<DocsV2Read.ListAllDocsUrlsResponse>;

transferDomainOwner({ domain, toOrgId }: { domain: string; toOrgId: string }): Promise<void>;
}

export class DocsV2DaoImpl implements DocsV2Dao {
constructor(private readonly prisma: PrismaClient) {}

public async transferDomainOwner({ domain, toOrgId }: { domain: string; toOrgId: string }): Promise<void> {
await this.prisma.docsV2.updateMany({
where: {
domain,
},
data: {
orgID: toOrgId,
},
});
}

public async checkDomainsDontBelongToAnotherOrg(domains: string[], orgId: string): Promise<boolean> {
const matchedDomains = await this.prisma.docsV2.findMany({
select: {
Expand Down

0 comments on commit 5c3e64b

Please sign in to comment.