feat: Entities in icon field, and other cleanup stuff (#619)
This commit is contained in:
parent
a8ac719af7
commit
fcd1879d09
|
|
@ -108,22 +108,24 @@ func logAclNoneMatched(cfg *config.Config, aclFunction string, user *Authenticat
|
||||||
}
|
}
|
||||||
|
|
||||||
func permissionsConfigToBits(permissions config.PermissionsList) PermissionBits {
|
func permissionsConfigToBits(permissions config.PermissionsList) PermissionBits {
|
||||||
|
type permPair struct {
|
||||||
|
enabled bool
|
||||||
|
bit PermissionBits
|
||||||
|
}
|
||||||
|
|
||||||
|
permMap := []permPair{
|
||||||
|
{permissions.View, View},
|
||||||
|
{permissions.Exec, Exec},
|
||||||
|
{permissions.Logs, Logs},
|
||||||
|
{permissions.Kill, Kill},
|
||||||
|
}
|
||||||
|
|
||||||
var ret PermissionBits
|
var ret PermissionBits
|
||||||
|
|
||||||
if permissions.View {
|
for _, perm := range permMap {
|
||||||
ret |= View
|
if perm.enabled {
|
||||||
|
ret |= perm.bit
|
||||||
}
|
}
|
||||||
|
|
||||||
if permissions.Exec {
|
|
||||||
ret |= Exec
|
|
||||||
}
|
|
||||||
|
|
||||||
if permissions.Logs {
|
|
||||||
ret |= Logs
|
|
||||||
}
|
|
||||||
|
|
||||||
if permissions.Kill {
|
|
||||||
ret |= Kill
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,10 @@ import (
|
||||||
sv "github.com/OliveTin/OliveTin/internal/stringvariables"
|
sv "github.com/OliveTin/OliveTin/internal/stringvariables"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
|
"math"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"math"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
package entityfiles
|
package entityfiles
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
sv "github.com/OliveTin/OliveTin/internal/stringvariables"
|
sv "github.com/OliveTin/OliveTin/internal/stringvariables"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLoadObjectPerLineJsonFile(t *testing.T) {
|
func TestLoadObjectPerLineJsonFile(t *testing.T) {
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,6 @@ func (api *oliveTinAPI) KillAction(ctx ctx.Context, req *apiv1.KillActionRequest
|
||||||
|
|
||||||
log.Warnf("Killing execution request by tracking ID: %v", req.ExecutionTrackingId)
|
log.Warnf("Killing execution request by tracking ID: %v", req.ExecutionTrackingId)
|
||||||
|
|
||||||
user := acl.UserFromContext(ctx, cfg)
|
|
||||||
action := cfg.FindAction(execReqLogEntry.ActionTitle)
|
action := cfg.FindAction(execReqLogEntry.ActionTitle)
|
||||||
|
|
||||||
if action == nil {
|
if action == nil {
|
||||||
|
|
@ -58,10 +57,17 @@ func (api *oliveTinAPI) KillAction(ctx ctx.Context, req *apiv1.KillActionRequest
|
||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if !acl.IsAllowedKill(cfg, user, action) {
|
user := acl.UserFromContext(ctx, cfg)
|
||||||
log.Warnf("Killing execution request not possible - user not allowed to kill this action: %v", req.ExecutionTrackingId)
|
|
||||||
ret.Killed = false
|
api.killActionByTrackingId(user, action, execReqLogEntry, ret)
|
||||||
|
|
||||||
return ret, nil
|
return ret, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (api *oliveTinAPI) killActionByTrackingId(user *acl.AuthenticatedUser, action *config.Action, execReqLogEntry *executor.InternalLogEntry, ret *apiv1.KillActionResponse) {
|
||||||
|
if !acl.IsAllowedKill(cfg, user, action) {
|
||||||
|
log.Warnf("Killing execution request not possible - user not allowed to kill this action: %v", execReqLogEntry.ExecutionTrackingID)
|
||||||
|
ret.Killed = false
|
||||||
}
|
}
|
||||||
|
|
||||||
err := api.executor.Kill(execReqLogEntry)
|
err := api.executor.Kill(execReqLogEntry)
|
||||||
|
|
@ -73,8 +79,6 @@ func (api *oliveTinAPI) KillAction(ctx ctx.Context, req *apiv1.KillActionRequest
|
||||||
} else {
|
} else {
|
||||||
ret.Killed = true
|
ret.Killed = true
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *oliveTinAPI) StartAction(ctx ctx.Context, req *apiv1.StartActionRequest) (*apiv1.StartActionResponse, error) {
|
func (api *oliveTinAPI) StartAction(ctx ctx.Context, req *apiv1.StartActionRequest) (*apiv1.StartActionResponse, error) {
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ func buildAction(actionId string, actionBinding *executor.ActionBinding, user *a
|
||||||
btn := apiv1.Action{
|
btn := apiv1.Action{
|
||||||
Id: actionId,
|
Id: actionId,
|
||||||
Title: sv.ReplaceEntityVars(actionBinding.EntityPrefix, action.Title),
|
Title: sv.ReplaceEntityVars(actionBinding.EntityPrefix, action.Title),
|
||||||
Icon: action.Icon,
|
Icon: sv.ReplaceEntityVars(actionBinding.EntityPrefix, action.Icon),
|
||||||
CanExec: acl.IsAllowedExec(cfg, user, action),
|
CanExec: acl.IsAllowedExec(cfg, user, action),
|
||||||
PopupOnStart: action.PopupOnStart,
|
PopupOnStart: action.PopupOnStart,
|
||||||
Order: int32(actionBinding.ConfigOrder),
|
Order: int32(actionBinding.ConfigOrder),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue