feat: 编辑表单下私钥字段默认为空
This commit is contained in:
@@ -47,7 +47,7 @@ const showEditForm = async (key: SshKeyBasicInfo) => {
|
|||||||
const details = await sshKeysStore.fetchDecryptedSshKey(key.id);
|
const details = await sshKeysStore.fetchDecryptedSshKey(key.id);
|
||||||
if (details) {
|
if (details) {
|
||||||
formData.name = details.name;
|
formData.name = details.name;
|
||||||
formData.private_key = details.privateKey;
|
formData.private_key = ''; // Do not pre-fill private key, empty means no change
|
||||||
formData.passphrase = ''; // Do not pre-fill passphrase
|
formData.passphrase = ''; // Do not pre-fill passphrase
|
||||||
isAddEditFormVisible.value = true;
|
isAddEditFormVisible.value = true;
|
||||||
} else {
|
} else {
|
||||||
@@ -60,7 +60,7 @@ const showEditForm = async (key: SshKeyBasicInfo) => {
|
|||||||
// Handle form submission (add or edit)
|
// Handle form submission (add or edit)
|
||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
formError.value = null;
|
formError.value = null;
|
||||||
if (!formData.name || !formData.private_key) {
|
if (!formData.name || (!keyToEdit.value && !formData.private_key)) { // Private key is required only for new keys
|
||||||
formError.value = t('sshKeys.modal.errorRequiredFields');
|
formError.value = t('sshKeys.modal.errorRequiredFields');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -68,11 +68,20 @@ const handleSubmit = async () => {
|
|||||||
let success = false;
|
let success = false;
|
||||||
const dataToSend: Partial<SshKeyInput> = {
|
const dataToSend: Partial<SshKeyInput> = {
|
||||||
name: formData.name,
|
name: formData.name,
|
||||||
private_key: formData.private_key,
|
|
||||||
// Only send passphrase if it's not empty
|
|
||||||
...(formData.passphrase && { passphrase: formData.passphrase }),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Add private_key to dataToSend only if it's provided by the user.
|
||||||
|
// In edit mode, an empty formData.private_key means the user does not want to change the key.
|
||||||
|
// In add mode, formData.private_key is guaranteed to be non-empty by the validation above.
|
||||||
|
if (formData.private_key) {
|
||||||
|
dataToSend.private_key = formData.private_key;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only send passphrase if it's not empty
|
||||||
|
if (formData.passphrase) {
|
||||||
|
dataToSend.passphrase = formData.passphrase;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (keyToEdit.value) {
|
if (keyToEdit.value) {
|
||||||
// Edit mode
|
// Edit mode
|
||||||
|
|||||||
Reference in New Issue
Block a user