Add profile 3D preferences and adapt DICOM preview resolution to memory budget
This commit is contained in:
1 parent
705762d57c
commit
7fd7ae6733
22 files changed
+500
-68
No files matched your search
@@ -0,0 +1,26 @@
|
||||
package users
|
||||
|
||||
type Dicom3DSettings struct {
|
||||
MemoryMiB int `json:"memoryMiB"`
|
||||
Quality string `json:"quality"`
|
||||
Opacity int `json:"opacity"`
|
||||
}
|
||||
|
||||
func (s Dicom3DSettings) Normalized() Dicom3DSettings {
|
||||
if s.MemoryMiB == 0 {
|
||||
s.MemoryMiB = 1536
|
||||
}
|
||||
if s.Quality == "" {
|
||||
s.Quality = "auto"
|
||||
}
|
||||
if s.Opacity == 0 {
|
||||
s.Opacity = 30
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func (s Dicom3DSettings) Valid() bool {
|
||||
s = s.Normalized()
|
||||
return s.MemoryMiB >= 128 && s.MemoryMiB <= 1536 && s.Opacity >= 5 && s.Opacity <= 100 &&
|
||||
(s.Quality == "auto" || s.Quality == "original" || s.Quality == "half" || s.Quality == "quarter")
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package users
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestDicom3DSettings(t *testing.T) {
|
||||
defaults := (Dicom3DSettings{}).Normalized()
|
||||
if defaults.MemoryMiB != 1536 || defaults.Quality != "auto" || defaults.Opacity != 30 || !defaults.Valid() {
|
||||
t.Fatal(defaults)
|
||||
}
|
||||
for _, bad := range []Dicom3DSettings{{MemoryMiB: 1537}, {MemoryMiB: -1}, {MemoryMiB: 127}, {Quality: "invalid"}, {Opacity: 101}, {Opacity: -1}} {
|
||||
if bad.Valid() {
|
||||
t.Fatalf("accepted invalid preferences: %+v", bad)
|
||||
}
|
||||
u := User{Dicom3D: bad}
|
||||
if u.Clean("", false, "Dicom3D") == nil {
|
||||
t.Fatalf("saved invalid preferences: %+v", bad)
|
||||
}
|
||||
}
|
||||
for _, quality := range []string{"auto", "original", "half", "quarter"} {
|
||||
u := User{Dicom3D: Dicom3DSettings{MemoryMiB: 512, Quality: quality, Opacity: 50}}
|
||||
if err := u.Clean("", false, "Dicom3D"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
+28
-21
@@ -19,27 +19,28 @@ const (
|
||||
|
||||
// User describes a user.
|
||||
type User struct {
|
||||
ID uint `storm:"id,increment" json:"id"`
|
||||
Username string `storm:"unique" json:"username"`
|
||||
DisplayName string `json:"displayName,omitempty"`
|
||||
ProfileName string `json:"profileName,omitempty"`
|
||||
Email string `json:"email,omitempty"`
|
||||
Password string `json:"password"`
|
||||
Scope string `json:"scope"`
|
||||
Locale string `json:"locale"`
|
||||
LockPassword bool `json:"lockPassword"`
|
||||
ViewMode ViewMode `json:"viewMode"`
|
||||
SingleClick bool `json:"singleClick"`
|
||||
RedirectAfterCopyMove bool `json:"redirectAfterCopyMove"`
|
||||
Perm Permissions `json:"perm"`
|
||||
Commands []string `json:"commands"`
|
||||
Sorting files.Sorting `json:"sorting"`
|
||||
Fs afero.Fs `json:"-" yaml:"-"`
|
||||
Rules []rules.Rule `json:"rules"`
|
||||
HideDotfiles bool `json:"hideDotfiles"`
|
||||
HidePreviews bool `json:"hidePreviews"`
|
||||
DateFormat bool `json:"dateFormat"`
|
||||
AceEditorTheme string `json:"aceEditorTheme"`
|
||||
ID uint `storm:"id,increment" json:"id"`
|
||||
Username string `storm:"unique" json:"username"`
|
||||
DisplayName string `json:"displayName,omitempty"`
|
||||
ProfileName string `json:"profileName,omitempty"`
|
||||
Email string `json:"email,omitempty"`
|
||||
Password string `json:"password"`
|
||||
Scope string `json:"scope"`
|
||||
Locale string `json:"locale"`
|
||||
LockPassword bool `json:"lockPassword"`
|
||||
ViewMode ViewMode `json:"viewMode"`
|
||||
SingleClick bool `json:"singleClick"`
|
||||
RedirectAfterCopyMove bool `json:"redirectAfterCopyMove"`
|
||||
Perm Permissions `json:"perm"`
|
||||
Commands []string `json:"commands"`
|
||||
Sorting files.Sorting `json:"sorting"`
|
||||
Fs afero.Fs `json:"-" yaml:"-"`
|
||||
Rules []rules.Rule `json:"rules"`
|
||||
HideDotfiles bool `json:"hideDotfiles"`
|
||||
HidePreviews bool `json:"hidePreviews"`
|
||||
Dicom3D Dicom3DSettings `json:"dicom3D"`
|
||||
DateFormat bool `json:"dateFormat"`
|
||||
AceEditorTheme string `json:"aceEditorTheme"`
|
||||
}
|
||||
|
||||
// GetRules implements rules.Provider.
|
||||
@@ -55,6 +56,7 @@ var checkableFields = []string{
|
||||
"Commands",
|
||||
"Sorting",
|
||||
"Rules",
|
||||
"Dicom3D",
|
||||
}
|
||||
|
||||
// Clean cleans up a user and verifies if all its fields
|
||||
@@ -66,6 +68,11 @@ func (u *User) Clean(baseScope string, followExternalSymlinks bool, fields ...st
|
||||
|
||||
for _, field := range fields {
|
||||
switch field {
|
||||
case "Dicom3D":
|
||||
if !u.Dicom3D.Valid() {
|
||||
return fberrors.ErrInvalidRequestParams
|
||||
}
|
||||
u.Dicom3D = u.Dicom3D.Normalized()
|
||||
case "Username":
|
||||
if u.Username == "" {
|
||||
return fberrors.ErrEmptyUsername
|
||||
|
||||
Reference in new issue
Block a user