feat: make hard-coded authz adapter editable, rename adapter to ormer (#2149)

* refactor: rename casbinAdapter to casdoorAdapter

* feat: add initEnforcer

* fix: router

* refactor: make hard-coded code configurable

* fix: data type

* feat: support sqlite3

* feat: disable delete and edit name for built in resources

* feat: optimize code

* fix: init

* fix: e2e

* fix: remove datasourcename

* fix: revert rename

* refactor: change all ORM's Adatper to Ormer

* refactor: name
This commit is contained in:
Yaodong Yu
2023-07-29 15:07:04 +08:00
committed by GitHub
parent 74b058aa3f
commit ea10f8e615
56 changed files with 1314 additions and 1031 deletions

View File

@ -69,7 +69,7 @@ func GetSubscriptionCount(owner, field, value string) (int64, error) {
func GetSubscriptions(owner string) ([]*Subscription, error) {
subscriptions := []*Subscription{}
err := adapter.Engine.Desc("created_time").Find(&subscriptions, &Subscription{Owner: owner})
err := ormer.Engine.Desc("created_time").Find(&subscriptions, &Subscription{Owner: owner})
if err != nil {
return subscriptions, err
}
@ -94,7 +94,7 @@ func getSubscription(owner string, name string) (*Subscription, error) {
}
subscription := Subscription{Owner: owner, Name: name}
existed, err := adapter.Engine.Get(&subscription)
existed, err := ormer.Engine.Get(&subscription)
if err != nil {
return nil, err
}
@ -119,7 +119,7 @@ func UpdateSubscription(id string, subscription *Subscription) (bool, error) {
return false, nil
}
affected, err := adapter.Engine.ID(core.PK{owner, name}).AllCols().Update(subscription)
affected, err := ormer.Engine.ID(core.PK{owner, name}).AllCols().Update(subscription)
if err != nil {
return false, err
}
@ -128,7 +128,7 @@ func UpdateSubscription(id string, subscription *Subscription) (bool, error) {
}
func AddSubscription(subscription *Subscription) (bool, error) {
affected, err := adapter.Engine.Insert(subscription)
affected, err := ormer.Engine.Insert(subscription)
if err != nil {
return false, err
}
@ -137,7 +137,7 @@ func AddSubscription(subscription *Subscription) (bool, error) {
}
func DeleteSubscription(subscription *Subscription) (bool, error) {
affected, err := adapter.Engine.ID(core.PK{subscription.Owner, subscription.Name}).Delete(&Subscription{})
affected, err := ormer.Engine.ID(core.PK{subscription.Owner, subscription.Name}).Delete(&Subscription{})
if err != nil {
return false, err
}