Add user to Resource.

This commit is contained in:
Yang Luo
2021-09-05 23:46:38 +08:00
parent 90ec8ec787
commit a1b16f88d1
6 changed files with 26 additions and 5 deletions

View File

@ -88,6 +88,7 @@ func (c *ApiController) DeleteResource() {
func (c *ApiController) UploadResource() { func (c *ApiController) UploadResource() {
owner := c.Input().Get("owner") owner := c.Input().Get("owner")
username := c.Input().Get("user")
application := c.Input().Get("application") application := c.Input().Get("application")
tag := c.Input().Get("tag") tag := c.Input().Get("tag")
parent := c.Input().Get("parent") parent := c.Input().Get("parent")
@ -134,6 +135,7 @@ func (c *ApiController) UploadResource() {
Owner: owner, Owner: owner,
Name: objectKey, Name: objectKey,
CreatedTime: util.GetCurrentTime(), CreatedTime: util.GetCurrentTime(),
User: username,
Provider: provider.Name, Provider: provider.Name,
Application: application, Application: application,
Tag: tag, Tag: tag,

View File

@ -26,6 +26,7 @@ type Resource struct {
Name string `xorm:"varchar(100) notnull pk" json:"name"` Name string `xorm:"varchar(100) notnull pk" json:"name"`
CreatedTime string `xorm:"varchar(100)" json:"createdTime"` CreatedTime string `xorm:"varchar(100)" json:"createdTime"`
User string `xorm:"varchar(100)" json:"user"`
Provider string `xorm:"varchar(100)" json:"provider"` Provider string `xorm:"varchar(100)" json:"provider"`
Application string `xorm:"varchar(100)" json:"application"` Application string `xorm:"varchar(100)" json:"application"`
Tag string `xorm:"varchar(100)" json:"tag"` Tag string `xorm:"varchar(100)" json:"tag"`
@ -38,6 +39,10 @@ type Resource struct {
} }
func GetResources(owner string) []*Resource { func GetResources(owner string) []*Resource {
if owner == "admin" {
owner = ""
}
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})
if err != nil { if err != nil {

View File

@ -99,7 +99,7 @@ class ApplicationEditPage extends React.Component {
} }
this.setState({uploading: true}); this.setState({uploading: true});
const fullFilePath = `termsOfUse/${this.state.application.owner}/${this.state.application.name}.html`; const fullFilePath = `termsOfUse/${this.state.application.owner}/${this.state.application.name}.html`;
ResourceBackend.uploadResource(this.state.application.owner, "termsOfUse", this.state.application.name, fullFilePath, info.file) ResourceBackend.uploadResource(this.props.account.owner, this.props.account.name, "termsOfUse", this.state.application.name, fullFilePath, info.file)
.then(res => { .then(res => {
if (res.status === "ok") { if (res.status === "ok") {
Setting.showMessage("success", i18next.t("application:File uploaded successfully")); Setting.showMessage("success", i18next.t("application:File uploaded successfully"));

View File

@ -58,7 +58,7 @@ export const CropperDiv = (props) => {
// Setting.showMessage("success", "uploading..."); // Setting.showMessage("success", "uploading...");
const extension = image.substring(image.indexOf('/') + 1, image.indexOf(';base64')); const extension = image.substring(image.indexOf('/') + 1, image.indexOf(';base64'));
const fullFilePath = `avatar/${user.owner}/${user.name}.${extension}`; const fullFilePath = `avatar/${user.owner}/${user.name}.${extension}`;
ResourceBackend.uploadResource("admin", "avatar", account.name, fullFilePath, blob) ResourceBackend.uploadResource(user.owner, user.name, "avatar", account.name, fullFilePath, blob)
.then((res) => { .then((res) => {
if (res.status === "ok") { if (res.status === "ok") {
window.location.href = "/account"; window.location.href = "/account";

View File

@ -63,7 +63,7 @@ class ResourceListPage extends React.Component {
this.setState({uploading: true}); this.setState({uploading: true});
const filename = info.fileList[0].name; const filename = info.fileList[0].name;
const fullFilePath = `resource/${this.props.account.owner}/${this.props.account.name}/${filename}`; const fullFilePath = `resource/${this.props.account.owner}/${this.props.account.name}/${filename}`;
ResourceBackend.uploadResource("admin", "custom", this.props.account.name, fullFilePath, info.file) ResourceBackend.uploadResource(this.props.account.owner, this.props.account.name, "custom", this.props.account.name, fullFilePath, info.file)
.then(res => { .then(res => {
if (res.status === "ok") { if (res.status === "ok") {
Setting.showMessage("success", i18next.t("application:File uploaded successfully")); Setting.showMessage("success", i18next.t("application:File uploaded successfully"));
@ -128,6 +128,20 @@ class ResourceListPage extends React.Component {
width: '80px', width: '80px',
sorter: (a, b) => a.tag.localeCompare(b.tag), sorter: (a, b) => a.tag.localeCompare(b.tag),
}, },
{
title: i18next.t("resource:User"),
dataIndex: 'user',
key: 'user',
width: '80px',
sorter: (a, b) => a.user.localeCompare(b.user),
render: (text, record, index) => {
return (
<Link to={`/users/${record.owner}/${record.user}`}>
{text}
</Link>
)
}
},
{ {
title: i18next.t("resource:Application"), title: i18next.t("resource:Application"),
dataIndex: 'application', dataIndex: 'application',

View File

@ -55,11 +55,11 @@ export function deleteResource(resource, provider="") {
}).then(res => res.json()); }).then(res => res.json());
} }
export function uploadResource(owner, tag, parent, fullFilePath, file, provider="") { export function uploadResource(owner, user, tag, parent, fullFilePath, file, provider="") {
const application = "app-built-in"; const application = "app-built-in";
let formData = new FormData(); let formData = new FormData();
formData.append("file", file); formData.append("file", file);
return fetch(`${Setting.ServerUrl}/api/upload-resource?owner=${owner}&application=${application}&tag=${tag}&parent=${parent}&fullFilePath=${encodeURIComponent(fullFilePath)}&provider=${provider}`, { return fetch(`${Setting.ServerUrl}/api/upload-resource?owner=${owner}&user=${user}&application=${application}&tag=${tag}&parent=${parent}&fullFilePath=${encodeURIComponent(fullFilePath)}&provider=${provider}`, {
body: formData, body: formData,
method: 'POST', method: 'POST',
credentials: 'include', credentials: 'include',