From 3aafd160ad213b9ecfb69c922c6611e733f5d00a Mon Sep 17 00:00:00 2001 From: Yang Luo Date: Fri, 8 Mar 2024 15:24:33 +0800 Subject: [PATCH] feat: fix owner issue in Token APIs --- casdoorsdk/token.go | 6 +++--- casdoorsdk/token_test.go | 11 ++++++----- casdoorsdk/util_modify.go | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/casdoorsdk/token.go b/casdoorsdk/token.go index 9992e21..2db8fc1 100644 --- a/casdoorsdk/token.go +++ b/casdoorsdk/token.go @@ -44,7 +44,7 @@ type Token struct { func (c *Client) GetTokens() ([]*Token, error) { queryMap := map[string]string{ - "owner": c.OrganizationName, + "owner": "admin", } url := c.GetUrl("get-tokens", queryMap) @@ -63,7 +63,7 @@ func (c *Client) GetTokens() ([]*Token, error) { } func (c *Client) GetPaginationTokens(p int, pageSize int, queryMap map[string]string) ([]*Token, int, error) { - queryMap["owner"] = c.OrganizationName + queryMap["owner"] = "admin" queryMap["p"] = strconv.Itoa(p) queryMap["pageSize"] = strconv.Itoa(pageSize) @@ -84,7 +84,7 @@ func (c *Client) GetPaginationTokens(p int, pageSize int, queryMap map[string]st func (c *Client) GetToken(name string) (*Token, error) { queryMap := map[string]string{ - "id": fmt.Sprintf("%s/%s", c.OrganizationName, name), + "id": fmt.Sprintf("%s/%s", "admin", name), } url := c.GetUrl("get-token", queryMap) diff --git a/casdoorsdk/token_test.go b/casdoorsdk/token_test.go index 4004b61..b296f32 100644 --- a/casdoorsdk/token_test.go +++ b/casdoorsdk/token_test.go @@ -25,11 +25,12 @@ func TestToken(t *testing.T) { // Add a new object token := &Token{ - Owner: "admin", - Name: name, - CreatedTime: GetCurrentTime(), - Code: "abc", - AccessToken: "123456", + Owner: "admin", + Name: name, + CreatedTime: GetCurrentTime(), + Organization: "casbin", + Code: "abc", + AccessToken: "123456", } _, err := AddToken(token) if err != nil { diff --git a/casdoorsdk/util_modify.go b/casdoorsdk/util_modify.go index eae6ea3..7d6001f 100644 --- a/casdoorsdk/util_modify.go +++ b/casdoorsdk/util_modify.go @@ -511,7 +511,7 @@ func (c *Client) modifyToken(action string, token *Token, columns []string) (*Re queryMap["columns"] = strings.Join(columns, ",") } - token.Owner = c.OrganizationName + // token.Owner = c.OrganizationName postBytes, err := json.Marshal(token) if err != nil { return nil, false, err