package sec

import (
	"gex/pkg/gex"
	"gex/pkg/sess"
)

func Middleware(req *gex.Req, res gex.Res) bool {
	pattern := req.Pattern

	// Cancel the security check as there are no permissions for this route
	if len(permissions[pattern]) == 0 {
		return true
	}

	handlerRoles := permissions[pattern]
	sess := req.Ctx["Sess"].(sess.Sess)

	for _, role := range handlerRoles {
		if sess.HasRole(role) {
			return true
		}
	}

	res.Send("No Access")
	return false
}
