Skip to content

Conversation

brichet
Copy link
Collaborator

@brichet brichet commented May 19, 2025

This PR adds a setting for the field visibility, and a signal when this setting changes.

Updating this setting doesn't change anything in UI from the secrets manager itself.
Only the extensions that uses the secrets manager (and listen for this setting) can display or not some fields.

If the settings are hidden from page config, this setting is removed from the settings panel and cannot be updated (the value is locked). This should prevent third party extensions to modify the value to display the fields (and be able to read the values from the DOM).

@brichet brichet added the enhancement New feature or request label May 19, 2025
Copy link
Collaborator Author

@brichet brichet left a comment

Choose a reason for hiding this comment

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

I added some comments to simplify the review.

Comment on lines +29 to +33
// If the secret fields are hidden from constructor, this setting comes from
// PageConfig, we need to lock the fields visibility.
if (options.showSecretFields === false) {
Private.lockFieldsVisibility();
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Lock the visibility setting if it is explicitly false at startup (coming from page config)

Comment on lines +394 to +400
export function setSecretFieldsVisibility(value: boolean): boolean {
if (!fieldsVisibilityLocked && value !== secretFieldsVisibility) {
secretFieldsVisibility = value;
return true;
}
return false;
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do not update the visibility if locked.

Comment on lines +41 to +47
if (PageConfig.getOption('secretsManager-showFields') === 'false') {
showSecretFieldsConfig = false;
}

const manager = new SecretsManager({
showSecretFields: showSecretFieldsConfig
});
Copy link
Collaborator Author

@brichet brichet May 20, 2025

Choose a reason for hiding this comment

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

Read the page config and setup the fields visibility at instantiation if required, to lock the setting.

Comment on lines +53 to +56
if (!showSecretFieldsConfig) {
delete settings.schema.properties?.['ShowSecretFields'];
return;
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Remove the visibility setting from the schema if it locked.

@brichet brichet requested a review from trungleduc May 20, 2025 09:58
@brichet
Copy link
Collaborator Author

brichet commented May 20, 2025

cc. @afshin, I don't know why I can't add you to the reviewers from UI...


// Otherwise listen to it to update the field visibility.
const updateFieldVisibility = () => {
const showSecretField =
Copy link
Member

@trungleduc trungleduc May 20, 2025

Choose a reason for hiding this comment

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

Suggested change
const showSecretField =
if(!showSecretFieldsConfig ){
return;
}
const showSecretField =

Copy link
Collaborator Author

@brichet brichet May 20, 2025

Choose a reason for hiding this comment

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

Do you think this is necessary ?
This function shouldn't be called because of the return statement just above(on the same condition), and even if it is, that should not change anything because the settings is locked in the manager.

Copy link
Member

Choose a reason for hiding this comment

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

indeed!

@brichet
Copy link
Collaborator Author

brichet commented May 20, 2025

Thanks for the review

@brichet brichet merged commit 101d782 into jupyterlab-contrib:main May 20, 2025
7 checks passed
@brichet brichet deleted the fields_visibility_setting branch May 20, 2025 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants