ultisuite-backend/internal/apitokens/scope.go
R3D347HR4Y bd7534658a Refactor and enhance unified frontend and API features
- Updated environment configuration to unify frontend for mail and drive under a single service.
- Revised README to reflect changes in frontend setup and routing for the unified application.
- Introduced new API documentation endpoints for better accessibility of API specifications.
- Enhanced drive and mail services with improved handling of file uploads and metadata enrichment.
- Implemented new API token management features, including creation, listing, and revocation of tokens.
- Added tests for new functionalities in drive and mail services to ensure reliability and correctness.
2026-06-07 15:44:30 +02:00

70 lines
1.3 KiB
Go

package apitokens
import (
"path"
"strings"
"github.com/ultisuite/ulti-backend/internal/nextcloud"
)
func AllowsMailAccount(auth *AuthContext, accountID string) bool {
if auth == nil || accountID == "" {
return true
}
if auth.MailScope.AllAccounts {
return true
}
for _, id := range auth.MailScope.AccountIDs {
if id == accountID {
return true
}
}
return false
}
func AllowsDrivePath(auth *AuthContext, rawPath string) bool {
if auth == nil {
return true
}
if auth.DriveScope.AllFolders {
return true
}
target := NormalizeDriveScopePath(rawPath)
if target == "" {
return true
}
for _, allowed := range auth.DriveScope.FolderPaths {
if drivePathWithinScope(target, allowed) {
return true
}
}
return false
}
func NormalizeDriveScopePath(rawPath string) string {
rawPath = strings.TrimSpace(rawPath)
if rawPath == "" {
return ""
}
normalized := nextcloud.NormalizeClientPath(rawPath)
if normalized == "" {
return "/"
}
if !strings.HasPrefix(normalized, "/") {
normalized = "/" + normalized
}
return path.Clean(normalized)
}
func drivePathWithinScope(target, allowed string) bool {
target = NormalizeDriveScopePath(target)
allowed = NormalizeDriveScopePath(allowed)
if allowed == "/" {
return true
}
if target == allowed {
return true
}
return strings.HasPrefix(target, allowed+"/")
}