|
|
@@ -3,42 +3,78 @@ package grpcapi
|
|
|
import (
|
|
|
apiv1 "github.com/OliveTin/OliveTin/gen/grpc/olivetin/api/v1"
|
|
|
config "github.com/OliveTin/OliveTin/internal/config"
|
|
|
+ log "github.com/sirupsen/logrus"
|
|
|
"golang.org/x/exp/slices"
|
|
|
)
|
|
|
|
|
|
-func dashboardCfgToPb(res *apiv1.GetDashboardComponentsResponse, dashboards []*config.DashboardComponent, cfg *config.Config) {
|
|
|
- for _, dashboard := range dashboards {
|
|
|
- res.Dashboards = append(res.Dashboards, &apiv1.DashboardComponent{
|
|
|
+func dashboardCfgToPb(rr *DashboardRenderRequest) []*apiv1.DashboardComponent {
|
|
|
+ ret := make([]*apiv1.DashboardComponent, 0)
|
|
|
+
|
|
|
+ for _, dashboard := range cfg.Dashboards {
|
|
|
+ pbdb := &apiv1.DashboardComponent{
|
|
|
Type: "dashboard",
|
|
|
Title: dashboard.Title,
|
|
|
- Contents: getDashboardComponentContents(dashboard, cfg),
|
|
|
- })
|
|
|
+ Contents: removeNulls(getDashboardComponentContents(dashboard, rr)),
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(pbdb.Contents) == 0 {
|
|
|
+ log.WithFields(log.Fields{
|
|
|
+ "dashboard": dashboard.Title,
|
|
|
+ "username": rr.AuthenticatedUser.Username,
|
|
|
+ }).Debugf("Dashboard has no readable contents, so it will not be visible in the web ui")
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ ret = append(ret, pbdb)
|
|
|
}
|
|
|
+
|
|
|
+ return ret
|
|
|
}
|
|
|
|
|
|
-func getDashboardComponentContents(dashboard *config.DashboardComponent, cfg *config.Config) []*apiv1.DashboardComponent {
|
|
|
+func removeNulls(components []*apiv1.DashboardComponent) []*apiv1.DashboardComponent {
|
|
|
ret := make([]*apiv1.DashboardComponent, 0)
|
|
|
|
|
|
- for _, subitem := range dashboard.Contents {
|
|
|
- if subitem.Type == "fieldset" && subitem.Entity != "" {
|
|
|
- ret = append(ret, buildEntityFieldsets(subitem.Entity, &subitem)...)
|
|
|
+ for _, component := range components {
|
|
|
+ if component == nil {
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
- newitem := &apiv1.DashboardComponent{
|
|
|
- Title: subitem.Title,
|
|
|
- Type: getDashboardComponentType(&subitem),
|
|
|
- Contents: getDashboardComponentContents(&subitem, cfg),
|
|
|
- Icon: getDashboardComponentIcon(&subitem, cfg),
|
|
|
- CssClass: subitem.CssClass,
|
|
|
- }
|
|
|
+ ret = append(ret, component)
|
|
|
+ }
|
|
|
|
|
|
- ret = append(ret, newitem)
|
|
|
+ return ret
|
|
|
+}
|
|
|
+
|
|
|
+func getDashboardComponentContents(dashboard *config.DashboardComponent, rr *DashboardRenderRequest) []*apiv1.DashboardComponent {
|
|
|
+ ret := make([]*apiv1.DashboardComponent, 0)
|
|
|
+
|
|
|
+ for _, subitem := range dashboard.Contents {
|
|
|
+ if subitem.Type == "fieldset" && subitem.Entity != "" {
|
|
|
+ ret = append(ret, buildEntityFieldsets(subitem.Entity, &subitem, rr)...)
|
|
|
+ } else {
|
|
|
+ ret = append(ret, buildDashboardComponentSimple(&subitem, rr))
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return ret
|
|
|
}
|
|
|
|
|
|
+func buildDashboardComponentSimple(subitem *config.DashboardComponent, rr *DashboardRenderRequest) *apiv1.DashboardComponent {
|
|
|
+ if !slices.Contains(rr.AllowedActionTitles, subitem.Title) {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+
|
|
|
+ newitem := &apiv1.DashboardComponent{
|
|
|
+ Title: subitem.Title,
|
|
|
+ Type: getDashboardComponentType(subitem),
|
|
|
+ Contents: getDashboardComponentContents(subitem, rr),
|
|
|
+ Icon: getDashboardComponentIcon(subitem, rr.cfg),
|
|
|
+ CssClass: subitem.CssClass,
|
|
|
+ }
|
|
|
+
|
|
|
+ return newitem
|
|
|
+}
|
|
|
+
|
|
|
func getDashboardComponentIcon(item *config.DashboardComponent, cfg *config.Config) string {
|
|
|
if item.Icon == "" {
|
|
|
return cfg.DefaultIconForDirectories
|