Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(add-modify): allow user to set custom owner instead of default #122

Merged
merged 6 commits into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading