mirror of
https://github.com/OliveTin/OliveTin
synced 2025-12-13 01:25:45 +00:00
63 lines
1.4 KiB
Go
63 lines
1.4 KiB
Go
package grpcapi
|
|
|
|
import (
|
|
"crypto/md5"
|
|
"fmt"
|
|
pb "github.com/jamesread/OliveTin/gen/grpc"
|
|
acl "github.com/jamesread/OliveTin/internal/acl"
|
|
config "github.com/jamesread/OliveTin/internal/config"
|
|
)
|
|
|
|
func actionsCfgToPb(cfgActions []config.Action, user *acl.User) *pb.GetDashboardComponentsResponse {
|
|
res := &pb.GetDashboardComponentsResponse{}
|
|
|
|
for _, action := range cfgActions {
|
|
if !acl.IsAllowedView(cfg, user, &action) {
|
|
continue
|
|
}
|
|
|
|
btn := actionCfgToPb(action, user)
|
|
res.Actions = append(res.Actions, btn)
|
|
}
|
|
|
|
return res
|
|
}
|
|
|
|
func actionCfgToPb(action config.Action, user *acl.User) *pb.Action {
|
|
btn := pb.Action{
|
|
Id: fmt.Sprintf("%x", md5.Sum([]byte(action.Title))),
|
|
Title: action.Title,
|
|
Icon: action.Icon,
|
|
CanExec: acl.IsAllowedExec(cfg, user, &action),
|
|
}
|
|
|
|
for _, cfgArg := range action.Arguments {
|
|
pbArg := pb.ActionArgument{
|
|
Name: cfgArg.Name,
|
|
Title: cfgArg.Title,
|
|
Type: cfgArg.Type,
|
|
DefaultValue: cfgArg.Default,
|
|
Choices: buildChoices(cfgArg.Choices),
|
|
}
|
|
|
|
btn.Arguments = append(btn.Arguments, &pbArg)
|
|
}
|
|
|
|
return &btn
|
|
}
|
|
|
|
func buildChoices(choices []config.ActionArgumentChoice) []*pb.ActionArgumentChoice {
|
|
ret := []*pb.ActionArgumentChoice{}
|
|
|
|
for _, cfgChoice := range choices {
|
|
pbChoice := pb.ActionArgumentChoice{
|
|
Value: cfgChoice.Value,
|
|
Title: cfgChoice.Title,
|
|
}
|
|
|
|
ret = append(ret, &pbChoice)
|
|
}
|
|
|
|
return ret
|
|
}
|