Show resource list page to users.

This commit is contained in:
Yang Luo 2021-09-06 00:49:10 +08:00
parent f4a59de3a5
commit e4846807cd
6 changed files with 28 additions and 19 deletions

View File

@ -85,6 +85,7 @@ p, *, *, GET, /api/get-user, *, *
p, *, *, GET, /api/get-organizations, *, * p, *, *, GET, /api/get-organizations, *, *
p, *, *, GET, /api/get-user-application, *, * p, *, *, GET, /api/get-user-application, *, *
p, *, *, GET, /api/get-default-providers, *, * p, *, *, GET, /api/get-default-providers, *, *
p, *, *, GET, /api/get-resources, *, *
p, *, *, POST, /api/upload-avatar, *, * p, *, *, POST, /api/upload-avatar, *, *
p, *, *, POST, /api/unlink, *, * p, *, *, POST, /api/unlink, *, *
p, *, *, POST, /api/set-password, *, * p, *, *, POST, /api/set-password, *, *

View File

@ -28,8 +28,9 @@ import (
func (c *ApiController) GetResources() { func (c *ApiController) GetResources() {
owner := c.Input().Get("owner") owner := c.Input().Get("owner")
user := c.Input().Get("user")
c.Data["json"] = object.GetResources(owner) c.Data["json"] = object.GetResources(owner, user)
c.ServeJSON() c.ServeJSON()
} }

View File

@ -38,13 +38,14 @@ type Resource struct {
Url string `xorm:"varchar(100)" json:"url"` Url string `xorm:"varchar(100)" json:"url"`
} }
func GetResources(owner string) []*Resource { func GetResources(owner string, user string) []*Resource {
if owner == "admin" { if owner == "built-in" {
owner = "" owner = ""
user = ""
} }
resources := []*Resource{} resources := []*Resource{}
err := adapter.Engine.Desc("created_time").Find(&resources, &Resource{Owner: owner}) err := adapter.Engine.Desc("created_time").Find(&resources, &Resource{Owner: owner, User: user})
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@ -321,13 +321,17 @@ class App extends Component {
</Link> </Link>
</Menu.Item> </Menu.Item>
); );
res.push( }
<Menu.Item key="/resources">
<Link to="/resources"> res.push(
{i18next.t("general:Resources")} <Menu.Item key="/resources">
</Link> <Link to="/resources">
</Menu.Item> {i18next.t("general:Resources")}
); </Link>
</Menu.Item>
);
if (Setting.isAdminUser(this.state.account)) {
res.push( res.push(
<Menu.Item key="/tokens"> <Menu.Item key="/tokens">
<Link to="/tokens"> <Link to="/tokens">
@ -336,13 +340,14 @@ class App extends Component {
</Menu.Item> </Menu.Item>
); );
res.push( res.push(
<Menu.Item key="/records"> <Menu.Item key="/records">
<Link to="/records"> <Link to="/records">
{i18next.t("general:Records")} {i18next.t("general:Records")}
</Link> </Link>
</Menu.Item> </Menu.Item>
); );
} }
res.push( res.push(
<Menu.Item key="/swagger"> <Menu.Item key="/swagger">
<a target="_blank" rel="noreferrer" href={"/swagger"}> <a target="_blank" rel="noreferrer" href={"/swagger"}>
@ -350,6 +355,7 @@ class App extends Component {
</a> </a>
</Menu.Item> </Menu.Item>
); );
return res; return res;
} }

View File

@ -37,7 +37,7 @@ class ResourceListPage extends React.Component {
} }
getResources() { getResources() {
ResourceBackend.getResources("admin") ResourceBackend.getResources(this.props.account.owner, this.props.account.name)
.then((res) => { .then((res) => {
this.setState({ this.setState({
resources: res, resources: res,

View File

@ -14,8 +14,8 @@
import * as Setting from "../Setting"; import * as Setting from "../Setting";
export function getResources(owner) { export function getResources(owner, user) {
return fetch(`${Setting.ServerUrl}/api/get-resources?owner=${owner}`, { return fetch(`${Setting.ServerUrl}/api/get-resources?owner=${owner}&user=${user}`, {
method: "GET", method: "GET",
credentials: "include" credentials: "include"
}).then(res => res.json()); }).then(res => res.json());