yao/attachment/convert.go
Max 5d18e76acd Enhance attachment management with public and share fields
- Introduced new fields in the attachment model for public access control and sharing options, allowing attachments to be marked as public or shared with specific teams.
- Updated the upload process to handle new permission fields, ensuring proper handling of public and share options during file uploads.
- Implemented permission checks in the file retrieval and deletion processes to enforce access control based on user roles and attachment settings.
- Added comprehensive tests for the new permission fields to validate functionality and ensure correct behavior in various scenarios.
2025-11-05 18:11:36 +08:00

61 lines
982 B
Go

package attachment
import (
"fmt"
"strings"
)
// toBool converts various types to boolean
func toBool(v interface{}) bool {
if v == nil {
return false
}
switch val := v.(type) {
case bool:
return val
case int:
return val != 0
case int64:
return val != 0
case uint8: // MySQL tinyint(1)
return val != 0
case float64:
return val != 0
case string:
normalized := strings.ToLower(strings.TrimSpace(val))
switch normalized {
case "true", "1", "enabled", "yes", "on":
return true
default:
return false
}
default:
return false
}
}
// toString converts various types to string
func toString(v interface{}) string {
if v == nil {
return ""
}
switch val := v.(type) {
case string:
return val
case int:
return fmt.Sprintf("%d", val)
case int64:
return fmt.Sprintf("%d", val)
case float64:
return fmt.Sprintf("%.0f", val)
case bool:
if val {
return "true"
}
return "false"
default:
return fmt.Sprintf("%v", val)
}
}