ultisuite-backend/internal/apitokens/scope.go
R3D347HR4Y 1d063237b9
Some checks are pending
CI / Go tests (push) Waiting to run
CI / Integration tests (push) Waiting to run
CI / DB migrations (push) Waiting to run
feat(transcription): integrate Faster Whisper for Jitsi transcriptions
- Added support for Faster Whisper transcription via Jigasi and Skynet.
- Updated .env.example to include new environment variables for transcription settings.
- Enhanced Jitsi Docker Compose configuration to include Skynet and Jigasi services.
- Introduced new API endpoints for managing organizational folders in the drive service.
- Updated Nextcloud initialization script to enable external file mounting.
- Improved error handling and response structures in the drive API.
- Added new properties for organization settings related to transcription and agenda management.
2026-06-12 19:10:18 +02:00

102 lines
2.1 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
}
// Scoped paths: org:{id}:/path or mount:{id}:/path
if strings.HasPrefix(target, "org:") || strings.HasPrefix(target, "mount:") {
for _, allowed := range auth.DriveScope.FolderPaths {
if driveScopePrefixMatch(target, allowed) {
return true
}
}
return false
}
for _, allowed := range auth.DriveScope.FolderPaths {
if drivePathWithinScope(target, allowed) {
return true
}
}
return false
}
func driveScopePrefixMatch(target, allowed string) bool {
allowed = strings.TrimSpace(allowed)
if allowed == "" || allowed == "/" {
return true
}
return target == allowed || strings.HasPrefix(target, allowed+":") || strings.HasPrefix(target, allowed+"/")
}
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+"/")
}
func AllowsAgendaCalendar(auth *AuthContext, calendarID string) bool {
if auth == nil || calendarID == "" {
return true
}
if auth.AgendaScope.AllCalendars {
return true
}
for _, id := range auth.AgendaScope.CalendarIDs {
if id == calendarID {
return true
}
}
return false
}