Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[server] OrganizationService:Fix unpin for pinnedEditorVersions (don't use deepmerge but overwrite if set) #20646

Merged
merged 1 commit into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions components/server/src/orgs/organization-service.spec.db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { expectError } from "../test/expect-utils";
import { UserService } from "../user/user-service";
import { DefaultWorkspaceImageValidator } from "./default-workspace-image-validator";
import { SYSTEM_USER } from "../authorization/authorizer";
import { IDEService } from "../ide-service";

const expect = chai.expect;

Expand Down Expand Up @@ -47,6 +48,36 @@ describe("OrganizationService", async () => {
await validateDefaultWorkspaceImage(userId, imageRef);
}
});
// Setup
container.rebind<IDEService>(IDEService).toConstantValue({
getIDEConfig: async () => ({
supervisorImage: "foo",
ideOptions: {
options: {
code: {
orderKey: "00",
title: "VS Code",
type: "browser",
logo: "https://ide.gitpod.io/image/ide-logo/vscode.svg",
label: "Browser",
image: "bar",
latestImage: "baz",
versions: [{ version: "1.2.3" }],
},
intellij: {
orderKey: "01",
title: "Intellij",
type: "desktop",
logo: "https://ide.gitpod.io/image/ide-logo/intellij.svg",
label: "Desktop",
image: "bar",
latestImage: "baz",
versions: [{ version: "4.5.6" }],
},
},
},
}),
} as any as IDEService);
os = container.get(OrganizationService);
userService = container.get<UserService>(UserService);
owner = await userService.createUser({
Expand Down Expand Up @@ -519,6 +550,26 @@ describe("OrganizationService", async () => {
const failingInvite = await orgService.getOrCreateInvite(owner.id, anotherOrg.id);
await expectError(ErrorCodes.PERMISSION_DENIED, () => os.joinOrganization(member.id, failingInvite.id));
});

it("should update pinnedEditorVersions", async () => {
// Create a test organization
const myOrg = await os.createOrganization(adminId, "My Org");

// Test 1: Set specific pinned editor versions
const pinnedVersions = { code: "1.2.3", intellij: "4.5.6" };
await os.updateSettings(adminId, myOrg.id, { pinnedEditorVersions: pinnedVersions });

// Verify the settings were updated correctly
let settings = await os.getSettings(adminId, myOrg.id);
expect(settings.pinnedEditorVersions).to.deep.equal(pinnedVersions);

// Test 2: Unset all pinned versions by setting an empty object
await os.updateSettings(adminId, myOrg.id, { pinnedEditorVersions: {} });

// Verify all pinned versions were removed
settings = await os.getSettings(adminId, myOrg.id);
expect(settings.pinnedEditorVersions).to.deep.equal({});
});
});

async function createOrgOwnedUser(os: OrganizationService, organizationId: string) {
Expand Down
5 changes: 5 additions & 0 deletions components/server/src/orgs/organization-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,11 @@ export class OrganizationService {
settings.roleRestrictions = partialUpdate.roleRestrictions;
}

// pinnedEditorVersions is an exception: override if set
if (partialUpdate.pinnedEditorVersions !== undefined) {
settings.pinnedEditorVersions = partialUpdate.pinnedEditorVersions;
}

return settings;
};

Expand Down
Loading