From 1eca82de6ca4a428b2726adc8cf8899740cba6d6 Mon Sep 17 00:00:00 2001 From: hamidreza abedi <92696830+hamidrabedi@users.noreply.github.com> Date: Sat, 10 Aug 2024 18:36:45 +0000 Subject: [PATCH] feat(add-modify): allow user to set custom owner instead of default (#122) * feat(application): add new fields with related structs to application * fix(add-modify): allow user to set custom owner instead of default * fix(user-modify): allow user to set custom owner for UserModify * test(cert) --- casdoorsdk/cert_test.go | 2 +- casdoorsdk/util_modify.go | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/casdoorsdk/cert_test.go b/casdoorsdk/cert_test.go index 4dbdc9c..11a8365 100644 --- a/casdoorsdk/cert_test.go +++ b/casdoorsdk/cert_test.go @@ -25,7 +25,7 @@ func TestCert(t *testing.T) { // Add a new object cert := &Cert{ - Owner: "admin", + Owner: TestCasdoorOrganization, Name: name, CreatedTime: GetCurrentTime(), DisplayName: name, diff --git a/casdoorsdk/util_modify.go b/casdoorsdk/util_modify.go index 0f4ccb4..038e417 100644 --- a/casdoorsdk/util_modify.go +++ b/casdoorsdk/util_modify.go @@ -23,7 +23,9 @@ import ( // modifyOrganization is an encapsulation of permission CUD(Create, Update, Delete) operations. // possible actions are `add-organization`, `update-organization`, `delete-organization`, func (c *Client) modifyOrganization(action string, organization *Organization, columns []string) (*Response, bool, error) { - organization.Owner = "admin" + if organization.Owner == "" { + organization.Owner = "admin" + } queryMap := map[string]string{ "id": fmt.Sprintf("%s/%s", organization.Owner, organization.Name), @@ -49,7 +51,9 @@ func (c *Client) modifyOrganization(action string, organization *Organization, c // modifyApplication is an encapsulation of permission CUD(Create, Update, Delete) operations. // possible actions are `add-application`, `update-application`, `delete-application`, func (c *Client) modifyApplication(action string, application *Application, columns []string) (*Response, bool, error) { - application.Owner = "admin" + if application.Owner == "" { + application.Owner = "admin" + } queryMap := map[string]string{ "id": fmt.Sprintf("%s/%s", application.Owner, application.Name), @@ -137,7 +141,9 @@ func (c *Client) modifyUserById(action string, id string, user *User, columns [] queryMap["columns"] = strings.Join(columns, ",") } - user.Owner = c.OrganizationName + if user.Owner == "" { + user.Owner = c.OrganizationName + } postBytes, err := json.Marshal(user) if err != nil { return nil, false, err @@ -212,7 +218,9 @@ func (c *Client) modifyCert(action string, cert *Cert, columns []string) (*Respo queryMap["columns"] = strings.Join(columns, ",") } - cert.Owner = c.OrganizationName + if cert.Owner == "" { + cert.Owner = c.OrganizationName + } postBytes, err := json.Marshal(cert) if err != nil { return nil, false, err