-
Notifications
You must be signed in to change notification settings - Fork 180
/
ws-attributes.go
38 lines (33 loc) · 972 Bytes
/
ws-attributes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package idm
import (
"strings"
json "github.com/pydio/cells/x/jsonx"
)
type WsAttributes struct {
AllowSync bool `json:"ALLOW_SYNC,omitempty"`
SkipRecycle bool `json:"SKIP_RECYCLE,omitempty"`
DefaultRights string `json:"DEFAULT_RIGHTS,omitempty"`
QuotaValue string `json:"QUOTA,omitempty"`
MetaLayout string `json:"META_LAYOUT,omitempty"`
}
func (m *Workspace) LoadAttributes() *WsAttributes {
attributes := &WsAttributes{}
if m.Attributes != "" && m.Attributes != "{}" {
// In case bool value was stored as string
strAttr := strings.ReplaceAll(m.Attributes, "\"true\"", "true")
strAttr = strings.ReplaceAll(strAttr, "\"false\"", "false")
// Unmarshal to WsAttributes struct
if e := json.Unmarshal([]byte(strAttr), attributes); e == nil {
return attributes
}
}
return attributes
}
func (m *Workspace) SetAttributes(a *WsAttributes) {
bb, _ := json.Marshal(a)
s := string(bb)
if s == "{}" {
s = ""
}
m.Attributes = s
}