Skip to content

Commit 303ad5d

Browse files
authored
Disallow opening Hidden classes using Open InterSystems Document... command (#1735)
1 parent 969b08d commit 303ad5d

File tree

1 file changed

+43
-15
lines changed

1 file changed

+43
-15
lines changed

src/utils/documentPicker.ts

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ export async function pickDocument(
311311

312312
return new Promise<string>((resolve) => {
313313
const quickPick = vscode.window.createQuickPick<DocumentPickerItem>();
314+
quickPick.prompt =
315+
"Select a package or folder to view its contents. Selecting '..' shows the previous level's contents. You may also type a full document name into the filter box and press 'Enter' to select that document.";
314316
quickPick.title = `${prompt ? prompt : "Select a document"} ${numberOfSteps ? `(${step}/${numberOfSteps})` : `in namespace '${api.ns}' on server '${api.serverId}'`}`;
315317
quickPick.ignoreFocusOut = true;
316318
quickPick.buttons = [
@@ -402,21 +404,47 @@ export async function pickDocument(
402404
doc.startsWith("%") && doc.split(".").length == 2 && doc.slice(-4) == ".cls"
403405
? `%Library.${doc.slice(1)}`
404406
: doc;
405-
api
406-
.headDoc(doc)
407-
.then(() => resolve(doc))
408-
.catch((error) => {
409-
vscode.window.showErrorMessage(
410-
error?.statusCode == 400
411-
? `'${doc}' is an invalid document name.`
412-
: error?.statusCode == 404
413-
? `Document '${doc}' does not exist.`
414-
: `Internal Server Error encountered trying to validate document '${doc}'.`,
415-
"Dismiss"
416-
);
417-
resolve(undefined);
418-
})
419-
.finally(() => quickPick.hide());
407+
if (doc.endsWith(".cls")) {
408+
// Use StudioOpenDialog for classes so we don't expose Hidden ones
409+
api
410+
.actionQuery("SELECT Name, Type FROM %Library.RoutineMgr_StudioOpenDialog(?,1,1,1,1,0,1,,0,1)", [doc])
411+
.then((data) => {
412+
if (data.result.content?.length) {
413+
// doc is the name of a class that exists and is visible by the user
414+
resolve(doc);
415+
} else {
416+
vscode.window.showErrorMessage(
417+
`Class '${doc.slice(0, -4)}' does not exist, or is Hidden.`,
418+
"Dismiss"
419+
);
420+
resolve(undefined);
421+
}
422+
})
423+
.catch(() => {
424+
vscode.window.showErrorMessage(
425+
`Internal Server Error encountered trying to validate class name '${doc.slice(0, -4)}'.`,
426+
"Dismiss"
427+
);
428+
resolve(undefined);
429+
})
430+
.finally(() => quickPick.hide());
431+
} else {
432+
api
433+
.headDoc(doc)
434+
.then(() => resolve(doc))
435+
.catch((error) => {
436+
vscode.window.showErrorMessage(
437+
error?.statusCode == 400
438+
? `'${doc}' is an invalid document name.`
439+
: error?.statusCode == 404
440+
? `Document '${doc}' does not exist.`
441+
: `Internal Server Error encountered trying to validate document '${doc}'.`,
442+
"Dismiss"
443+
);
444+
resolve(undefined);
445+
})
446+
.finally(() => quickPick.hide());
447+
}
420448
} else {
421449
// The document name came from an item so no validation is required
422450
resolve(doc);

0 commit comments

Comments
 (0)