|
8 | 8 | groupPasswordDisableRequestSchema, |
9 | 9 | groupPasswordEnableRequestSchema, |
10 | 10 | groupPrivacyJoinRequestsPatchSchema, |
| 11 | + groupPrivacyPrivateRequestSchema, |
11 | 12 | groupPrivacyPublicRequestSchema, |
12 | 13 | healthResponseSchema, |
13 | 14 | userDefaultArrowPatchSchema, |
@@ -1673,6 +1674,78 @@ app.patch("/api/groups/:groupId/privacy/join-requests", async (c) => { |
1673 | 1674 | } |
1674 | 1675 | }); |
1675 | 1676 |
|
| 1677 | +app.post("/api/groups/:groupId/privacy/private", async (c) => { |
| 1678 | + const sessionEnv = getSessionEnv(c.env); |
| 1679 | + if (sessionEnv == null) { |
| 1680 | + return c.json(serviceUnavailableBody, 503); |
| 1681 | + } |
| 1682 | + const hyper = c.env.HYPERDRIVE; |
| 1683 | + if (hyper == null) { |
| 1684 | + return c.json( |
| 1685 | + { |
| 1686 | + code: "SERVICE_UNAVAILABLE" as const, |
| 1687 | + message: "HYPERDRIVE binding is not configured.", |
| 1688 | + }, |
| 1689 | + 503, |
| 1690 | + ); |
| 1691 | + } |
| 1692 | + |
| 1693 | + let bodyJson: unknown; |
| 1694 | + try { |
| 1695 | + bodyJson = await c.req.json(); |
| 1696 | + } catch { |
| 1697 | + return c.json({ code: "BAD_REQUEST", message: "Expected JSON body." }, 400); |
| 1698 | + } |
| 1699 | + |
| 1700 | + const parsed = groupPrivacyPrivateRequestSchema.safeParse(bodyJson); |
| 1701 | + if (!parsed.success) { |
| 1702 | + return c.json( |
| 1703 | + { |
| 1704 | + code: "VALIDATION_ERROR", |
| 1705 | + message: parsed.error.flatten().formErrors.join("; "), |
| 1706 | + }, |
| 1707 | + 400, |
| 1708 | + ); |
| 1709 | + } |
| 1710 | + |
| 1711 | + const db = getDbForConnectionString(hyper.connectionString); |
| 1712 | + const cookieHeader = c.req.header("Cookie"); |
| 1713 | + const groupId = c.req.param("groupId"); |
| 1714 | + |
| 1715 | + const payload = { |
| 1716 | + groupAccessKeyring: parsed.data.groupAccessKeyring, |
| 1717 | + groupEncryptedName: parsed.data.groupEncryptedName, |
| 1718 | + groupEncryptedContentKeyring: parsed.data.groupEncryptedContentKeyring, |
| 1719 | + groupPublicKeyring: parsed.data.groupPublicKeyring, |
| 1720 | + groupEncryptedPrivateKeyring: parsed.data.groupEncryptedPrivateKeyring, |
| 1721 | + groupMembers: parsed.data.groupMembers, |
| 1722 | + groupJoinInvitations: parsed.data.groupJoinInvitations, |
| 1723 | + groupJoinRequests: parsed.data.groupJoinRequests, |
| 1724 | + groupPages: parsed.data.groupPages, |
| 1725 | + }; |
| 1726 | + |
| 1727 | + try { |
| 1728 | + const { performGroupPrivacyMakePrivate } = await import("@deepnotes/session"); |
| 1729 | + await performGroupPrivacyMakePrivate({ |
| 1730 | + db, |
| 1731 | + env: sessionEnv, |
| 1732 | + accessCookie: readCookieHeader(cookieHeader, "accessToken"), |
| 1733 | + groupId, |
| 1734 | + payload, |
| 1735 | + }); |
| 1736 | + return c.body(null, 204); |
| 1737 | + } catch (e) { |
| 1738 | + const { SessionError } = await import("@deepnotes/session"); |
| 1739 | + if (e instanceof SessionError) { |
| 1740 | + return c.json( |
| 1741 | + { code: e.code, message: e.message }, |
| 1742 | + e.status as ContentfulStatusCode, |
| 1743 | + ); |
| 1744 | + } |
| 1745 | + throw e; |
| 1746 | + } |
| 1747 | +}); |
| 1748 | + |
1676 | 1749 | app.delete("/api/groups/:groupId", async (c) => { |
1677 | 1750 | const sessionEnv = getSessionEnv(c.env); |
1678 | 1751 | if (sessionEnv == null) { |
|
0 commit comments