Fix bug where apps would sometimes disable automatically

This commit is contained in:
Konstantin Wohlwend 2025-10-28 00:19:50 -07:00
parent 09a9686878
commit 54becf5d9a
2 changed files with 65 additions and 6 deletions

View File

@ -223,12 +223,6 @@ export async function createOrUpdateProjectWithLegacyConfig(
'rbac.defaultPermissions.teamMember': translateDefaultPermissions(dataOptions.team_member_default_permissions),
'rbac.defaultPermissions.teamCreator': translateDefaultPermissions(dataOptions.team_creator_default_permissions),
'rbac.defaultPermissions.signUp': translateDefaultPermissions(dataOptions.user_default_permissions),
// ======================= apps =======================
'apps.installed': {
authentication: { enabled: true },
emails: { enabled: true },
"launch-checklist": { enabled: true },
},
});
if (options.type === "create") {
@ -257,6 +251,10 @@ export async function createOrUpdateProjectWithLegacyConfig(
configOverrideOverride['rbac.defaultPermissions.teamMember'] ??= { 'team_member': true };
configOverrideOverride['auth.password.allowSignIn'] ??= true;
configOverrideOverride['apps.installed.authentication.enabled'] ??= true;
configOverrideOverride['apps.installed.emails.enabled'] ??= true;
configOverrideOverride['apps.installed.api-keys.enabled'] ??= true;
}
await overrideEnvironmentConfigOverride({
projectId: projectId,

View File

@ -1532,3 +1532,64 @@ it("should increment and decrement userCount when a user is added to a project",
expect(finalProjectResponse.body.total_users).toBe(0);
});
it("should preserve API Keys app enabled state when updating allowUserApiKeys config", async ({ expect }) => {
await Auth.Otp.signIn();
const { adminAccessToken } = await Project.createAndGetAdminToken();
// Enable the API Keys app
const enableAppResponse = await niceBackendFetch("/api/v1/internal/config/override", {
accessType: "admin",
method: "PATCH",
headers: {
'x-stack-admin-access-token': adminAccessToken,
},
body: {
config_override_string: JSON.stringify({
'apps.installed.api-keys': {
enabled: true,
},
}),
},
});
expect(enableAppResponse).toMatchInlineSnapshot(`
NiceResponse {
"status": 200,
"body": {},
"headers": Headers { <some fields may have been hidden> },
}
`);
// Verify the API Keys app is enabled
const getConfigResponse1 = await niceBackendFetch("/api/v1/internal/config", {
accessType: "admin",
headers: {
'x-stack-admin-access-token': adminAccessToken,
},
});
expect(getConfigResponse1.status).toBe(200);
expect(JSON.parse(getConfigResponse1.body.config_string).apps.installed["api-keys"]).toMatchInlineSnapshot(`
{ "enabled": true }
`);
// Update allowUserApiKeys using the old project update endpoint
const { updateProjectResponse } = await Project.updateCurrent(adminAccessToken, {
config: {
allow_user_api_keys: true,
},
});
expect(updateProjectResponse.status).toBe(200);
expect(updateProjectResponse.body.config.allow_user_api_keys).toBe(true);
// Verify the API Keys app is still enabled after the update
const getConfigResponse2 = await niceBackendFetch("/api/v1/internal/config", {
accessType: "admin",
headers: {
'x-stack-admin-access-token': adminAccessToken,
},
});
expect(getConfigResponse2.status).toBe(200);
expect(JSON.parse(getConfigResponse2.body.config_string).apps.installed["api-keys"]).toMatchInlineSnapshot(`
{ "enabled": true }
`);
});