From dc0712c8a5127ba5679bcd80f4fd990f39b59fae Mon Sep 17 00:00:00 2001 From: Yang Luo Date: Sun, 11 Jul 2021 23:49:06 +0800 Subject: [PATCH] Replace getDefaultApplication() with getUserApplication(). --- authz/authz.go | 2 +- controllers/application.go | 22 +++++++++------------- routers/router.go | 2 +- web/src/UserEditPage.js | 6 +++--- web/src/backend/ApplicationBackend.js | 4 ++-- 5 files changed, 16 insertions(+), 20 deletions(-) diff --git a/authz/authz.go b/authz/authz.go index c9444aac..3287dac9 100644 --- a/authz/authz.go +++ b/authz/authz.go @@ -82,7 +82,7 @@ p, *, *, GET, /api/get-application, *, * p, *, *, GET, /api/get-users, *, * p, *, *, GET, /api/get-user, *, * p, *, *, GET, /api/get-organizations, *, * -p, *, *, GET, /api/get-default-application, *, * +p, *, *, GET, /api/get-user-application, *, * p, *, *, GET, /api/get-default-providers, *, * p, *, *, POST, /api/upload-avatar, *, * p, *, *, POST, /api/unlink, *, * diff --git a/controllers/application.go b/controllers/application.go index 0be7f3ab..36bb3946 100644 --- a/controllers/application.go +++ b/controllers/application.go @@ -44,23 +44,19 @@ func (c *ApiController) GetApplication() { c.ServeJSON() } -// @Title GetDefaultApplication -// @Description get the detail of the default application -// @Param owner query string true "The owner of the application." +// @Title GetUserApplication +// @Description get the detail of the user's application +// @Param id query string true "The id of the user" // @Success 200 {object} object.Application The Response object -// @router /get-default-application [get] -func (c *ApiController) GetDefaultApplication() { - //owner := c.Input().Get("owner") - - if c.GetSessionUser() == "" { - c.Data["json"] = nil - c.ServeJSON() +// @router /get-user-application [get] +func (c *ApiController) GetUserApplication() { + id := c.Input().Get("id") + user := object.GetUser(id) + if user == nil { + c.ResponseError("No such user.") return } - username := c.GetSessionUser() - user := object.GetUser(username) - c.Data["json"] = object.GetApplicationByUser(user) c.ServeJSON() } diff --git a/routers/router.go b/routers/router.go index 554e9acc..4c663882 100644 --- a/routers/router.go +++ b/routers/router.go @@ -73,7 +73,7 @@ func initAPI() { beego.Router("/api/get-applications", &controllers.ApiController{}, "GET:GetApplications") beego.Router("/api/get-application", &controllers.ApiController{}, "GET:GetApplication") - beego.Router("/api/get-default-application", &controllers.ApiController{}, "GET:GetDefaultApplication") + beego.Router("/api/get-user-application", &controllers.ApiController{}, "GET:GetUserApplication") beego.Router("/api/update-application", &controllers.ApiController{}, "POST:UpdateApplication") beego.Router("/api/add-application", &controllers.ApiController{}, "POST:AddApplication") beego.Router("/api/delete-application", &controllers.ApiController{}, "POST:DeleteApplication") diff --git a/web/src/UserEditPage.js b/web/src/UserEditPage.js index a4412c7a..fe7267a8 100644 --- a/web/src/UserEditPage.js +++ b/web/src/UserEditPage.js @@ -49,7 +49,7 @@ class UserEditPage extends React.Component { UNSAFE_componentWillMount() { this.getUser(); this.getOrganizations(); - this.getDefaultApplication(); + this.getUserApplication(); } getUser() { @@ -70,8 +70,8 @@ class UserEditPage extends React.Component { }); } - getDefaultApplication() { - ApplicationBackend.getDefaultApplication("admin") + getUserApplication() { + ApplicationBackend.getUserApplication(this.state.organizationName, this.state.userName) .then((application) => { this.setState({ application: application, diff --git a/web/src/backend/ApplicationBackend.js b/web/src/backend/ApplicationBackend.js index 1d795f63..851921fd 100644 --- a/web/src/backend/ApplicationBackend.js +++ b/web/src/backend/ApplicationBackend.js @@ -28,8 +28,8 @@ export function getApplication(owner, name) { }).then(res => res.json()); } -export function getDefaultApplication(owner) { - return fetch(`${Setting.ServerUrl}/api/get-default-application?owner=${owner}`, { +export function getUserApplication(owner, name) { + return fetch(`${Setting.ServerUrl}/api/get-user-application?id=${owner}/${encodeURIComponent(name)}`, { method: "GET", credentials: "include" }).then(res => res.json());