37 lines
921 B
Go
37 lines
921 B
Go
package state
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
|
|
"simplegit/common"
|
|
)
|
|
|
|
var (
|
|
ErrDenied = errors.New("access denied")
|
|
|
|
ErrInvalidToken = errors.New("invalid or expired token")
|
|
|
|
ErrInvalidCredentials = errors.New("invalid username or password")
|
|
|
|
ErrRepoNotFound = errors.New("repository not found")
|
|
|
|
ErrNamespaceNotFound = errors.New("namespace does not exist")
|
|
)
|
|
|
|
func (s *LocalState) hasAccess(credType CredType, credID, repoID, nsID int64, perm common.Perm) (bool, error) {
|
|
var acls []ACL
|
|
err := s.engine.Where("cred_type = ? AND cred_id = ? AND ((target_type = ? AND target_id = ?) OR (target_type = ? AND target_id = ?))",
|
|
credType, credID, TargetTypeRepo, repoID, TargetTypeNS, nsID).Find(&acls)
|
|
if err != nil {
|
|
return false, fmt.Errorf("lookup acl: %w", err)
|
|
}
|
|
best := 0
|
|
for _, a := range acls {
|
|
if r := common.Perm(a.Perm).PermRank(); r > best {
|
|
best = r
|
|
}
|
|
}
|
|
return best >= perm.PermRank(), nil
|
|
}
|