Skip to content

Commit 54becf5

Browse files
committed
Fix bug where apps would sometimes disable automatically
1 parent 09a9686 commit 54becf5

2 files changed

Lines changed: 65 additions & 6 deletions

File tree

apps/backend/src/lib/projects.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,6 @@ export async function createOrUpdateProjectWithLegacyConfig(
223223
'rbac.defaultPermissions.teamMember': translateDefaultPermissions(dataOptions.team_member_default_permissions),
224224
'rbac.defaultPermissions.teamCreator': translateDefaultPermissions(dataOptions.team_creator_default_permissions),
225225
'rbac.defaultPermissions.signUp': translateDefaultPermissions(dataOptions.user_default_permissions),
226-
// ======================= apps =======================
227-
'apps.installed': {
228-
authentication: { enabled: true },
229-
emails: { enabled: true },
230-
"launch-checklist": { enabled: true },
231-
},
232226
});
233227

234228
if (options.type === "create") {
@@ -257,6 +251,10 @@ export async function createOrUpdateProjectWithLegacyConfig(
257251
configOverrideOverride['rbac.defaultPermissions.teamMember'] ??= { 'team_member': true };
258252

259253
configOverrideOverride['auth.password.allowSignIn'] ??= true;
254+
255+
configOverrideOverride['apps.installed.authentication.enabled'] ??= true;
256+
configOverrideOverride['apps.installed.emails.enabled'] ??= true;
257+
configOverrideOverride['apps.installed.api-keys.enabled'] ??= true;
260258
}
261259
await overrideEnvironmentConfigOverride({
262260
projectId: projectId,

apps/e2e/tests/backend/endpoints/api/v1/projects.test.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,3 +1532,64 @@ it("should increment and decrement userCount when a user is added to a project",
15321532
expect(finalProjectResponse.body.total_users).toBe(0);
15331533

15341534
});
1535+
1536+
it("should preserve API Keys app enabled state when updating allowUserApiKeys config", async ({ expect }) => {
1537+
await Auth.Otp.signIn();
1538+
const { adminAccessToken } = await Project.createAndGetAdminToken();
1539+
1540+
// Enable the API Keys app
1541+
const enableAppResponse = await niceBackendFetch("/api/v1/internal/config/override", {
1542+
accessType: "admin",
1543+
method: "PATCH",
1544+
headers: {
1545+
'x-stack-admin-access-token': adminAccessToken,
1546+
},
1547+
body: {
1548+
config_override_string: JSON.stringify({
1549+
'apps.installed.api-keys': {
1550+
enabled: true,
1551+
},
1552+
}),
1553+
},
1554+
});
1555+
expect(enableAppResponse).toMatchInlineSnapshot(`
1556+
NiceResponse {
1557+
"status": 200,
1558+
"body": {},
1559+
"headers": Headers { <some fields may have been hidden> },
1560+
}
1561+
`);
1562+
1563+
// Verify the API Keys app is enabled
1564+
const getConfigResponse1 = await niceBackendFetch("/api/v1/internal/config", {
1565+
accessType: "admin",
1566+
headers: {
1567+
'x-stack-admin-access-token': adminAccessToken,
1568+
},
1569+
});
1570+
expect(getConfigResponse1.status).toBe(200);
1571+
expect(JSON.parse(getConfigResponse1.body.config_string).apps.installed["api-keys"]).toMatchInlineSnapshot(`
1572+
{ "enabled": true }
1573+
`);
1574+
1575+
// Update allowUserApiKeys using the old project update endpoint
1576+
const { updateProjectResponse } = await Project.updateCurrent(adminAccessToken, {
1577+
config: {
1578+
allow_user_api_keys: true,
1579+
},
1580+
});
1581+
expect(updateProjectResponse.status).toBe(200);
1582+
expect(updateProjectResponse.body.config.allow_user_api_keys).toBe(true);
1583+
1584+
// Verify the API Keys app is still enabled after the update
1585+
const getConfigResponse2 = await niceBackendFetch("/api/v1/internal/config", {
1586+
accessType: "admin",
1587+
headers: {
1588+
'x-stack-admin-access-token': adminAccessToken,
1589+
},
1590+
});
1591+
expect(getConfigResponse2.status).toBe(200);
1592+
expect(JSON.parse(getConfigResponse2.body.config_string).apps.installed["api-keys"]).toMatchInlineSnapshot(`
1593+
{ "enabled": true }
1594+
`);
1595+
});

0 commit comments

Comments
 (0)