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

fix(V3): Edit team config fails with global & project level present #3138

Merged
merged 10 commits into from
Oct 3, 2024
1 change: 1 addition & 0 deletions packages/zowe-explorer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ All notable changes to the "vscode-extension-for-zowe" extension will be documen
- Fixed issue where Search operation did not prompt for credentials if profile contains expired token. [#2259](https://github.com/zowe/zowe-explorer-vscode/issues/2259)
- Fixed issue where inactive status was not displayed for profiles loaded from Global Config. [#3134](https://github.com/zowe/zowe-explorer-vscode/issues/3134)
- Fixed issue where switching from token-based authentication to user/password would cause an error for nested profiles. [#3142](https://github.com/zowe/zowe-explorer-vscode/issues/3142)
- Fixed issue seen editing team configuration when global and project level team configuration exists. [#3125](https://github.com/zowe/zowe-explorer-vscode/issues/3125)
t1m0thyj marked this conversation as resolved.
Show resolved Hide resolved

## `3.0.0-next.202409132122`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
} from "../../__mocks__/mockCreators/shared";
import { createDatasetSessionNode, createDatasetTree } from "../../__mocks__/mockCreators/datasets";
import { createProfileManager } from "../../__mocks__/mockCreators/profiles";
import { imperative, Gui, ZoweTreeNode, ZoweVsCodeExtension, IZoweTree, IZoweTreeNode, Validation } from "@zowe/zowe-explorer-api";
import { imperative, Gui, ZoweTreeNode, ZoweVsCodeExtension, IZoweTree, IZoweTreeNode, Validation, FileManagement } from "@zowe/zowe-explorer-api";
import { Profiles } from "../../../src/configuration/Profiles";
import { ZoweExplorerExtender } from "../../../src/extending/ZoweExplorerExtender";
import { ZoweExplorerApiRegister } from "../../../src/extending/ZoweExplorerApiRegister";
Expand Down Expand Up @@ -403,6 +403,7 @@ describe("Profiles Unit Tests - Function editZoweConfigFile", () => {

const spyQuickPick = jest.spyOn(Gui, "showQuickPick");
spyQuickPick.mockResolvedValueOnce("Global: in the Zowe home directory" as any);
jest.spyOn(FileManagement, "getZoweDir").mockReturnValue("file://globalPath/.zowe");
const spyOpenFile = jest.spyOn(globalMocks.mockProfileInstance, "openConfigFile");
await Profiles.getInstance().editZoweConfigFile();
expect(spyQuickPick).toHaveBeenCalled();
Expand Down
22 changes: 14 additions & 8 deletions packages/zowe-explorer/src/configuration/Profiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,16 @@

public async editZoweConfigFile(): Promise<void> {
ZoweLogger.trace("Profiles.editZoweConfigFile called.");
const existingLayers = await this.getConfigLayers();
const configLayers = await this.getConfigLayers();
const uniquePaths = new Set();
const existingLayers = configLayers.filter((layer) => {
const normalized = path.normalize(layer.path);
if (!uniquePaths.has(normalized)) {
uniquePaths.add(normalized);
return true;
}
return false;

Check warning on line 531 in packages/zowe-explorer/src/configuration/Profiles.ts

View check run for this annotation

Codecov / codecov/patch

packages/zowe-explorer/src/configuration/Profiles.ts#L531

Added line #L531 was not covered by tests
});
if (existingLayers.length === 1) {
await this.openConfigFile(existingLayers[0].path);
Gui.showMessage(this.manualEditMsg);
Expand All @@ -530,15 +539,15 @@
switch (choice) {
case "project":
for (const file of existingLayers) {
if (file.user) {
if (!file.global) {
await this.openConfigFile(file.path);
}
}
Gui.showMessage(this.manualEditMsg);
break;
case "global":
for (const file of existingLayers) {
if (file.global) {
if (file.path.includes(FileManagement.getZoweDir())) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the change on this line could be reverted to address Fernando's comment 😋

Suggested change
if (file.path.includes(FileManagement.getZoweDir())) {
if (file.global) {

await this.openConfigFile(file.path);
}
}
Expand Down Expand Up @@ -822,10 +831,7 @@
const configApi = profInfo.getTeamConfig();
const profAttrs = await this.getProfileFromConfig(profileName);
if (profAttrs.profLoc.jsonLoc) {
configApi.set(
`${profAttrs.profLoc.jsonLoc}.secure`,
loginTokenType?.startsWith("apimlAuthenticationToken") ? [] : ["tokenValue"]
);
configApi.set(`${profAttrs.profLoc.jsonLoc}.secure`, loginTokenType?.startsWith("apimlAuthenticationToken") ? [] : ["tokenValue"]);
}
configApi.delete(profInfo.mergeArgsForProfile(profAttrs).knownArgs.find((arg) => arg.argName === "user")?.argLoc.jsonLoc);
configApi.delete(profInfo.mergeArgsForProfile(profAttrs).knownArgs.find((arg) => arg.argName === "password")?.argLoc.jsonLoc);
Expand Down Expand Up @@ -1059,7 +1065,7 @@
public async openConfigFile(filePath: string): Promise<void> {
ZoweLogger.trace("Profiles.openConfigFile called.");
const document = await vscode.workspace.openTextDocument(filePath);
await Gui.showTextDocument(document);
await Gui.showTextDocument(document, { preview: false });
}

/**
Expand Down
Loading