MCPcopy Index your code
hub / github.com/CapSoftware/Cap / createSpace

Function createSpace

apps/web/actions/organization/create-space.ts:34–185  ·  view source on GitHub ↗
(
	formData: FormData,
)

Source from the content-addressed store, hash-verified

32}
33
34export async function createSpace(
35 formData: FormData,
36): Promise<CreateSpaceResponse> {
37 try {
38 const user = await getCurrentUser();
39
40 if (!user || !user.activeOrganizationId) {
41 return {
42 success: false,
43 error: "User not logged in or no active organization",
44 };
45 }
46
47 const name = formData.get("name") as string;
48 const passwordEnabled = formData.get("passwordEnabled") === "true";
49 const password = formData.get("password") as string | null;
50 const publicEnabled = formData.get("public") === "true";
51 const settings = getSpaceSettingsFromFormData(formData);
52 const canUseProFeatures = userIsPro(user);
53
54 if (!name) {
55 return {
56 success: false,
57 error: "Space name is required",
58 };
59 }
60
61 if (passwordEnabled && !password?.trim()) {
62 return {
63 success: false,
64 error: "Space password is required",
65 };
66 }
67
68 if (!canUseProFeatures && passwordEnabled) {
69 return {
70 success: false,
71 error: "Upgrade required to protect a space with a password",
72 };
73 }
74
75 if (!canUseProFeatures && hasProSpaceSettingsEnabled(settings)) {
76 return {
77 success: false,
78 error: "Upgrade required to change these viewer rules",
79 };
80 }
81
82 if (
83 publicEnabled &&
84 !(await isOrganizationOwnerPro(
85 Organisation.OrganisationId.make(user.activeOrganizationId),
86 ))
87 ) {
88 return {
89 success: false,
90 error: "Upgrade to Cap Pro to create a public collection link",
91 };

Callers

nothing calls this directly

Calls 7

userIsProFunction · 0.90
isOrganizationOwnerProFunction · 0.90
dbFunction · 0.90
hashPasswordFunction · 0.90
uploadSpaceIconFunction · 0.90

Tested by

no test coverage detected