Compare commits

...

14 Commits

Author SHA1 Message Date
Yaodong Yu
bfe8e5f3e7 fix: fix response data assignment error (#2129) 2023-07-25 13:52:31 +08:00
Yang Luo
702ee6acd0 Print log for StartLdapServer()'s error 2023-07-25 01:49:43 +08:00
Yaodong Yu
0a9587901a fix: fix response data assignment error in ApplicationEditPage.js (#2126) 2023-07-24 20:09:09 +08:00
Yaodong Yu
577bd6ce58 feat: fix response data assignment error (#2123) 2023-07-24 14:52:30 +08:00
Yaodong Yu
3c4112dd44 refactor: optimize the code to getEnforcer (#2120) 2023-07-24 14:02:34 +08:00
haiwu
b7a37126ad feat: restrict redirectUrls for CAS login (#2118)
* feat: support cas restricted login

* feat: add cas login i18n

* feat: add CheckCasService for all cas api

* feat: gofumpt

* feat: replace 404

* feat: reuse i18n

* feat: delete CheckCasService

* Update token_cas.go

* Update LoginPage.js

* Update token_cas.go

---------

Co-authored-by: hsluoyz <hsluoyz@qq.com>
2023-07-24 11:47:31 +08:00
UsherFall
8669d5bb0d chore: hide field of IntranetEndpoint in Tencent COS storage provider (#2117) 2023-07-23 19:02:42 +08:00
Baihhh
aee3ea4981 feat: improve TermsOfUse UI in mobile (#2106)
* style: Mobile interface adaptation

Signed-off-by: baihhh <2542274498@qq.com>

* Update index.css

---------

Signed-off-by: baihhh <2542274498@qq.com>
Co-authored-by: hsluoyz <hsluoyz@qq.com>
2023-07-23 15:28:13 +08:00
Yang Luo
516f4b7569 Fix response of /api/get-sorted-users and /api/get-user-count 2023-07-23 14:46:38 +08:00
UsherFall
7d7ca10481 fix: hide fields of minio storage provider (#2115)
* feat: hide field of minio storage provider

* feat: hide field of domain in minio storage provider
2023-07-23 14:40:30 +08:00
UsherFall
a9d4978a0f chore: hide fields of local file system storage provider (#2109)
* style: adjust local file system storage

* style: disable domain when use local file system
2023-07-23 11:48:15 +08:00
Yang Luo
09f40bb5ce Fix id of "/api/get-resource" API 2023-07-23 11:33:48 +08:00
Yaodong Yu
a6f803aff1 feat: refactor code to use responseOK everywhere (#2111)
* refactor: use responseOK return frontend format json data

* revert handle error

* revert handle error
2023-07-23 09:49:16 +08:00
Yang Luo
fc9528be43 Add createDatabaseForPostgres() 2023-07-22 16:19:13 +08:00
65 changed files with 394 additions and 347 deletions

View File

@@ -48,14 +48,11 @@ func (c *ApiController) GetApplications() {
} else { } else {
applications, err = object.GetOrganizationApplications(owner, organization) applications, err = object.GetOrganizationApplications(owner, organization)
} }
if err != nil { if err != nil {
c.ResponseError(err.Error()) c.ResponseError(err.Error())
return return
} }
c.ResponseOk(object.GetMaskedApplications(applications, userId))
c.Data["json"] = object.GetMaskedApplications(applications, userId)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetApplicationCount(owner, field, value) count, err := object.GetApplicationCount(owner, field, value)
@@ -86,14 +83,14 @@ func (c *ApiController) GetApplications() {
func (c *ApiController) GetApplication() { func (c *ApiController) GetApplication() {
userId := c.GetSessionUsername() userId := c.GetSessionUsername()
id := c.Input().Get("id") id := c.Input().Get("id")
app, err := object.GetApplication(id) app, err := object.GetApplication(id)
if err != nil { if err != nil {
c.ResponseError(err.Error()) c.ResponseError(err.Error())
return return
} }
c.Data["json"] = object.GetMaskedApplication(app, userId) c.ResponseOk(object.GetMaskedApplication(app, userId))
c.ServeJSON()
} }
// GetUserApplication // GetUserApplication
@@ -106,25 +103,24 @@ func (c *ApiController) GetApplication() {
func (c *ApiController) GetUserApplication() { func (c *ApiController) GetUserApplication() {
userId := c.GetSessionUsername() userId := c.GetSessionUsername()
id := c.Input().Get("id") id := c.Input().Get("id")
user, err := object.GetUser(id) user, err := object.GetUser(id)
if err != nil { if err != nil {
c.ResponseError(err.Error()) c.ResponseError(err.Error())
return return
} }
if user == nil { if user == nil {
c.ResponseError(fmt.Sprintf(c.T("general:The user: %s doesn't exist"), id)) c.ResponseError(fmt.Sprintf(c.T("general:The user: %s doesn't exist"), id))
return return
} }
app, err := object.GetApplicationByUser(user) application, err := object.GetApplicationByUser(user)
if err != nil { if err != nil {
c.ResponseError(err.Error()) c.ResponseError(err.Error())
return return
} }
c.Data["json"] = object.GetMaskedApplication(app, userId) c.ResponseOk(object.GetMaskedApplication(application, userId))
c.ServeJSON()
} }
// GetOrganizationApplications // GetOrganizationApplications
@@ -157,8 +153,7 @@ func (c *ApiController) GetOrganizationApplications() {
return return
} }
c.Data["json"] = object.GetMaskedApplications(applications, userId) c.ResponseOk(object.GetMaskedApplications(applications, userId))
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)

View File

@@ -45,8 +45,7 @@ func (c *ApiController) GetCerts() {
return return
} }
c.Data["json"] = maskedCerts c.ResponseOk(maskedCerts)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetCertCount(owner, field, value) count, err := object.GetCertCount(owner, field, value)
@@ -87,8 +86,7 @@ func (c *ApiController) GetGlobleCerts() {
return return
} }
c.Data["json"] = maskedCerts c.ResponseOk(maskedCerts)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetGlobalCertsCount(field, value) count, err := object.GetGlobalCertsCount(field, value)
@@ -123,8 +121,7 @@ func (c *ApiController) GetCert() {
return return
} }
c.Data["json"] = object.GetMaskedCert(cert) c.ResponseOk(object.GetMaskedCert(cert))
c.ServeJSON()
} }
// UpdateCert // UpdateCert

View File

@@ -45,8 +45,7 @@ func (c *ApiController) GetChats() {
return return
} }
c.Data["json"] = maskedChats c.ResponseOk(maskedChats)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetChatCount(owner, field, value) count, err := object.GetChatCount(owner, field, value)
@@ -82,8 +81,7 @@ func (c *ApiController) GetChat() {
return return
} }
c.Data["json"] = maskedChat c.ResponseOk(maskedChat)
c.ServeJSON()
} }
// UpdateChat // UpdateChat

View File

@@ -82,9 +82,9 @@ func (c *ApiController) GetGroup() {
group, err := object.GetGroup(id) group, err := object.GetGroup(id)
if err != nil { if err != nil {
c.ResponseError(err.Error()) c.ResponseError(err.Error())
} else { return
c.ResponseOk(group)
} }
c.ResponseOk(group)
} }
// UpdateGroup // UpdateGroup

View File

@@ -125,7 +125,12 @@ func (c *ApiController) GetLdap() {
} }
_, name := util.GetOwnerAndNameFromId(id) _, name := util.GetOwnerAndNameFromId(id)
c.ResponseOk(object.GetMaskedLdap(object.GetLdap(name))) ldap, err := object.GetLdap(name)
if err != nil {
c.ResponseError(err.Error())
return
}
c.ResponseOk(object.GetMaskedLdap(ldap))
} }
// AddLdap // AddLdap

View File

@@ -57,8 +57,7 @@ func (c *ApiController) GetMessages() {
return return
} }
c.Data["json"] = object.GetMaskedMessages(messages) c.ResponseOk(object.GetMaskedMessages(messages))
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetMessageCount(owner, organization, field, value) count, err := object.GetMessageCount(owner, organization, field, value)
@@ -94,8 +93,7 @@ func (c *ApiController) GetMessage() {
return return
} }
c.Data["json"] = object.GetMaskedMessage(message) c.ResponseOk(message)
c.ServeJSON()
} }
func (c *ApiController) ResponseErrorStream(errorText string) { func (c *ApiController) ResponseErrorStream(errorText string) {

View File

@@ -45,8 +45,7 @@ func (c *ApiController) GetModels() {
return return
} }
c.Data["json"] = models c.ResponseOk(models)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetModelCount(owner, field, value) count, err := object.GetModelCount(owner, field, value)
@@ -82,8 +81,7 @@ func (c *ApiController) GetModel() {
return return
} }
c.Data["json"] = model c.ResponseOk(model)
c.ServeJSON()
} }
// UpdateModel // UpdateModel

View File

@@ -55,8 +55,7 @@ func (c *ApiController) GetOrganizations() {
return return
} }
c.Data["json"] = maskedOrganizations c.ResponseOk(maskedOrganizations)
c.ServeJSON()
} else { } else {
if !isGlobalAdmin { if !isGlobalAdmin {
maskedOrganizations, err := object.GetMaskedOrganizations(object.GetOrganizations(owner, c.getCurrentUser().Owner)) maskedOrganizations, err := object.GetMaskedOrganizations(object.GetOrganizations(owner, c.getCurrentUser().Owner))
@@ -184,6 +183,8 @@ func (c *ApiController) DeleteOrganization() {
func (c *ApiController) GetDefaultApplication() { func (c *ApiController) GetDefaultApplication() {
userId := c.GetSessionUsername() userId := c.GetSessionUsername()
id := c.Input().Get("id") id := c.Input().Get("id")
redirectUri := c.Input().Get("redirectUri")
typ := c.Input().Get("type")
application, err := object.GetDefaultApplication(id) application, err := object.GetDefaultApplication(id)
if err != nil { if err != nil {
@@ -191,6 +192,14 @@ func (c *ApiController) GetDefaultApplication() {
return return
} }
if typ == "cas" {
err = object.CheckCasRestrict(application, c.GetAcceptLanguage(), redirectUri)
if err != nil {
c.ResponseError(err.Error())
return
}
}
maskedApplication := object.GetMaskedApplication(application, userId) maskedApplication := object.GetMaskedApplication(application, userId)
c.ResponseOk(maskedApplication) c.ResponseOk(maskedApplication)
} }

View File

@@ -46,8 +46,7 @@ func (c *ApiController) GetPayments() {
return return
} }
c.Data["json"] = payments c.ResponseOk(payments)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetPaymentCount(owner, organization, field, value) count, err := object.GetPaymentCount(owner, organization, field, value)
@@ -106,8 +105,7 @@ func (c *ApiController) GetPayment() {
return return
} }
c.Data["json"] = payment c.ResponseOk(payment)
c.ServeJSON()
} }
// UpdatePayment // UpdatePayment

View File

@@ -45,8 +45,7 @@ func (c *ApiController) GetPermissions() {
return return
} }
c.Data["json"] = permissions c.ResponseOk(permissions)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetPermissionCount(owner, field, value) count, err := object.GetPermissionCount(owner, field, value)
@@ -85,7 +84,6 @@ func (c *ApiController) GetPermissionsBySubmitter() {
} }
c.ResponseOk(permissions, len(permissions)) c.ResponseOk(permissions, len(permissions))
return
} }
// GetPermissionsByRole // GetPermissionsByRole
@@ -104,7 +102,6 @@ func (c *ApiController) GetPermissionsByRole() {
} }
c.ResponseOk(permissions, len(permissions)) c.ResponseOk(permissions, len(permissions))
return
} }
// GetPermission // GetPermission
@@ -123,8 +120,7 @@ func (c *ApiController) GetPermission() {
return return
} }
c.Data["json"] = permission c.ResponseOk(permission)
c.ServeJSON()
} }
// UpdatePermission // UpdatePermission

View File

@@ -45,8 +45,7 @@ func (c *ApiController) GetPlans() {
return return
} }
c.Data["json"] = plans c.ResponseOk(plans)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetPlanCount(owner, field, value) count, err := object.GetPlanCount(owner, field, value)
@@ -95,11 +94,10 @@ func (c *ApiController) GetPlan() {
plan.Options = append(plan.Options, option.DisplayName) plan.Options = append(plan.Options, option.DisplayName)
} }
c.Data["json"] = plan c.ResponseOk(plan)
} else { } else {
c.Data["json"] = plan c.ResponseOk(plan)
} }
c.ServeJSON()
} }
// UpdatePlan // UpdatePlan

View File

@@ -45,8 +45,7 @@ func (c *ApiController) GetPricings() {
return return
} }
c.Data["json"] = pricings c.ResponseOk(pricings)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetPricingCount(owner, field, value) count, err := object.GetPricingCount(owner, field, value)
@@ -82,8 +81,7 @@ func (c *ApiController) GetPricing() {
return return
} }
c.Data["json"] = pricing c.ResponseOk(pricing)
c.ServeJSON()
} }
// UpdatePricing // UpdatePricing

View File

@@ -46,8 +46,7 @@ func (c *ApiController) GetProducts() {
return return
} }
c.Data["json"] = products c.ResponseOk(products)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetProductCount(owner, field, value) count, err := object.GetProductCount(owner, field, value)
@@ -89,8 +88,7 @@ func (c *ApiController) GetProduct() {
return return
} }
c.Data["json"] = product c.ResponseOk(product)
c.ServeJSON()
} }
// UpdateProduct // UpdateProduct

View File

@@ -51,8 +51,7 @@ func (c *ApiController) GetRecords() {
return return
} }
c.Data["json"] = records c.ResponseOk(records)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
if c.IsGlobalAdmin() && organizationName != "" { if c.IsGlobalAdmin() && organizationName != "" {
@@ -99,8 +98,7 @@ func (c *ApiController) GetRecordsByFilter() {
return return
} }
c.Data["json"] = records c.ResponseOk(records)
c.ServeJSON()
} }
// AddRecord // AddRecord

View File

@@ -67,8 +67,7 @@ func (c *ApiController) GetResources() {
return return
} }
c.Data["json"] = resources c.ResponseOk(resources)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetResourceCount(owner, user, field, value) count, err := object.GetResourceCount(owner, user, field, value)
@@ -104,8 +103,7 @@ func (c *ApiController) GetResource() {
return return
} }
c.Data["json"] = resource c.ResponseOk(resource)
c.ServeJSON()
} }
// UpdateResource // UpdateResource

View File

@@ -45,8 +45,7 @@ func (c *ApiController) GetRoles() {
return return
} }
c.Data["json"] = roles c.ResponseOk(roles)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetRoleCount(owner, field, value) count, err := object.GetRoleCount(owner, field, value)
@@ -82,8 +81,7 @@ func (c *ApiController) GetRole() {
return return
} }
c.Data["json"] = role c.ResponseOk(role)
c.ServeJSON()
} }
// UpdateRole // UpdateRole

View File

@@ -45,8 +45,7 @@ func (c *ApiController) GetSessions() {
return return
} }
c.Data["json"] = sessions c.ResponseOk(sessions)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetSessionCount(owner, field, value) count, err := object.GetSessionCount(owner, field, value)
@@ -81,8 +80,7 @@ func (c *ApiController) GetSingleSession() {
return return
} }
c.Data["json"] = session c.ResponseOk(session)
c.ServeJSON()
} }
// UpdateSession // UpdateSession
@@ -161,7 +159,5 @@ func (c *ApiController) IsSessionDuplicated() {
return return
} }
c.Data["json"] = &Response{Status: "ok", Msg: "", Data: isUserSessionDuplicated} c.ResponseOk(isUserSessionDuplicated)
c.ServeJSON()
} }

View File

@@ -45,8 +45,7 @@ func (c *ApiController) GetSubscriptions() {
return return
} }
c.Data["json"] = subscriptions c.ResponseOk(subscriptions)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetSubscriptionCount(owner, field, value) count, err := object.GetSubscriptionCount(owner, field, value)
@@ -82,8 +81,7 @@ func (c *ApiController) GetSubscription() {
return return
} }
c.Data["json"] = subscription c.ResponseOk(subscription)
c.ServeJSON()
} }
// UpdateSubscription // UpdateSubscription

View File

@@ -46,8 +46,7 @@ func (c *ApiController) GetSyncers() {
return return
} }
c.Data["json"] = organizationSyncers c.ResponseOk(organizationSyncers)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetSyncerCount(owner, organization, field, value) count, err := object.GetSyncerCount(owner, organization, field, value)
@@ -83,8 +82,7 @@ func (c *ApiController) GetSyncer() {
return return
} }
c.Data["json"] = syncer c.ResponseOk(syncer)
c.ServeJSON()
} }
// UpdateSyncer // UpdateSyncer

View File

@@ -47,8 +47,7 @@ func (c *ApiController) GetTokens() {
return return
} }
c.Data["json"] = token c.ResponseOk(token)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetTokenCount(owner, organization, field, value) count, err := object.GetTokenCount(owner, organization, field, value)
@@ -83,8 +82,7 @@ func (c *ApiController) GetToken() {
return return
} }
c.Data["json"] = token c.ResponseOk(token)
c.ServeJSON()
} }
// UpdateToken // UpdateToken

View File

@@ -45,8 +45,7 @@ func (c *ApiController) GetGlobalUsers() {
return return
} }
c.Data["json"] = maskedUsers c.ResponseOk(maskedUsers)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetGlobalUserCount(field, value) count, err := object.GetGlobalUserCount(field, value)
@@ -106,8 +105,7 @@ func (c *ApiController) GetUsers() {
return return
} }
c.Data["json"] = maskedUsers c.ResponseOk(maskedUsers)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetUserCount(owner, field, value, groupName) count, err := object.GetUserCount(owner, field, value, groupName)
@@ -215,8 +213,7 @@ func (c *ApiController) GetUser() {
return return
} }
c.Data["json"] = maskedUser c.ResponseOk(maskedUser)
c.ServeJSON()
} }
// UpdateUser // UpdateUser
@@ -513,8 +510,7 @@ func (c *ApiController) GetSortedUsers() {
return return
} }
c.Data["json"] = maskedUsers c.ResponseOk(maskedUsers)
c.ServeJSON()
} }
// GetUserCount // GetUserCount
@@ -541,8 +537,7 @@ func (c *ApiController) GetUserCount() {
return return
} }
c.Data["json"] = count c.ResponseOk(count)
c.ServeJSON()
} }
// AddUserkeys // AddUserkeys

View File

@@ -46,8 +46,7 @@ func (c *ApiController) GetWebhooks() {
return return
} }
c.Data["json"] = webhooks c.ResponseOk(webhooks)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetWebhookCount(owner, organization, field, value) count, err := object.GetWebhookCount(owner, organization, field, value)
@@ -84,8 +83,7 @@ func (c *ApiController) GetWebhook() {
return return
} }
c.Data["json"] = webhook c.ResponseOk(webhook)
c.ServeJSON()
} }
// UpdateWebhook // UpdateWebhook

View File

@@ -34,7 +34,7 @@ func StartLdapServer() {
server.Handle(routes) server.Handle(routes)
err := server.ListenAndServe("0.0.0.0:" + conf.GetConfigString("ldapServerPort")) err := server.ListenAndServe("0.0.0.0:" + conf.GetConfigString("ldapServerPort"))
if err != nil { if err != nil {
return log.Printf("StartLdapServer() failed, ErrMsg = %s", err.Error())
} }
} }

View File

@@ -15,8 +15,10 @@
package object package object
import ( import (
"database/sql"
"fmt" "fmt"
"runtime" "runtime"
"strings"
"github.com/beego/beego" "github.com/beego/beego"
"github.com/casdoor/casdoor/conf" "github.com/casdoor/casdoor/conf"
@@ -46,6 +48,11 @@ func InitConfig() {
} }
func InitAdapter() { func InitAdapter() {
err := createDatabaseForPostgres(conf.GetConfigString("driverName"), conf.GetConfigDataSourceName(), conf.GetConfigString("dbName"))
if err != nil {
panic(err)
}
adapter = NewAdapter(conf.GetConfigString("driverName"), conf.GetConfigDataSourceName(), conf.GetConfigString("dbName")) adapter = NewAdapter(conf.GetConfigString("driverName"), conf.GetConfigDataSourceName(), conf.GetConfigString("dbName"))
tableNamePrefix := conf.GetConfigString("tableNamePrefix") tableNamePrefix := conf.GetConfigString("tableNamePrefix")
@@ -96,7 +103,32 @@ func NewAdapter(driverName string, dataSourceName string, dbName string) *Adapte
return a return a
} }
func createDatabaseForPostgres(driverName string, dataSourceName string, dbName string) error {
if driverName == "postgres" {
db, err := sql.Open(driverName, dataSourceName)
if err != nil {
return err
}
defer db.Close()
_, err = db.Exec(fmt.Sprintf("CREATE DATABASE %s;", dbName))
if err != nil {
if !strings.Contains(err.Error(), "already exists") {
return err
}
}
return nil
} else {
return nil
}
}
func (a *Adapter) CreateDatabase() error { func (a *Adapter) CreateDatabase() error {
if a.driverName == "postgres" {
return nil
}
engine, err := xorm.NewEngine(a.driverName, a.dataSourceName) engine, err := xorm.NewEngine(a.driverName, a.dataSourceName)
if err != nil { if err != nil {
return err return err

View File

@@ -161,5 +161,8 @@ func modelChangeTrigger(oldName string, newName string) error {
} }
func HasRoleDefinition(m model.Model) bool { func HasRoleDefinition(m model.Model) bool {
if m == nil {
return false
}
return m["g"] != nil return m["g"] != nil
} }

View File

@@ -26,42 +26,7 @@ import (
xormadapter "github.com/casdoor/xorm-adapter/v3" xormadapter "github.com/casdoor/xorm-adapter/v3"
) )
func getEnforcer(permission *Permission, permissionIDs ...string) *casbin.Enforcer { func getEnforcer(p *Permission, permissionIDs ...string) *casbin.Enforcer {
tableName := "permission_rule"
if len(permission.Adapter) != 0 {
adapterObj, err := getCasbinAdapter(permission.Owner, permission.Adapter)
if err != nil {
panic(err)
}
if adapterObj != nil && adapterObj.Table != "" {
tableName = adapterObj.Table
}
}
tableNamePrefix := conf.GetConfigString("tableNamePrefix")
driverName := conf.GetConfigString("driverName")
dataSourceName := conf.GetConfigRealDataSourceName(driverName)
adapter, err := xormadapter.NewAdapterWithTableName(driverName, dataSourceName, tableName, tableNamePrefix, true)
if err != nil {
panic(err)
}
permissionModel, err := getModel(permission.Owner, permission.Model)
if err != nil {
panic(err)
}
m := model.Model{}
if permissionModel != nil {
m, err = GetBuiltInModel(permissionModel.ModelText)
} else {
m, err = GetBuiltInModel("")
}
if err != nil {
panic(err)
}
// Init an enforcer instance without specifying a model or adapter. // Init an enforcer instance without specifying a model or adapter.
// If you specify an adapter, it will load all policies, which is a // If you specify an adapter, it will load all policies, which is a
// heavy process that can slow down the application. // heavy process that can slow down the application.
@@ -70,14 +35,17 @@ func getEnforcer(permission *Permission, permissionIDs ...string) *casbin.Enforc
panic(err) panic(err)
} }
err = enforcer.InitWithModelAndAdapter(m, nil) err = p.setEnforcerModel(enforcer)
if err != nil { if err != nil {
panic(err) panic(err)
} }
enforcer.SetAdapter(adapter) err = p.setEnforcerAdapter(enforcer)
if err != nil {
panic(err)
}
policyFilterV5 := []string{permission.GetId()} policyFilterV5 := []string{p.GetId()}
if len(permissionIDs) != 0 { if len(permissionIDs) != 0 {
policyFilterV5 = permissionIDs policyFilterV5 = permissionIDs
} }
@@ -86,7 +54,7 @@ func getEnforcer(permission *Permission, permissionIDs ...string) *casbin.Enforc
V5: policyFilterV5, V5: policyFilterV5,
} }
if !HasRoleDefinition(m) { if !HasRoleDefinition(enforcer.GetModel()) {
policyFilter.Ptype = []string{"p"} policyFilter.Ptype = []string{"p"}
} }
@@ -98,6 +66,54 @@ func getEnforcer(permission *Permission, permissionIDs ...string) *casbin.Enforc
return enforcer return enforcer
} }
func (p *Permission) setEnforcerAdapter(enforcer *casbin.Enforcer) error {
tableName := "permission_rule"
if len(p.Adapter) != 0 {
adapterObj, err := getCasbinAdapter(p.Owner, p.Adapter)
if err != nil {
return err
}
if adapterObj != nil && adapterObj.Table != "" {
tableName = adapterObj.Table
}
}
tableNamePrefix := conf.GetConfigString("tableNamePrefix")
driverName := conf.GetConfigString("driverName")
dataSourceName := conf.GetConfigRealDataSourceName(driverName)
casbinAdapter, err := xormadapter.NewAdapterWithTableName(driverName, dataSourceName, tableName, tableNamePrefix, true)
if err != nil {
return err
}
enforcer.SetAdapter(casbinAdapter)
return nil
}
func (p *Permission) setEnforcerModel(enforcer *casbin.Enforcer) error {
permissionModel, err := getModel(p.Owner, p.Model)
if err != nil {
return err
}
// TODO: return error if permissionModel is nil.
m := model.Model{}
if permissionModel != nil {
m, err = GetBuiltInModel(permissionModel.ModelText)
} else {
m, err = GetBuiltInModel("")
}
if err != nil {
return err
}
err = enforcer.InitWithModelAndAdapter(m, nil)
if err != nil {
return err
}
return nil
}
func getPolicies(permission *Permission) [][]string { func getPolicies(permission *Permission) [][]string {
var policies [][]string var policies [][]string

View File

@@ -16,6 +16,7 @@ package object
import ( import (
"fmt" "fmt"
"strings"
"github.com/casdoor/casdoor/util" "github.com/casdoor/casdoor/util"
"github.com/xorm-io/core" "github.com/xorm-io/core"
@@ -76,6 +77,10 @@ func GetPaginationResources(owner, user string, offset, limit int, field, value,
} }
func getResource(owner string, name string) (*Resource, error) { func getResource(owner string, name string) (*Resource, error) {
if !strings.HasPrefix(name, "/") {
name = "/" + name
}
resource := Resource{Owner: owner, Name: name} resource := Resource{Owner: owner, Name: name}
existed, err := adapter.Engine.Get(&resource) existed, err := adapter.Engine.Get(&resource)
if err != nil { if err != nil {

View File

@@ -26,6 +26,7 @@ import (
"time" "time"
"github.com/beevik/etree" "github.com/beevik/etree"
"github.com/casdoor/casdoor/i18n"
"github.com/casdoor/casdoor/util" "github.com/casdoor/casdoor/util"
dsig "github.com/russellhaering/goxmldsig" dsig "github.com/russellhaering/goxmldsig"
) )
@@ -122,6 +123,13 @@ var stToServiceResponse sync.Map
// pgt is short for proxy granting ticket // pgt is short for proxy granting ticket
var pgtToServiceResponse sync.Map var pgtToServiceResponse sync.Map
func CheckCasRestrict(application *Application, lang string, service string) error {
if len(application.RedirectUris) > 0 && !application.IsRedirectUriValid(service) {
return fmt.Errorf(i18n.Translate(lang, "token:Redirect URI: %s doesn't exist in the allowed Redirect URI list"), service)
}
return nil
}
func StoreCasTokenForPgt(token *CasAuthenticationSuccess, service, userId string) string { func StoreCasTokenForPgt(token *CasAuthenticationSuccess, service, userId string) string {
pgt := fmt.Sprintf("PGT-%s", util.GenerateId()) pgt := fmt.Sprintf("PGT-%s", util.GenerateId())
pgtToServiceResponse.Store(pgt, &CasAuthenticationSuccessWrapper{ pgtToServiceResponse.Store(pgt, &CasAuthenticationSuccessWrapper{

View File

@@ -156,7 +156,7 @@ func AuthzFilter(ctx *context.Context) {
urlPath := getUrlPath(ctx.Request.URL.Path) urlPath := getUrlPath(ctx.Request.URL.Path)
objOwner, objName := "", "" objOwner, objName := "", ""
if urlPath != "/api/get-app-login" { if urlPath != "/api/get-app-login" && urlPath != "/api/get-resource" {
objOwner, objName = getObject(ctx) objOwner, objName = getObject(ctx)
} }

View File

@@ -23,7 +23,7 @@ func GetStorageProvider(providerType string, clientId string, clientSecret strin
case "AWS S3": case "AWS S3":
return NewAwsS3StorageProvider(clientId, clientSecret, region, bucket, endpoint) return NewAwsS3StorageProvider(clientId, clientSecret, region, bucket, endpoint)
case "MinIO": case "MinIO":
return NewMinIOS3StorageProvider(clientId, clientSecret, region, bucket, endpoint) return NewMinIOS3StorageProvider(clientId, clientSecret, "_", bucket, endpoint)
case "Aliyun OSS": case "Aliyun OSS":
return NewAliyunOssStorageProvider(clientId, clientSecret, region, bucket, endpoint) return NewAliyunOssStorageProvider(clientId, clientSecret, region, bucket, endpoint)
case "Tencent Cloud COS": case "Tencent Cloud COS":

View File

@@ -68,7 +68,7 @@ class AdapterEditPage extends React.Component {
OrganizationBackend.getOrganizations("admin") OrganizationBackend.getOrganizations("admin")
.then((res) => { .then((res) => {
this.setState({ this.setState({
organizations: (res.msg === undefined) ? res : [], organizations: res.data || [],
}); });
}); });
} }
@@ -80,8 +80,9 @@ class AdapterEditPage extends React.Component {
Setting.showMessage("error", res.msg); Setting.showMessage("error", res.msg);
return; return;
} }
this.setState({ this.setState({
models: res, models: res.data,
}); });
}); });
} }

View File

@@ -119,7 +119,7 @@ class ApplicationEditPage extends React.Component {
getApplication() { getApplication() {
ApplicationBackend.getApplication("admin", this.state.applicationName) ApplicationBackend.getApplication("admin", this.state.applicationName)
.then((res) => { .then((res) => {
if (res === null) { if (res.data === null) {
this.props.history.push("/404"); this.props.history.push("/404");
return; return;
} }
@@ -129,32 +129,33 @@ class ApplicationEditPage extends React.Component {
return; return;
} }
if (res.grantTypes === null || res.grantTypes === undefined || res.grantTypes.length === 0) { const application = res.data;
res.grantTypes = ["authorization_code"]; if (application.grantTypes === null || application.grantTypes === undefined || application.grantTypes.length === 0) {
application.grantTypes = ["authorization_code"];
} }
if (res.tags === null || res.tags === undefined) { if (application.tags === null || application.tags === undefined) {
res.tags = []; application.tags = [];
} }
this.setState({ this.setState({
application: res, application: application,
}); });
this.getCerts(res.organization); this.getCerts(application.organization);
}); });
} }
getOrganizations() { getOrganizations() {
OrganizationBackend.getOrganizations("admin") OrganizationBackend.getOrganizations("admin")
.then((res) => { .then((res) => {
if (res?.status === "error") { if (res.status === "error") {
this.setState({ this.setState({
isAuthorized: false, isAuthorized: false,
}); });
} else { } else {
this.setState({ this.setState({
organizations: (res.msg === undefined) ? res : [], organizations: res.data || [],
}); });
} }
}); });
@@ -164,7 +165,7 @@ class ApplicationEditPage extends React.Component {
CertBackend.getCerts(owner) CertBackend.getCerts(owner)
.then((res) => { .then((res) => {
this.setState({ this.setState({
certs: (res.msg === undefined) ? res : [], certs: res.data || [],
}); });
}); });
} }
@@ -184,9 +185,9 @@ class ApplicationEditPage extends React.Component {
getSamlMetadata() { getSamlMetadata() {
ApplicationBackend.getSamlMetadata("admin", this.state.applicationName) ApplicationBackend.getSamlMetadata("admin", this.state.applicationName)
.then((res) => { .then((data) => {
this.setState({ this.setState({
samlMetadata: res, samlMetadata: data,
}); });
}); });
} }

View File

@@ -45,7 +45,7 @@ class CertEditPage extends React.Component {
getCert() { getCert() {
CertBackend.getCert(this.state.owner, this.state.certName) CertBackend.getCert(this.state.owner, this.state.certName)
.then((res) => { .then((res) => {
if (res === null) { if (res.data === null) {
this.props.history.push("/404"); this.props.history.push("/404");
return; return;
} }
@@ -56,7 +56,7 @@ class CertEditPage extends React.Component {
} }
this.setState({ this.setState({
cert: res, cert: res.data,
}); });
}); });
} }
@@ -65,7 +65,7 @@ class CertEditPage extends React.Component {
OrganizationBackend.getOrganizations("admin") OrganizationBackend.getOrganizations("admin")
.then((res) => { .then((res) => {
this.setState({ this.setState({
organizations: (res.msg === undefined) ? res : [], organizations: res.data || [],
}); });
}); });
} }

View File

@@ -41,7 +41,7 @@ class ChatEditPage extends React.Component {
getChat() { getChat() {
ChatBackend.getChat("admin", this.state.chatName) ChatBackend.getChat("admin", this.state.chatName)
.then((res) => { .then((res) => {
if (res === null) { if (res.data === null) {
this.props.history.push("/404"); this.props.history.push("/404");
return; return;
} }
@@ -51,10 +51,10 @@ class ChatEditPage extends React.Component {
return; return;
} }
this.setState({ this.setState({
chat: res, chat: res.data,
}); });
this.getUsers(res.organization); this.getUsers(res.data.organization);
}); });
} }
@@ -62,7 +62,7 @@ class ChatEditPage extends React.Component {
OrganizationBackend.getOrganizations("admin") OrganizationBackend.getOrganizations("admin")
.then((res) => { .then((res) => {
this.setState({ this.setState({
organizations: (res.msg === undefined) ? res : [], organizations: res.data || [],
}); });
}); });
} }
@@ -76,7 +76,7 @@ class ChatEditPage extends React.Component {
} }
this.setState({ this.setState({
users: res, users: res.data,
}); });
}); });
} }

View File

@@ -79,7 +79,8 @@ class ChatPage extends BaseListPage {
getMessages(chatName) { getMessages(chatName) {
MessageBackend.getChatMessages(chatName) MessageBackend.getChatMessages(chatName)
.then((messages) => { .then((res) => {
const messages = res.data;
this.setState({ this.setState({
messages: messages, messages: messages,
}); });
@@ -229,7 +230,7 @@ class ChatPage extends BaseListPage {
</div> </div>
) )
} }
<ChatBox messages={this.state.messages} sendMessage={(text) => {this.sendMessage(text);}} account={this.props.account} /> <ChatBox messages={this.state.messages || []} sendMessage={(text) => {this.sendMessage(text);}} account={this.props.account} />
</div> </div>
</div> </div>
); );

View File

@@ -79,7 +79,9 @@ class EntryPage extends React.Component {
Setting.showMessage("error", res.msg); Setting.showMessage("error", res.msg);
return; return;
} }
const themeData = res !== null ? Setting.getThemeData(res.organizationObj, res) : Conf.ThemeDefault;
const application = res.data;
const themeData = application !== null ? Setting.getThemeData(application.organizationObj, application) : Conf.ThemeDefault;
this.props.updataThemeData(themeData); this.props.updataThemeData(themeData);
}); });
}; };

View File

@@ -67,7 +67,7 @@ class GroupEditPage extends React.Component {
.then((res) => { .then((res) => {
if (res.status === "ok") { if (res.status === "ok") {
this.setState({ this.setState({
organizations: res.data, organizations: res.data || [],
}); });
} }
}); });

View File

@@ -55,7 +55,7 @@ class LdapEditPage extends React.Component {
OrganizationBackend.getOrganizations("admin") OrganizationBackend.getOrganizations("admin")
.then((res) => { .then((res) => {
this.setState({ this.setState({
organizations: (res.msg === undefined) ? res : [], organizations: res.data || [],
}); });
}); });
} }

View File

@@ -46,7 +46,7 @@ class MessageEditPage extends React.Component {
getMessage() { getMessage() {
MessageBackend.getMessage("admin", this.state.messageName) MessageBackend.getMessage("admin", this.state.messageName)
.then((res) => { .then((res) => {
if (res === null) { if (res.data === null) {
this.props.history.push("/404"); this.props.history.push("/404");
return; return;
} }
@@ -54,11 +54,11 @@ class MessageEditPage extends React.Component {
Setting.showMessage("error", res.msg); Setting.showMessage("error", res.msg);
return; return;
} }
this.setState({
message: res,
});
this.getUsers(res.organization); this.setState({
message: res.data,
});
this.getUsers(res.data.organization);
}); });
} }
@@ -66,7 +66,7 @@ class MessageEditPage extends React.Component {
OrganizationBackend.getOrganizations("admin") OrganizationBackend.getOrganizations("admin")
.then((res) => { .then((res) => {
this.setState({ this.setState({
organizations: (res.msg === undefined) ? res : [], organizations: res.data || [],
}); });
}); });
} }
@@ -75,7 +75,7 @@ class MessageEditPage extends React.Component {
ChatBackend.getChats("admin") ChatBackend.getChats("admin")
.then((res) => { .then((res) => {
this.setState({ this.setState({
chats: (res.msg === undefined) ? res : [], chats: res.data || [],
}); });
}); });
} }
@@ -87,8 +87,9 @@ class MessageEditPage extends React.Component {
Setting.showMessage("error", res.msg); Setting.showMessage("error", res.msg);
return; return;
} }
this.setState({ this.setState({
users: res, users: res.data,
}); });
}); });
} }

View File

@@ -48,7 +48,7 @@ class ModelEditPage extends React.Component {
getModel() { getModel() {
ModelBackend.getModel(this.state.organizationName, this.state.modelName) ModelBackend.getModel(this.state.organizationName, this.state.modelName)
.then((res) => { .then((res) => {
if (res === null) { if (res.data === null) {
this.props.history.push("/404"); this.props.history.push("/404");
return; return;
} }
@@ -59,7 +59,7 @@ class ModelEditPage extends React.Component {
} }
this.setState({ this.setState({
model: res, model: res.data,
}); });
}); });
} }
@@ -68,7 +68,7 @@ class ModelEditPage extends React.Component {
OrganizationBackend.getOrganizations("admin") OrganizationBackend.getOrganizations("admin")
.then((res) => { .then((res) => {
this.setState({ this.setState({
organizations: (res.msg === undefined) ? res : [], organizations: res.data || [],
}); });
}); });
} }

View File

@@ -75,7 +75,7 @@ class OrganizationEditPage extends React.Component {
} }
this.setState({ this.setState({
applications: res, applications: res.data || [],
}); });
}); });
} }

View File

@@ -41,14 +41,14 @@ class PaymentEditPage extends React.Component {
getPayment() { getPayment() {
PaymentBackend.getPayment("admin", this.state.paymentName) PaymentBackend.getPayment("admin", this.state.paymentName)
.then((payment) => { .then((res) => {
if (payment === null) { if (res.data === null) {
this.props.history.push("/404"); this.props.history.push("/404");
return; return;
} }
this.setState({ this.setState({
payment: payment, payment: res.data,
}); });
Setting.scrollToDiv("invoice-area"); Setting.scrollToDiv("invoice-area");

View File

@@ -41,12 +41,12 @@ class PaymentResultPage extends React.Component {
getPayment() { getPayment() {
PaymentBackend.getPayment("admin", this.state.paymentName) PaymentBackend.getPayment("admin", this.state.paymentName)
.then((payment) => { .then((res) => {
this.setState({ this.setState({
payment: payment, payment: res.data,
}); });
if (payment.state === "Created") { if (res.data.state === "Created") {
this.setState({timeout: setTimeout(() => this.getPayment(), 1000)}); this.setState({timeout: setTimeout(() => this.getPayment(), 1000)});
} }
}); });

View File

@@ -50,7 +50,9 @@ class PermissionEditPage extends React.Component {
getPermission() { getPermission() {
PermissionBackend.getPermission(this.state.organizationName, this.state.permissionName) PermissionBackend.getPermission(this.state.organizationName, this.state.permissionName)
.then((res) => { .then((res) => {
if (res === null) { const permission = res.data;
if (permission === null) {
this.props.history.push("/404"); this.props.history.push("/404");
return; return;
} }
@@ -61,14 +63,14 @@ class PermissionEditPage extends React.Component {
} }
this.setState({ this.setState({
permission: res, permission: permission,
}); });
this.getUsers(res.owner); this.getUsers(permission.owner);
this.getRoles(res.owner); this.getRoles(permission.owner);
this.getModels(res.owner); this.getModels(permission.owner);
this.getResources(res.owner); this.getResources(permission.owner);
this.getModel(res.owner, res.model); this.getModel(permission.owner, permission.model);
}); });
} }
@@ -76,7 +78,7 @@ class PermissionEditPage extends React.Component {
OrganizationBackend.getOrganizations("admin") OrganizationBackend.getOrganizations("admin")
.then((res) => { .then((res) => {
this.setState({ this.setState({
organizations: (res.msg === undefined) ? res : [], organizations: res.data || [],
}); });
}); });
} }
@@ -88,8 +90,9 @@ class PermissionEditPage extends React.Component {
Setting.showMessage("error", res.msg); Setting.showMessage("error", res.msg);
return; return;
} }
this.setState({ this.setState({
users: res, users: res.data,
}); });
}); });
} }
@@ -101,8 +104,9 @@ class PermissionEditPage extends React.Component {
Setting.showMessage("error", res.msg); Setting.showMessage("error", res.msg);
return; return;
} }
this.setState({ this.setState({
roles: res, roles: res.data,
}); });
}); });
} }
@@ -114,21 +118,21 @@ class PermissionEditPage extends React.Component {
Setting.showMessage("error", res.msg); Setting.showMessage("error", res.msg);
return; return;
} }
this.setState({ this.setState({
models: res, models: res.data,
}); });
}); });
} }
getModel(organizationName, modelName) { getModel(organizationName, modelName) {
if (modelName === "") {
return;
}
ModelBackend.getModel(organizationName, modelName) ModelBackend.getModel(organizationName, modelName)
.then((res) => { .then((res) => {
if (res.status === "error") {
Setting.showMessage("error", res.msg);
return;
}
this.setState({ this.setState({
model: res, model: res.data,
}); });
}); });
} }
@@ -137,7 +141,7 @@ class PermissionEditPage extends React.Component {
ApplicationBackend.getApplicationsByOrganization("admin", organizationName) ApplicationBackend.getApplicationsByOrganization("admin", organizationName)
.then((res) => { .then((res) => {
this.setState({ this.setState({
resources: (res.msg === undefined) ? res : [], resources: res.data || [],
}); });
}); });
} }

View File

@@ -46,18 +46,18 @@ class PlanEditPage extends React.Component {
getPlan() { getPlan() {
PlanBackend.getPlan(this.state.organizationName, this.state.planName) PlanBackend.getPlan(this.state.organizationName, this.state.planName)
.then((plan) => { .then((res) => {
if (plan === null) { if (res.data === null) {
this.props.history.push("/404"); this.props.history.push("/404");
return; return;
} }
this.setState({ this.setState({
plan: plan, plan: res.data,
}); });
this.getUsers(plan.owner); this.getUsers(this.state.organizationName);
this.getRoles(plan.owner); this.getRoles(this.state.organizationName);
}); });
} }
@@ -68,8 +68,9 @@ class PlanEditPage extends React.Component {
Setting.showMessage("error", res.msg); Setting.showMessage("error", res.msg);
return; return;
} }
this.setState({ this.setState({
roles: res, roles: res.data,
}); });
}); });
} }
@@ -81,8 +82,9 @@ class PlanEditPage extends React.Component {
Setting.showMessage("error", res.msg); Setting.showMessage("error", res.msg);
return; return;
} }
this.setState({ this.setState({
users: res, users: res.data,
}); });
}); });
} }
@@ -91,7 +93,7 @@ class PlanEditPage extends React.Component {
OrganizationBackend.getOrganizations("admin") OrganizationBackend.getOrganizations("admin")
.then((res) => { .then((res) => {
this.setState({ this.setState({
organizations: (res.msg === undefined) ? res : [], organizations: res.data || [],
}); });
}); });
} }

View File

@@ -44,13 +44,12 @@ class PricingEditPage extends React.Component {
this.getPricing(); this.getPricing();
this.getOrganizations(); this.getOrganizations();
this.getApplicationsByOrganization(this.state.organizationName); this.getApplicationsByOrganization(this.state.organizationName);
this.getUserApplication();
} }
getPricing() { getPricing() {
PricingBackend.getPricing(this.state.organizationName, this.state.pricingName) PricingBackend.getPricing(this.state.organizationName, this.state.pricingName)
.then((res) => { .then((res) => {
if (res === null) { if (res.data === null) {
this.props.history.push("/404"); this.props.history.push("/404");
return; return;
} }
@@ -61,9 +60,9 @@ class PricingEditPage extends React.Component {
} }
this.setState({ this.setState({
pricing: res, pricing: res.data,
}); });
this.getPlans(res.owner); this.getPlans(this.state.organizationName);
}); });
} }
@@ -74,8 +73,9 @@ class PricingEditPage extends React.Component {
Setting.showMessage("error", res.msg); Setting.showMessage("error", res.msg);
return; return;
} }
this.setState({ this.setState({
plans: res, plans: res.data,
}); });
}); });
} }
@@ -84,7 +84,16 @@ class PricingEditPage extends React.Component {
OrganizationBackend.getOrganizations("admin") OrganizationBackend.getOrganizations("admin")
.then((res) => { .then((res) => {
this.setState({ this.setState({
organizations: (res.msg === undefined) ? res : [], organizations: res.data || [],
});
});
}
getApplicationsByOrganization(organizationName) {
ApplicationBackend.getApplicationsByOrganization("admin", organizationName)
.then((res) => {
this.setState({
applications: res.data || [],
}); });
}); });
} }
@@ -107,28 +116,6 @@ class PricingEditPage extends React.Component {
}); });
} }
getApplicationsByOrganization(organizationName) {
ApplicationBackend.getApplicationsByOrganization("admin", organizationName)
.then((res) => {
this.setState({
applications: (res.msg === undefined) ? res : [],
});
});
}
getUserApplication() {
ApplicationBackend.getUserApplication(this.state.organizationName, this.state.userName)
.then((res) => {
if (res.status === "error") {
Setting.showMessage("error", res.msg);
return;
}
this.setState({
application: res,
});
});
}
renderPricing() { renderPricing() {
return ( return (
<Card size="small" title={ <Card size="small" title={

View File

@@ -48,7 +48,7 @@ class ProductBuyPage extends React.Component {
} }
this.setState({ this.setState({
product: res, product: res.data,
}); });
}); });
} }

View File

@@ -46,14 +46,14 @@ class ProductEditPage extends React.Component {
getProduct() { getProduct() {
ProductBackend.getProduct(this.state.organizationName, this.state.productName) ProductBackend.getProduct(this.state.organizationName, this.state.productName)
.then((product) => { .then((res) => {
if (product === null) { if (res.data === null) {
this.props.history.push("/404"); this.props.history.push("/404");
return; return;
} }
this.setState({ this.setState({
product: product, product: res.data,
}); });
}); });
} }
@@ -62,7 +62,7 @@ class ProductEditPage extends React.Component {
OrganizationBackend.getOrganizations("admin") OrganizationBackend.getOrganizations("admin")
.then((res) => { .then((res) => {
this.setState({ this.setState({
organizations: (res.msg === undefined) ? res : [], organizations: res.data || [],
}); });
}); });
} }

View File

@@ -50,7 +50,7 @@ class ProviderEditPage extends React.Component {
getProvider() { getProvider() {
ProviderBackend.getProvider(this.state.owner, this.state.providerName) ProviderBackend.getProvider(this.state.owner, this.state.providerName)
.then((res) => { .then((res) => {
if (res === null) { if (res.data === null) {
this.props.history.push("/404"); this.props.history.push("/404");
return; return;
} }
@@ -72,7 +72,7 @@ class ProviderEditPage extends React.Component {
OrganizationBackend.getOrganizations("admin") OrganizationBackend.getOrganizations("admin")
.then((res) => { .then((res) => {
this.setState({ this.setState({
organizations: res.msg === undefined ? res : [], organizations: res.data || [],
}); });
}); });
} }
@@ -527,7 +527,7 @@ class ProviderEditPage extends React.Component {
) )
} }
{ {
(this.state.provider.category === "Captcha" && this.state.provider.type === "Default") || this.state.provider.category === "Web3" ? null : ( (this.state.provider.category === "Captcha" && this.state.provider.type === "Default") || (this.state.provider.category === "Web3") || (this.state.provider.category === "Storage" && this.state.provider.type === "Local File System") ? null : (
<React.Fragment> <React.Fragment>
{ {
this.state.provider.category === "AI" ? null : ( this.state.provider.category === "AI" ? null : (
@@ -616,36 +616,42 @@ class ProviderEditPage extends React.Component {
} }
{this.state.provider.category === "Storage" ? ( {this.state.provider.category === "Storage" ? (
<div> <div>
<Row style={{marginTop: "20px"}} > {["Local File System"].includes(this.state.provider.type) ? null : (
<Col style={{marginTop: "5px"}} span={2}> <Row style={{marginTop: "20px"}} >
{Setting.getLabel(i18next.t("provider:Endpoint"), i18next.t("provider:Region endpoint for Internet"))} : <Col style={{marginTop: "5px"}} span={2}>
</Col> {Setting.getLabel(i18next.t("provider:Endpoint"), i18next.t("provider:Region endpoint for Internet"))} :
<Col span={22} > </Col>
<Input value={this.state.provider.endpoint} onChange={e => { <Col span={22} >
this.updateProviderField("endpoint", e.target.value); <Input value={this.state.provider.endpoint} onChange={e => {
}} /> this.updateProviderField("endpoint", e.target.value);
</Col> }} />
</Row> </Col>
<Row style={{marginTop: "20px"}} > </Row>
<Col style={{marginTop: "5px"}} span={2}> )}
{Setting.getLabel(i18next.t("provider:Endpoint (Intranet)"), i18next.t("provider:Region endpoint for Intranet"))} : {["Local File System", "MinIO", "Tencent Cloud COS"].includes(this.state.provider.type) ? null : (
</Col> <Row style={{marginTop: "20px"}} >
<Col span={22} > <Col style={{marginTop: "5px"}} span={2}>
<Input value={this.state.provider.intranetEndpoint} onChange={e => { {Setting.getLabel(i18next.t("provider:Endpoint (Intranet)"), i18next.t("provider:Region endpoint for Intranet"))} :
this.updateProviderField("intranetEndpoint", e.target.value); </Col>
}} /> <Col span={22} >
</Col> <Input value={this.state.provider.intranetEndpoint} onChange={e => {
</Row> this.updateProviderField("intranetEndpoint", e.target.value);
<Row style={{marginTop: "20px"}} > }} />
<Col style={{marginTop: "5px"}} span={2}> </Col>
{Setting.getLabel(i18next.t("provider:Bucket"), i18next.t("provider:Bucket - Tooltip"))} : </Row>
</Col> )}
<Col span={22} > {["Local File System"].includes(this.state.provider.type) ? null : (
<Input value={this.state.provider.bucket} onChange={e => { <Row style={{marginTop: "20px"}} >
this.updateProviderField("bucket", e.target.value); <Col style={{marginTop: "5px"}} span={2}>
}} /> {Setting.getLabel(i18next.t("provider:Bucket"), i18next.t("provider:Bucket - Tooltip"))} :
</Col> </Col>
</Row> <Col span={22} >
<Input value={this.state.provider.bucket} onChange={e => {
this.updateProviderField("bucket", e.target.value);
}} />
</Col>
</Row>
)}
<Row style={{marginTop: "20px"}} > <Row style={{marginTop: "20px"}} >
<Col style={{marginTop: "5px"}} span={2}> <Col style={{marginTop: "5px"}} span={2}>
{Setting.getLabel(i18next.t("provider:Path prefix"), i18next.t("provider:Path prefix - Tooltip"))} : {Setting.getLabel(i18next.t("provider:Path prefix"), i18next.t("provider:Path prefix - Tooltip"))} :
@@ -656,17 +662,19 @@ class ProviderEditPage extends React.Component {
}} /> }} />
</Col> </Col>
</Row> </Row>
<Row style={{marginTop: "20px"}} > {["MinIO"].includes(this.state.provider.type) ? null : (
<Col style={{marginTop: "5px"}} span={2}> <Row style={{marginTop: "20px"}} >
{Setting.getLabel(i18next.t("provider:Domain"), i18next.t("provider:Domain - Tooltip"))} : <Col style={{marginTop: "5px"}} span={2}>
</Col> {Setting.getLabel(i18next.t("provider:Domain"), i18next.t("provider:Domain - Tooltip"))} :
<Col span={22} > </Col>
<Input value={this.state.provider.domain} onChange={e => { <Col span={22} >
this.updateProviderField("domain", e.target.value); <Input value={this.state.provider.domain} disabled={this.state.provider.type === "Local File System"} onChange={e => {
}} /> this.updateProviderField("domain", e.target.value);
</Col> }} />
</Row> </Col>
{["AWS S3", "MinIO", "Tencent Cloud COS"].includes(this.state.provider.type) ? ( </Row>
)}
{["AWS S3", "Tencent Cloud COS"].includes(this.state.provider.type) ? (
<Row style={{marginTop: "20px"}} > <Row style={{marginTop: "20px"}} >
<Col style={{marginTop: "5px"}} span={2}> <Col style={{marginTop: "5px"}} span={2}>
{Setting.getLabel(i18next.t("provider:Region ID"), i18next.t("provider:Region ID - Tooltip"))} : {Setting.getLabel(i18next.t("provider:Region ID"), i18next.t("provider:Region ID - Tooltip"))} :

View File

@@ -43,7 +43,7 @@ class RoleEditPage extends React.Component {
getRole() { getRole() {
RoleBackend.getRole(this.state.organizationName, this.state.roleName) RoleBackend.getRole(this.state.organizationName, this.state.roleName)
.then((res) => { .then((res) => {
if (res === null) { if (res.data === null) {
this.props.history.push("/404"); this.props.history.push("/404");
return; return;
} }
@@ -53,11 +53,11 @@ class RoleEditPage extends React.Component {
} }
this.setState({ this.setState({
role: res, role: res.data,
}); });
this.getUsers(res.owner); this.getUsers(this.state.organizationName);
this.getRoles(res.owner); this.getRoles(this.state.organizationName);
}); });
} }
@@ -65,7 +65,7 @@ class RoleEditPage extends React.Component {
OrganizationBackend.getOrganizations("admin") OrganizationBackend.getOrganizations("admin")
.then((res) => { .then((res) => {
this.setState({ this.setState({
organizations: (res.msg === undefined) ? res : [], organizations: res.data || [],
}); });
}); });
} }
@@ -77,8 +77,9 @@ class RoleEditPage extends React.Component {
Setting.showMessage("error", res.msg); Setting.showMessage("error", res.msg);
return; return;
} }
this.setState({ this.setState({
users: res, users: res.data,
}); });
}); });
} }
@@ -90,8 +91,9 @@ class RoleEditPage extends React.Component {
Setting.showMessage("error", res.msg); Setting.showMessage("error", res.msg);
return; return;
} }
this.setState({ this.setState({
roles: res, roles: res.data,
}); });
}); });
} }

View File

@@ -47,7 +47,7 @@ class SubscriptionEditPage extends React.Component {
getSubscription() { getSubscription() {
SubscriptionBackend.getSubscription(this.state.organizationName, this.state.subscriptionName) SubscriptionBackend.getSubscription(this.state.organizationName, this.state.subscriptionName)
.then((res) => { .then((res) => {
if (res === null) { if (res.data === null) {
this.props.history.push("/404"); this.props.history.push("/404");
return; return;
} }
@@ -58,11 +58,11 @@ class SubscriptionEditPage extends React.Component {
} }
this.setState({ this.setState({
subscription: res, subscription: res.data,
}); });
this.getUsers(res.owner); this.getUsers(this.state.organizationName);
this.getPlanes(res.owner); this.getPlanes(this.state.organizationName);
}); });
} }
@@ -70,7 +70,7 @@ class SubscriptionEditPage extends React.Component {
PlanBackend.getPlans(organizationName) PlanBackend.getPlans(organizationName)
.then((res) => { .then((res) => {
this.setState({ this.setState({
planes: res, planes: res.data,
}); });
}); });
} }
@@ -82,8 +82,9 @@ class SubscriptionEditPage extends React.Component {
Setting.showMessage("error", res.msg); Setting.showMessage("error", res.msg);
return; return;
} }
this.setState({ this.setState({
users: res, users: res.data,
}); });
}); });
} }
@@ -92,7 +93,7 @@ class SubscriptionEditPage extends React.Component {
OrganizationBackend.getOrganizations("admin") OrganizationBackend.getOrganizations("admin")
.then((res) => { .then((res) => {
this.setState({ this.setState({
organizations: (res.msg === undefined) ? res : [], organizations: res.data || [],
}); });
}); });
} }

View File

@@ -48,7 +48,7 @@ class SyncerEditPage extends React.Component {
getSyncer() { getSyncer() {
SyncerBackend.getSyncer("admin", this.state.syncerName) SyncerBackend.getSyncer("admin", this.state.syncerName)
.then((res) => { .then((res) => {
if (res === null) { if (res.data === null) {
this.props.history.push("/404"); this.props.history.push("/404");
return; return;
} }
@@ -59,7 +59,7 @@ class SyncerEditPage extends React.Component {
} }
this.setState({ this.setState({
syncer: res, syncer: res.data,
}); });
}); });
} }
@@ -68,7 +68,7 @@ class SyncerEditPage extends React.Component {
OrganizationBackend.getOrganizations("admin") OrganizationBackend.getOrganizations("admin")
.then((res) => { .then((res) => {
this.setState({ this.setState({
organizations: (res.msg === undefined) ? res : [], organizations: res.data || [],
}); });
}); });
} }

View File

@@ -36,7 +36,7 @@ class TokenEditPage extends React.Component {
getToken() { getToken() {
TokenBackend.getToken("admin", this.state.tokenName) TokenBackend.getToken("admin", this.state.tokenName)
.then((res) => { .then((res) => {
if (res === null) { if (res.data === null) {
this.props.history.push("/404"); this.props.history.push("/404");
return; return;
} }
@@ -47,7 +47,7 @@ class TokenEditPage extends React.Component {
} }
this.setState({ this.setState({
token: res, token: res.data,
}); });
}); });
} }

View File

@@ -75,19 +75,20 @@ class UserEditPage extends React.Component {
getUser() { getUser() {
UserBackend.getUser(this.state.organizationName, this.state.userName) UserBackend.getUser(this.state.organizationName, this.state.userName)
.then((data) => { .then((res) => {
if (data === null) { if (res.data === null) {
this.props.history.push("/404"); this.props.history.push("/404");
return; return;
} }
if (data.status === null || data.status !== "error") { if (res.status === "error") {
this.setState({ Setting.showMessage("error", res.msg);
user: data, return;
multiFactorAuths: data?.multiFactorAuths ?? [],
});
} }
this.setState({ this.setState({
user: res.data,
multiFactorAuths: res.data?.multiFactorAuths ?? [],
loading: false, loading: false,
}); });
}); });
@@ -108,7 +109,7 @@ class UserEditPage extends React.Component {
OrganizationBackend.getOrganizations("admin") OrganizationBackend.getOrganizations("admin")
.then((res) => { .then((res) => {
this.setState({ this.setState({
organizations: (res.msg === undefined) ? res : [], organizations: res.data || [],
}); });
}); });
} }
@@ -117,7 +118,7 @@ class UserEditPage extends React.Component {
ApplicationBackend.getApplicationsByOrganization("admin", organizationName) ApplicationBackend.getApplicationsByOrganization("admin", organizationName)
.then((res) => { .then((res) => {
this.setState({ this.setState({
applications: (res.msg === undefined) ? res : [], applications: res.data || [],
}); });
}); });
} }
@@ -129,12 +130,10 @@ class UserEditPage extends React.Component {
Setting.showMessage("error", res.msg); Setting.showMessage("error", res.msg);
return; return;
} }
this.setState({
application: res,
});
this.setState({ this.setState({
isGroupsVisible: res.organizationObj.accountItems?.some((item) => item.name === "Groups" && item.visible), application: res.data,
isGroupsVisible: res.data?.organizationObj.accountItems?.some((item) => item.name === "Groups" && item.visible),
}); });
}); });
} }

View File

@@ -122,14 +122,14 @@ class WebhookEditPage extends React.Component {
getWebhook() { getWebhook() {
WebhookBackend.getWebhook("admin", this.state.webhookName) WebhookBackend.getWebhook("admin", this.state.webhookName)
.then((webhook) => { .then((res) => {
if (webhook === null) { if (res.data === null) {
this.props.history.push("/404"); this.props.history.push("/404");
return; return;
} }
this.setState({ this.setState({
webhook: webhook, webhook: res.data,
}); });
}); });
} }
@@ -138,7 +138,7 @@ class WebhookEditPage extends React.Component {
OrganizationBackend.getOrganizations("admin") OrganizationBackend.getOrganizations("admin")
.then((res) => { .then((res) => {
this.setState({ this.setState({
organizations: (res.msg === undefined) ? res : [], organizations: res.data || [],
}); });
}); });
} }

View File

@@ -68,7 +68,7 @@ class ForgetPage extends React.Component {
Setting.showMessage("error", res.msg); Setting.showMessage("error", res.msg);
return; return;
} }
this.onUpdateApplication(res); this.onUpdateApplication(res.data);
}); });
} }
getApplicationObj() { getApplicationObj() {

View File

@@ -170,10 +170,15 @@ class LoginPage extends React.Component {
Setting.showMessage("error", res.msg); Setting.showMessage("error", res.msg);
return; return;
} }
this.onUpdateApplication(res); this.onUpdateApplication(res.data);
}); });
} else { } else {
OrganizationBackend.getDefaultApplication("admin", this.state.owner) let redirectUri = "";
if (this.state.type === "cas") {
const casParams = Util.getCasParameters();
redirectUri = casParams.service;
}
OrganizationBackend.getDefaultApplication("admin", this.state.owner, this.state.type, redirectUri)
.then((res) => { .then((res) => {
if (res.status === "ok") { if (res.status === "ok") {
const application = res.data; const application = res.data;
@@ -183,9 +188,9 @@ class LoginPage extends React.Component {
}); });
} else { } else {
this.onUpdateApplication(null); this.onUpdateApplication(null);
Setting.showMessage("error", res.msg); this.setState({
msg: res.msg,
this.props.history.push("/404"); });
} }
}); });
} }

View File

@@ -69,7 +69,7 @@ class MfaSetupPage extends React.Component {
return; return;
} }
this.setState({ this.setState({
application: res, application: res.data,
}); });
} else { } else {
Setting.showMessage("error", i18next.t("mfa:Failed to get application")); Setting.showMessage("error", i18next.t("mfa:Failed to get application"));

View File

@@ -63,7 +63,7 @@ class PromptPage extends React.Component {
} }
this.setState({ this.setState({
user: res, user: res.data,
}); });
}); });
} }
@@ -80,9 +80,9 @@ class PromptPage extends React.Component {
return; return;
} }
this.onUpdateApplication(res); this.onUpdateApplication(res.data);
this.setState({ this.setState({
application: res, application: res.data,
}); });
}); });
} }

View File

@@ -48,9 +48,10 @@ class ResultPage extends React.Component {
Setting.showMessage("error", res.msg); Setting.showMessage("error", res.msg);
return; return;
} }
this.onUpdateApplication(res);
this.onUpdateApplication(res.data);
this.setState({ this.setState({
application: res, application: res.data,
}); });
}); });
} }

View File

@@ -114,7 +114,7 @@ class SignupPage extends React.Component {
return; return;
} }
this.onUpdateApplication(res); this.onUpdateApplication(res.data);
}); });
} }

View File

@@ -70,8 +70,8 @@ export function deleteOrganization(organization) {
}).then(res => res.json()); }).then(res => res.json());
} }
export function getDefaultApplication(owner, name) { export function getDefaultApplication(owner, name, type = "", redirectUri = "") {
return fetch(`${Setting.ServerUrl}/api/get-default-application?id=${owner}/${encodeURIComponent(name)}`, { return fetch(`${Setting.ServerUrl}/api/get-default-application?id=${owner}/${encodeURIComponent(name)}&type=${type}&redirectUri=${redirectUri}`, {
method: "GET", method: "GET",
credentials: "include", credentials: "include",
headers: { headers: {

View File

@@ -36,7 +36,7 @@ class HomePage extends React.Component {
ApplicationBackend.getApplicationsByOrganization("admin", organizationName) ApplicationBackend.getApplicationsByOrganization("admin", organizationName)
.then((res) => { .then((res) => {
this.setState({ this.setState({
applications: (res.msg === undefined) ? res : [], applications: res.data || [],
}); });
}); });
} }

View File

@@ -15,6 +15,7 @@
import {Checkbox, Form, Modal} from "antd"; import {Checkbox, Form, Modal} from "antd";
import i18next from "i18next"; import i18next from "i18next";
import React, {useEffect, useState} from "react"; import React, {useEffect, useState} from "react";
import * as Setting from "../../Setting";
export const AgreementModal = (props) => { export const AgreementModal = (props) => {
const {open, onOk, onCancel, application} = props; const {open, onOk, onCancel, application} = props;
@@ -31,14 +32,16 @@ export const AgreementModal = (props) => {
<Modal <Modal
title={i18next.t("signup:Terms of Use")} title={i18next.t("signup:Terms of Use")}
open={open} open={open}
width={"55vw"} width={Setting.isMobile() ? "100vw" : "55vw"}
closable={false} closable={false}
okText={i18next.t("signup:Accept")} okText={i18next.t("signup:Accept")}
cancelText={i18next.t("signup:Decline")} cancelText={i18next.t("signup:Decline")}
onOk={onOk} onOk={onOk}
onCancel={onCancel} onCancel={onCancel}
style={{top: Setting.isMobile() ? "5px" : ""}}
maskStyle={{backgroundColor: Setting.isMobile() ? "white" : ""}}
> >
<iframe title={"terms"} style={{border: 0, width: "100%", height: "60vh"}} srcDoc={doc} /> <iframe title={"terms"} style={{border: 0, width: "100%", height: Setting.isMobile() ? "80vh" : "60vh"}} srcDoc={doc} />
</Modal> </Modal>
); );
}; };