mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-23 02:35:49 +08:00
Refactor GetDefaultApplication().
This commit is contained in:
parent
6508d96162
commit
b103683fea
@ -50,9 +50,18 @@ func (c *ApiController) GetApplication() {
|
||||
// @Success 200 {object} object.Application The Response object
|
||||
// @router /get-default-application [get]
|
||||
func (c *ApiController) GetDefaultApplication() {
|
||||
owner := c.Input().Get("owner")
|
||||
//owner := c.Input().Get("owner")
|
||||
|
||||
c.Data["json"] = object.GetDefaultApplication(owner)
|
||||
if c.GetSessionUser() == "" {
|
||||
c.Data["json"] = nil
|
||||
c.ServeJSON()
|
||||
return
|
||||
}
|
||||
|
||||
username := c.GetSessionUser()
|
||||
user := object.GetUser(username)
|
||||
|
||||
c.Data["json"] = object.GetApplicationByUser(user)
|
||||
c.ServeJSON()
|
||||
}
|
||||
|
||||
|
@ -89,10 +89,9 @@ func getApplication(owner string, name string) *Application {
|
||||
}
|
||||
}
|
||||
|
||||
func GetDefaultApplication(owner string) *Application {
|
||||
name := "app-built-in"
|
||||
application := Application{Owner: owner, Name: name}
|
||||
existed, err := adapter.Engine.Get(&application)
|
||||
func getApplicationByOrganization(organization string) *Application {
|
||||
application := Application{}
|
||||
existed, err := adapter.Engine.Where("organization=?", organization).Get(&application)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -106,6 +105,10 @@ func GetDefaultApplication(owner string) *Application {
|
||||
}
|
||||
}
|
||||
|
||||
func GetApplicationByUser(user *User) *Application {
|
||||
return getApplicationByOrganization(user.Owner)
|
||||
}
|
||||
|
||||
func getApplicationByClientId(clientId string) *Application {
|
||||
application := Application{}
|
||||
existed, err := adapter.Engine.Where("client_id=?", clientId).Get(&application)
|
||||
|
Loading…
x
Reference in New Issue
Block a user