mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-02 11:20:18 +08:00
feat: support shared application across organizations (#3108)
* feat: support share application * revert: revert i18n * fix: improve code format * fix: improve code format and move GetSharedOrgFromApp to string.go
This commit is contained in:
@ -91,6 +91,7 @@ type Application struct {
|
||||
CertPublicKey string `xorm:"-" json:"certPublicKey"`
|
||||
Tags []string `xorm:"mediumtext" json:"tags"`
|
||||
SamlAttributes []*SamlItem `xorm:"varchar(1000)" json:"samlAttributes"`
|
||||
IsShared bool `json:"isShared"`
|
||||
|
||||
ClientId string `xorm:"varchar(100)" json:"clientId"`
|
||||
ClientSecret string `xorm:"varchar(100)" json:"clientSecret"`
|
||||
@ -123,9 +124,9 @@ func GetApplicationCount(owner, field, value string) (int64, error) {
|
||||
return session.Count(&Application{})
|
||||
}
|
||||
|
||||
func GetOrganizationApplicationCount(owner, Organization, field, value string) (int64, error) {
|
||||
func GetOrganizationApplicationCount(owner, organization, field, value string) (int64, error) {
|
||||
session := GetSession(owner, -1, -1, field, value, "", "")
|
||||
return session.Count(&Application{Organization: Organization})
|
||||
return session.Where("organization = ? or is_shared = ? ", organization, true).Count(&Application{})
|
||||
}
|
||||
|
||||
func GetApplications(owner string) ([]*Application, error) {
|
||||
@ -140,7 +141,7 @@ func GetApplications(owner string) ([]*Application, error) {
|
||||
|
||||
func GetOrganizationApplications(owner string, organization string) ([]*Application, error) {
|
||||
applications := []*Application{}
|
||||
err := ormer.Engine.Desc("created_time").Find(&applications, &Application{Organization: organization})
|
||||
err := ormer.Engine.Desc("created_time").Where("organization = ? or is_shared = ? ", organization, true).Find(&applications, &Application{})
|
||||
if err != nil {
|
||||
return applications, err
|
||||
}
|
||||
@ -162,7 +163,7 @@ func GetPaginationApplications(owner string, offset, limit int, field, value, so
|
||||
func GetPaginationOrganizationApplications(owner, organization string, offset, limit int, field, value, sortField, sortOrder string) ([]*Application, error) {
|
||||
applications := []*Application{}
|
||||
session := GetSession(owner, offset, limit, field, value, sortField, sortOrder)
|
||||
err := session.Find(&applications, &Application{Organization: organization})
|
||||
err := session.Where("organization = ? or is_shared = ? ", organization, true).Find(&applications, &Application{})
|
||||
if err != nil {
|
||||
return applications, err
|
||||
}
|
||||
@ -337,12 +338,18 @@ func getApplication(owner string, name string) (*Application, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
application := Application{Owner: owner, Name: name}
|
||||
realApplicationName, sharedOrg := util.GetSharedOrgFromApp(name)
|
||||
|
||||
application := Application{Owner: owner, Name: realApplicationName}
|
||||
existed, err := ormer.Engine.Get(&application)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if application.IsShared && sharedOrg != "" {
|
||||
application.Organization = sharedOrg
|
||||
}
|
||||
|
||||
if existed {
|
||||
err = extendApplicationWithProviders(&application)
|
||||
if err != nil {
|
||||
@ -428,11 +435,18 @@ func GetApplicationByUserId(userId string) (application *Application, err error)
|
||||
|
||||
func GetApplicationByClientId(clientId string) (*Application, error) {
|
||||
application := Application{}
|
||||
existed, err := ormer.Engine.Where("client_id=?", clientId).Get(&application)
|
||||
|
||||
realClientId, sharedOrg := util.GetSharedOrgFromApp(clientId)
|
||||
|
||||
existed, err := ormer.Engine.Where("client_id=?", realClientId).Get(&application)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if application.IsShared && sharedOrg != "" {
|
||||
application.Organization = sharedOrg
|
||||
}
|
||||
|
||||
if existed {
|
||||
err = extendApplicationWithProviders(&application)
|
||||
if err != nil {
|
||||
@ -626,6 +640,10 @@ func UpdateApplication(id string, application *Application) (bool, error) {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if application.IsShared == true && application.Organization != "built-in" {
|
||||
return false, fmt.Errorf("only applications belonging to built-in organization can be shared")
|
||||
}
|
||||
|
||||
for _, providerItem := range application.Providers {
|
||||
providerItem.Provider = nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user