From 8efd9648358def7491ede24fe67e27779280426c Mon Sep 17 00:00:00 2001 From: greenhandatsjtu <40566803+greenhandatsjtu@users.noreply.github.com> Date: Tue, 10 May 2022 17:37:12 +0800 Subject: [PATCH] fix: unchanged masked client_secret/password updated to `***` (#749) --- object/application.go | 6 +++++- object/organization.go | 8 ++++++-- object/provider.go | 9 ++++++++- object/syncer.go | 6 +++++- object/user.go | 3 +++ 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/object/application.go b/object/application.go index 485d0b63..ecf4143c 100644 --- a/object/application.go +++ b/object/application.go @@ -257,7 +257,11 @@ func UpdateApplication(id string, application *Application) bool { providerItem.Provider = nil } - affected, err := adapter.Engine.ID(core.PK{owner, name}).AllCols().Update(application) + session := adapter.Engine.ID(core.PK{owner, name}).AllCols() + if application.ClientSecret == "***" { + session.Omit("client_secret") + } + affected, err := session.Update(application) if err != nil { panic(err) } diff --git a/object/organization.go b/object/organization.go index cbad48ab..f8c2ca6c 100644 --- a/object/organization.go +++ b/object/organization.go @@ -128,7 +128,7 @@ func UpdateOrganization(id string, organization *Organization) bool { } } - if organization.MasterPassword != "" { + if organization.MasterPassword != "" && organization.MasterPassword != "***" { credManager := cred.GetCredManager(organization.PasswordType) if credManager != nil { hashedPassword := credManager.GetHashedPassword(organization.MasterPassword, "", organization.PasswordSalt) @@ -136,7 +136,11 @@ func UpdateOrganization(id string, organization *Organization) bool { } } - affected, err := adapter.Engine.ID(core.PK{owner, name}).AllCols().Update(organization) + session := adapter.Engine.ID(core.PK{owner, name}).AllCols() + if organization.MasterPassword == "***" { + session.Omit("master_password") + } + affected, err := session.Update(organization) if err != nil { panic(err) } diff --git a/object/provider.go b/object/provider.go index a41dc52c..4e05dad7 100644 --- a/object/provider.go +++ b/object/provider.go @@ -172,7 +172,14 @@ func UpdateProvider(id string, provider *Provider) bool { return false } - affected, err := adapter.Engine.ID(core.PK{owner, name}).AllCols().Update(provider) + session := adapter.Engine.ID(core.PK{owner, name}).AllCols() + if provider.ClientSecret == "***" { + session = session.Omit("client_secret") + } + if provider.ClientSecret2 == "***" { + session = session.Omit("client_secret2") + } + affected, err := session.Update(provider) if err != nil { panic(err) } diff --git a/object/syncer.go b/object/syncer.go index 9c46b9de..dcd0de6b 100644 --- a/object/syncer.go +++ b/object/syncer.go @@ -133,7 +133,11 @@ func UpdateSyncer(id string, syncer *Syncer) bool { return false } - affected, err := adapter.Engine.ID(core.PK{owner, name}).AllCols().Update(syncer) + session := adapter.Engine.ID(core.PK{owner, name}).AllCols() + if syncer.Password == "***" { + session.Omit("password") + } + affected, err := session.Update(syncer) if err != nil { panic(err) } diff --git a/object/user.go b/object/user.go index 33dfebc3..ef3c0f6f 100644 --- a/object/user.go +++ b/object/user.go @@ -314,6 +314,9 @@ func UpdateUser(id string, user *User, columns []string, isGlobalAdmin bool) boo return false } + if user.Password == "***" { + user.Password = oldUser.Password + } user.UpdateUserHash() if user.Avatar != oldUser.Avatar && user.Avatar != "" && user.PermanentAvatar != "*" {