From aac6f65bf5940b8df49fa6f6ab3224854ba01f3f Mon Sep 17 00:00:00 2001 From: Thai Date: Fri, 10 Feb 2023 17:37:32 +0700 Subject: [PATCH] feat: update user by id (#56) * feat: update user by id * ID to id * ID to id --- casdoorsdk/base.go | 6 +++++- casdoorsdk/user.go | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/casdoorsdk/base.go b/casdoorsdk/base.go index 02bd282..71a9311 100644 --- a/casdoorsdk/base.go +++ b/casdoorsdk/base.go @@ -179,8 +179,12 @@ func DoPostBytesRaw(url string, contentType string, body io.Reader) ([]byte, err // modifyUser is an encapsulation of user CUD(Create, Update, Delete) operations. // possible actions are `add-user`, `update-user`, `delete-user`, func modifyUser(action string, user *User, columns []string) (*Response, bool, error) { + return modifyUserById(action, user.GetId(), user, columns) +} + +func modifyUserById(action string, id string, user *User, columns []string) (*Response, bool, error) { queryMap := map[string]string{ - "id": fmt.Sprintf("%s/%s", user.Owner, user.Name), + "id": id, } if len(columns) != 0 { diff --git a/casdoorsdk/user.go b/casdoorsdk/user.go index 15914b0..5df8022 100644 --- a/casdoorsdk/user.go +++ b/casdoorsdk/user.go @@ -314,6 +314,11 @@ func SetPassword(owner, name, oldPassword, newPassword string) (bool, error) { return resp.Status == "ok", nil } +func UpdateUserById(id string, user *User) (bool, error) { + _, affected, err := modifyUserById("update-user", id, user, nil) + return affected, err +} + func UpdateUser(user *User) (bool, error) { _, affected, err := modifyUser("update-user", user, nil) return affected, err @@ -338,3 +343,7 @@ func CheckUserPassword(user *User) (bool, error) { response, _, err := modifyUser("check-user-password", user, nil) return response.Status == "ok", err } + +func (u User) GetId() string { + return fmt.Sprintf("%s/%s", u.Owner, u.Name) +}