feat: response with status in casbin_adapter.go (#1384)

* fix: response standardized information with status in `casbin_adapter.go`

* fix: remove redundant statements
This commit is contained in:
imp2002 2022-12-08 10:22:59 +08:00 committed by GitHub
parent 2bb2c36f22
commit e705eecffe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 12 deletions

View File

@ -32,8 +32,8 @@ func (c *ApiController) GetCasbinAdapters() {
sortField := c.Input().Get("sortField")
sortOrder := c.Input().Get("sortOrder")
if limit == "" || page == "" {
c.Data["json"] = object.GetCasbinAdapters(owner)
c.ServeJSON()
adapters := object.GetCasbinAdapters(owner)
c.ResponseOk(adapters)
} else {
limit := util.ParseInt(limit)
paginator := pagination.SetPaginator(c.Ctx, limit, int64(object.GetCasbinAdapterCount(owner, field, value)))
@ -44,8 +44,8 @@ func (c *ApiController) GetCasbinAdapters() {
func (c *ApiController) GetCasbinAdapter() {
id := c.Input().Get("id")
c.Data["json"] = object.GetCasbinAdapter(id)
c.ServeJSON()
adapter := object.GetCasbinAdapter(id)
c.ResponseOk(adapter)
}
func (c *ApiController) UpdateCasbinAdapter() {
@ -96,8 +96,7 @@ func (c *ApiController) SyncPolicies() {
return
}
c.Data["json"] = policies
c.ServeJSON()
c.ResponseOk(policies)
}
func (c *ApiController) UpdatePolicy() {

View File

@ -48,12 +48,14 @@ class AdapterEditPage extends React.Component {
getAdapter() {
AdapterBackend.getAdapter(this.state.owner, this.state.adapterName)
.then((adapter) => {
this.setState({
adapter: adapter,
});
.then((res) => {
if (res.status === "ok") {
this.setState({
adapter: res.data,
});
this.getModels(adapter.owner);
this.getModels(this.adapter.owner);
}
});
}

View File

@ -91,7 +91,7 @@ class PolicyTable extends React.Component {
AdapterBackend.syncPolicies(this.props.owner, this.props.name)
.then((res) => {
if (res.status === "ok") {
this.setState({policyLists: res});
this.setState({policyLists: res.data});
} else {
Setting.showMessage("error", `${i18next.t("adapter:Failed to sync policies")}: ${res.msg}`);
}