fix: reset stale asset protocols on platform change#5399
Open
frederick-wang wants to merge 1 commit into
Open
Conversation
10ceeb4 to
d3865f0
Compare
d3865f0 to
2023202
Compare
|
Member
|
@frederick-wang 您描述的这个问题 经过测试确实复现了,当平台设置了 protocol 之后后续增加或减少的时候资产并不会同步它已经配置的资产,但是当前代码经过我测试我发现当我设置为支持 4 个协议后,资产与之配置 4个协议,Plateform 减少一个,不切换 Plateform 此时资产直接变为 1 个。因此这需要更多的一个考量 |
Member
|
@frederick-wang 如果可以请进一步补充更多的复现细节 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.







Problem
Changing the selected asset platform refreshes
protocols.el.choices, but the form intentionally does not clear the currentprotocolsvalue inupdatePlatformProtocols(). That preserves gateway-switch behavior, but it also meansProtocolSelectorcan keep protocol values from the previously selected platform.One reproducible case is a Windows asset form that starts from a platform exposing
rdpand then switches to a custom Windows OpenSSH platform exposing onlysshandsftp. The platform choices are updated correctly, but the selector can still carry the oldrdpitem and miss the new platform default such assftp.Root Cause
setDefaultItems()preferred existing asset protocol values wheneverthis.valuewas non-empty.getAssetDefaultItems()also returned the old item even when the new platform choices did not contain that protocol name. As a result, unsupported protocols could survive a platform change.Fix
In asset protocol mode (
settingReadonly), detect whether the current value contains protocol names that are absent from the new choices. If unsupported values are found, rebuild the selector items from the current platform defaults (required,primary, ordefault) instead of carrying stale values forward.If the existing values are still compatible with the new platform choices, the selector keeps them, including custom ports, and still adds missing required/primary protocols as before. This keeps the behavior needed by the existing gateway-switch comment while fixing platform changes that actually replace the protocol set.
This also drops absent protocols in
getAssetDefaultItems()and usesArray.isArray()/Set.has()to address the SonarCloud warnings on the changed lines.Tests
Added
ProtocolSelectorunit coverage for:rdp + sshvalues resetting tossh + sftpafter the platform choices changeValidated locally with:
npm_config_registry=https://registry.npmmirror.com npx -y yarn@1.22.22 install --frozen-lockfile --registry https://registry.npmmirror.com --network-timeout 600000./node_modules/.bin/eslint src/components/Form/FormFields/ProtocolSelector/index.vue tests/unit/components/ProtocolSelector.spec.jsgit diff --checknode:20-bullseyetargeted test:yarn test:unit tests/unit/components/ProtocolSelector.spec.jspassed with 4 testsNote: the full local
yarn test:unitsuite still has unrelated existing failures in this checkout: old Jest/Babel setup requires the Babel 7 bridge package, two utils specs import files that are not present atsrc/utils/index.jsandsrc/utils/validate.js, andBreadcrumb.spec.jsimports Element UI which pulls untransformedlodash-esESM. The newProtocolSelectorspec passes in the isolated Docker test environment.