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
3 changed files with 13 additions and 12 deletions

View File

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

View File

@ -48,12 +48,14 @@ class AdapterEditPage extends React.Component {
getAdapter() { getAdapter() {
AdapterBackend.getAdapter(this.state.owner, this.state.adapterName) AdapterBackend.getAdapter(this.state.owner, this.state.adapterName)
.then((adapter) => { .then((res) => {
this.setState({ if (res.status === "ok") {
adapter: adapter, 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) AdapterBackend.syncPolicies(this.props.owner, this.props.name)
.then((res) => { .then((res) => {
if (res.status === "ok") { if (res.status === "ok") {
this.setState({policyLists: res}); this.setState({policyLists: res.data});
} else { } else {
Setting.showMessage("error", `${i18next.t("adapter:Failed to sync policies")}: ${res.msg}`); Setting.showMessage("error", `${i18next.t("adapter:Failed to sync policies")}: ${res.msg}`);
} }