Skip to content

Commit

Permalink
Merge pull request #3138 from zowe/fix/editTeamConfig
Browse files Browse the repository at this point in the history
fix(V3): Edit team config fails with global & project level present
  • Loading branch information
JillieBeanSim authored Oct 3, 2024
2 parents b43eccb + 99b0a65 commit 27836ed
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
2 changes: 2 additions & 0 deletions packages/zowe-explorer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ All notable changes to the "vscode-extension-for-zowe" extension will be documen
- Fixed issue where obsolete credentials persisted for PDS member nodes in Data Sets tree. [#3112](https://github.com/zowe/zowe-explorer-vscode/issues/3112)
- 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 the "Edit Profile" operation to open the correct files when both global and project team configs are present. [#3125](https://github.com/zowe/zowe-explorer-vscode/issues/3125)

## `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
20 changes: 13 additions & 7 deletions packages/zowe-explorer/src/configuration/Profiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,16 @@ export class Profiles extends ProfilesCache {

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;
});
if (existingLayers.length === 1) {
await this.openConfigFile(existingLayers[0].path);
Gui.showMessage(this.manualEditMsg);
Expand All @@ -530,7 +539,7 @@ export class Profiles extends ProfilesCache {
switch (choice) {
case "project":
for (const file of existingLayers) {
if (file.user) {
if (!file.global) {
await this.openConfigFile(file.path);
}
}
Expand Down Expand Up @@ -822,10 +831,7 @@ export class Profiles extends ProfilesCache {
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 @@ export class Profiles extends ProfilesCache {
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

0 comments on commit 27836ed

Please sign in to comment.