Skip to content

Commit

Permalink
feat(add-modify): allow user to set custom owner instead of default (#…
Browse files Browse the repository at this point in the history
…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)
  • Loading branch information
hamidrabedi authored Aug 10, 2024
1 parent b893494 commit 1eca82d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion casdoorsdk/cert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 12 additions & 4 deletions casdoorsdk/util_modify.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1eca82d

Please sign in to comment.