mirror of
https://github.com/passbolt/go-passbolt.git
synced 2025-05-10 09:58:21 +00:00
make update functions keep old value if passed ""
This commit is contained in:
parent
8381328ea9
commit
444a3d0583
2 changed files with 56 additions and 5 deletions
|
@ -84,9 +84,11 @@ func UpdateGroup(ctx context.Context, c *api.Client, groupID, name string, opera
|
|||
}
|
||||
|
||||
var currentMemberships []api.GroupMembership
|
||||
var currentName string
|
||||
for _, g := range groups {
|
||||
if g.ID == groupID {
|
||||
currentMemberships = g.GroupUsers
|
||||
currentName = g.Name
|
||||
break
|
||||
}
|
||||
}
|
||||
|
@ -100,6 +102,10 @@ func UpdateGroup(ctx context.Context, c *api.Client, groupID, name string, opera
|
|||
Secrets: []api.Secret{},
|
||||
}
|
||||
|
||||
if name == "" {
|
||||
request.Name = currentName
|
||||
}
|
||||
|
||||
// Generate Group Membership changes based on current Group Memberships
|
||||
for _, operation := range operations {
|
||||
membership, err := getMembershipByUserID(currentMemberships, operation.UserID)
|
||||
|
|
|
@ -147,21 +147,66 @@ func UpdateResource(ctx context.Context, c *api.Client, resourceID, name, userna
|
|||
ID: resourceID,
|
||||
// This needs to be specified or it will revert to a legacy password
|
||||
ResourceTypeID: resource.ResourceTypeID,
|
||||
Name: name,
|
||||
Username: username,
|
||||
URI: uri,
|
||||
Name: resource.Name,
|
||||
Username: resource.Username,
|
||||
URI: resource.URI,
|
||||
}
|
||||
|
||||
if name != "" {
|
||||
newResource.Name = name
|
||||
}
|
||||
if username != "" {
|
||||
newResource.Username = username
|
||||
}
|
||||
if uri != "" {
|
||||
newResource.URI = uri
|
||||
}
|
||||
|
||||
var secretData string
|
||||
switch rType.Slug {
|
||||
case "password-string":
|
||||
newResource.Description = resource.Description
|
||||
if description != "" {
|
||||
newResource.Description = description
|
||||
}
|
||||
if password != "" {
|
||||
secretData = password
|
||||
} else {
|
||||
secret, err := c.GetSecret(ctx, resourceID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Getting Secret: %w", err)
|
||||
}
|
||||
secretData, err = c.DecryptMessage(secret.Data)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Decrypting Secret: %w", err)
|
||||
}
|
||||
}
|
||||
case "password-and-description":
|
||||
tmp := api.SecretDataTypePasswordAndDescription{
|
||||
Password: password,
|
||||
Description: description,
|
||||
}
|
||||
if password != "" || description != "" {
|
||||
secret, err := c.GetSecret(ctx, resourceID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Getting Secret: %w", err)
|
||||
}
|
||||
oldSecretData, err := c.DecryptMessage(secret.Data)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Decrypting Secret: %w", err)
|
||||
}
|
||||
var oldSecret api.SecretDataTypePasswordAndDescription
|
||||
err = json.Unmarshal([]byte(oldSecretData), &oldSecret)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Parsing Decrypted Secret Data: %w", err)
|
||||
}
|
||||
if password == "" {
|
||||
tmp.Password = oldSecret.Password
|
||||
}
|
||||
if description == "" {
|
||||
tmp.Description = oldSecret.Description
|
||||
}
|
||||
}
|
||||
res, err := json.Marshal(&tmp)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Marshalling Secret Data: %w", err)
|
||||
|
|
Loading…
Add table
Reference in a new issue