Revert "fix: refactor AddPolicy"

This reverts commit 17f16c53af.
This commit is contained in:
Derrick Hammer 2024-01-15 23:08:44 -05:00
parent 17f16c53af
commit b2d863d466
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 6 additions and 5 deletions

View File

@ -5,6 +5,7 @@ import (
"github.com/casbin/casbin/v2/model"
"github.com/casbin/casbin/v2/persist"
"go.uber.org/zap"
"strings"
"sync"
)
@ -23,9 +24,9 @@ func GetCasbin(logger *zap.Logger) *casbin.Enforcer {
}
// Add policies after creating the enforcer
_ = a.AddPolicy("admin", "/admin", "GET")
_ = a.AddPolicy("admin", "/admin", "POST")
_ = a.AddPolicy("admin", "/admin", "DELETE")
_ = a.AddPolicy("admin", "/admin", []string{"GET"})
_ = a.AddPolicy("admin", "/admin", []string{"POST"})
_ = a.AddPolicy("admin", "/admin", []string{"DELETE"})
err = e.LoadPolicy()
if err != nil {
@ -70,12 +71,12 @@ func (a *PolicyAdapter) SavePolicy(model model.Model) error {
// AddPolicy adds a policy rule to the storage.
// AddPolicy adds a policy rule to the storage.
func (a *PolicyAdapter) AddPolicy(sub string, obj string, act string) error {
func (a *PolicyAdapter) AddPolicy(sec string, ptype string, rule []string) error {
a.lock.Lock()
defer a.lock.Unlock()
// Create a line representing the policy rule
line := sub + ", " + obj + ", " + act
line := ptype + ", " + strings.Join(rule, ", ")
// Check if the policy rule already exists
for _, existingLine := range a.policy {