diff --git a/cmd/aicra/main.go b/cmd/aicra/main.go index cf70552..6855455 100644 --- a/cmd/aicra/main.go +++ b/cmd/aicra/main.go @@ -158,7 +158,7 @@ func main() { /* (3) Compile middlewares */ if compileMiddlewares { clifmt.Title("compile middlewares") - err = buildControllers(mPath, filepath.Join(projectPath, ".build/middleware")) + err = buildTypes(mPath, filepath.Join(projectPath, ".build/middleware")) if err != nil { fmt.Printf("%s compilation error: %s\n", clifmt.Warn(), err) } diff --git a/config/method.go b/config/method.go index ba7ce0a..03fb08e 100644 --- a/config/method.go +++ b/config/method.go @@ -1,7 +1,6 @@ package config import ( - "fmt" "git.xdrm.io/go/aicra/middleware" ) @@ -12,6 +11,36 @@ import ( // > level 1 is OR // > level 2 is AND func (m *Method) CheckScope(scope middleware.Scope) bool { - fmt.Printf("Scope: %v\n", m.Permission) + + for _, OR := range m.Permission { + + granted := true + + for _, AND := range OR { + + if !isPermInScope(AND, scope) { + granted = false + break + } + + } + + // if one is valid -> grant + if granted { + return true + } + + } + + return false +} + +// Returns whether @perm is present in @scope +func isPermInScope(perm string, scope []string) bool { + for _, s := range scope { + if perm == s { + return true + } + } return false }