fix(05): WR-04 default File.IsPublic to true without trapping false

This commit is contained in:
Jakub Zych
2026-09-19 15:34:50 +02:00
parent fb12b2237d
commit c12e6576f6
3 changed files with 99 additions and 16 deletions

View File

@@ -22,25 +22,37 @@ type Owner interface {
// File is Winter's system_files row. AttachmentID is a string because
// Winter stores the morph FK as a string, never an integer.
type File struct {
ID uint `gorm:"column:id;primaryKey"`
DiskName string `gorm:"column:disk_name"`
FileName string `gorm:"column:file_name"`
FileSize int64 `gorm:"column:file_size"`
ContentType string `gorm:"column:content_type"`
Title *string `gorm:"column:title"`
Description *string `gorm:"column:description"`
Field string `gorm:"column:field"`
AttachmentID string `gorm:"column:attachment_id"`
AttachmentType string `gorm:"column:attachment_type"`
IsPublic bool `gorm:"column:is_public"`
SortOrder int `gorm:"column:sort_order"`
Metadata *string `gorm:"column:metadata"`
CreatedAt time.Time `gorm:"column:created_at"`
UpdatedAt time.Time `gorm:"column:updated_at"`
ID uint `gorm:"column:id;primaryKey"`
DiskName string `gorm:"column:disk_name"`
FileName string `gorm:"column:file_name"`
FileSize int64 `gorm:"column:file_size"`
ContentType string `gorm:"column:content_type"`
Title *string `gorm:"column:title"`
Description *string `gorm:"column:description"`
Field string `gorm:"column:field"`
AttachmentID string `gorm:"column:attachment_id"`
AttachmentType string `gorm:"column:attachment_type"`
// Pointer so GORM can distinguish unset (nil → DEFAULT TRUE) from
// explicit false. A non-pointer bool with default:true cannot persist
// false because false is the zero value GORM replaces with the default.
IsPublic *bool `gorm:"column:is_public;not null;default:true"`
SortOrder int `gorm:"column:sort_order"`
Metadata *string `gorm:"column:metadata"`
CreatedAt time.Time `gorm:"column:created_at"`
UpdatedAt time.Time `gorm:"column:updated_at"`
}
func (File) TableName() string { return "system_files" }
// Public reports Winter's is_public flag. A nil pointer is treated as true,
// matching the SQL DEFAULT TRUE and File::create() behaviour.
func (f File) Public() bool {
if f.IsPublic == nil {
return true
}
return *f.IsPublic
}
var all []any
// Register appends models so schema tooling can see File without a plugin registry.