fix: password not saved correctly when editing asset
This commit is contained in:
+13
-5
@@ -248,6 +248,11 @@ func (s assetService) UpdateById(id string, m maps.Map) error {
|
||||
return err
|
||||
}
|
||||
|
||||
existingAsset, err := repository.AssetRepository.FindById(context.TODO(), id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
switch item.AccountType {
|
||||
case "credential":
|
||||
item.Username = "-"
|
||||
@@ -261,9 +266,9 @@ func (s assetService) UpdateById(id string, m maps.Map) error {
|
||||
item.Username = "-"
|
||||
}
|
||||
if len(item.Passphrase) == 0 {
|
||||
item.Passphrase = "-"
|
||||
item.Passphrase = existingAsset.Passphrase
|
||||
}
|
||||
case "custom":
|
||||
case "password":
|
||||
item.PrivateKey = "-"
|
||||
item.Passphrase = "-"
|
||||
item.CredentialId = "-"
|
||||
@@ -271,7 +276,8 @@ func (s assetService) UpdateById(id string, m maps.Map) error {
|
||||
item.Username = "-"
|
||||
}
|
||||
if len(item.Password) == 0 {
|
||||
item.Password = "-"
|
||||
item.Password = existingAsset.Password
|
||||
item.Encrypted = existingAsset.Encrypted
|
||||
}
|
||||
}
|
||||
|
||||
@@ -287,8 +293,10 @@ func (s assetService) UpdateById(id string, m maps.Map) error {
|
||||
item.AccessGatewayId = "-"
|
||||
}
|
||||
|
||||
if err := s.Encrypt(&item, config.GlobalCfg.EncryptionPassword); err != nil {
|
||||
return err
|
||||
if item.Password != "" && item.Password != "-" && !item.Encrypted {
|
||||
if err := s.Encrypt(&item, config.GlobalCfg.EncryptionPassword); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return s.Transaction(context.Background(), func(ctx context.Context) error {
|
||||
|
||||
Reference in New Issue
Block a user