forked from pydio/cells
/
meta-user.go
158 lines (139 loc) · 4.62 KB
/
meta-user.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package modifiers
import (
"context"
"github.com/pydio/cells/common/config"
json "github.com/pydio/cells/x/jsonx"
service "github.com/pydio/cells/common/service/proto"
"github.com/pydio/cells/common"
defaults "github.com/pydio/cells/common/micro"
"github.com/pydio/cells/common/proto/idm"
"github.com/pydio/cells/common/service/frontend"
)
// MetaUserRegModifier adds/updates some registry contributions for rendering metadata.
func MetaUserRegModifier(ctx context.Context, status frontend.RequestStatus, registry *frontend.Cpydio_registry) error {
client := idm.NewUserMetaServiceClient(common.ServiceGrpcNamespace_+common.ServiceUserMeta, defaults.NewClient())
respStream, e := client.ListUserMetaNamespace(ctx, &idm.ListUserMetaNamespaceRequest{})
if e != nil {
return e
}
defer respStream.Close()
var namespaces []*idm.UserMetaNamespace
for {
r, e := respStream.Recv()
if e != nil {
break
}
namespaces = append(namespaces, r.UserMetaNamespace)
}
if len(namespaces) == 0 {
return nil
}
columns := &frontend.Ccolumns{}
searchables := make(map[string]string)
searchableRenderers := make(map[string]string)
var crtAdmin bool
if status.User.Logged && status.User.UserObject.Attributes != nil {
if p, ok := status.User.UserObject.Attributes[idm.UserAttrProfile]; ok && p == common.PydioProfileAdmin {
crtAdmin = true
}
}
for _, ns := range namespaces {
var readAdminOnly bool
for _, p := range ns.Policies {
if p.Action == service.ResourcePolicyAction_READ && p.Subject == "profile:admin" {
readAdminOnly = true
}
}
if readAdminOnly && !crtAdmin {
continue
}
var nsDef map[string]interface{}
if e := json.Unmarshal([]byte(ns.JsonDefinition), &nsDef); e != nil {
continue
}
nsType := nsDef["type"].(string)
if nsType == "json" {
continue
}
column := &frontend.Cadditional_column{
AttrmessageString: ns.Label,
AttrattributeName: ns.Namespace,
AttrsortType: "String",
AttrdefaultVisibilty: "true",
}
if ns.Indexable {
searchables[ns.Namespace] = ns.Label
}
switch nsType {
case "stars_rate":
column.AttrreactModifier = "ReactMeta.Renderer.renderStars"
column.AttrsortType = "CellSorterValue"
if ns.Indexable {
searchableRenderers[ns.Namespace] = "ReactMeta.Renderer.formPanelStars"
}
case "css_label":
column.AttrreactModifier = "ReactMeta.Renderer.renderCSSLabel"
column.AttrsortType = "CellSorterValue"
if ns.Indexable {
searchableRenderers[ns.Namespace] = "ReactMeta.Renderer.formPanelCssLabels"
}
case "choice":
column.AttrreactModifier = "ReactMeta.Renderer.renderSelector"
column.AttrsortType = "CellSorterValue"
if data, ok := nsDef["data"]; ok {
remarshed, _ := json.Marshal(data)
column.AttrmetaAdditional = string(remarshed)
}
if ns.Indexable {
searchableRenderers[ns.Namespace] = "ReactMeta.Renderer.formPanelSelectorFilter"
}
case "tags":
column.AttrreactModifier = "ReactMeta.Renderer.renderTagsCloud"
if ns.Indexable {
searchableRenderers[ns.Namespace] = "ReactMeta.Renderer.formPanelTags"
}
}
columns.Cadditional_column = append(columns.Cadditional_column, column)
}
// Add a section in the registry_contribution
if registry.Cclient_configs == nil {
registry.Cclient_configs = &frontend.Cclient_configs{
Ccomponent_config: []*frontend.Ccomponent_config{},
}
}
registry.Cclient_configs.Ccomponent_config = append(registry.Cclient_configs.Ccomponent_config, &frontend.Ccomponent_config{
Attrcomponent: "FilesList",
Ccolumns: columns,
})
if len(searchables) > 0 {
appendPart := true
tPart := &frontend.Ctemplate_part{
AttrajxpId: "search_container",
AttrajxpClass: "SearchEngine",
Attrtheme: "material",
}
optionsData := make(map[string]interface{})
for _, part := range registry.Cclient_configs.Ctemplate_part {
if part.AttrajxpId == "search_container" && part.AttrajxpClass == "SearchEngine" && part.Attrtheme == "material" {
tPart = part
var options map[string]interface{}
if e := json.Unmarshal([]byte(part.AttrajxpOptions), &options); e == nil {
optionsData = options
}
appendPart = false
break
}
}
optionsData["metaColumns"] = searchables
optionsData["reactColumnsRenderers"] = searchableRenderers
if config.Get("services", common.ServiceGrpcNamespace_+common.ServiceSearch, "indexContent").Default(false).Bool() {
optionsData["indexContent"] = true
}
searchOptions, _ := json.Marshal(optionsData)
tPart.AttrajxpOptions = string(searchOptions)
if appendPart {
registry.Cclient_configs.Ctemplate_part = append(registry.Cclient_configs.Ctemplate_part, tPart)
}
}
return nil
}