From 42b1c94719a63902951ea0b6bd420eba2edbb70f Mon Sep 17 00:00:00 2001 From: Lennart Fleischmann Date: Thu, 17 Oct 2024 14:03:07 +0200 Subject: [PATCH] fix: session delete action Suspends the action if there is only one session and it is the same as the current. Also now validates the allowed input values during execution. --- .../flow/profile/action_session_delete.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/backend/flow_api/flow/profile/action_session_delete.go b/backend/flow_api/flow/profile/action_session_delete.go index c41f88401..8f733f137 100644 --- a/backend/flow_api/flow/profile/action_session_delete.go +++ b/backend/flow_api/flow/profile/action_session_delete.go @@ -40,18 +40,32 @@ func (a SessionDelete) Initialize(c flowpilot.InitializationContext) { return } + var deletableSessions []string for _, session := range sessions { if session.ID != currentSessionID { - input.AllowedValue(session.ID.String(), session.ID.String()) + deletableSessions = append(deletableSessions, session.ID.String()) } } + if len(deletableSessions) < 1 { + c.SuspendAction() + return + } + + for _, deletableSession := range deletableSessions { + input.AllowedValue(deletableSession, deletableSession) + } + c.AddInputs(input) } func (a SessionDelete) Execute(c flowpilot.ExecutionContext) error { deps := a.GetDeps(c) + if valid := c.ValidateInputData(); !valid { + return c.Error(flowpilot.ErrorFormDataInvalid) + } + sessionToBeDeleted := uuid.FromStringOrNil(c.Input().Get("session_id").String()) session, err := deps.Persister.GetSessionPersisterWithConnection(deps.Tx).Get(sessionToBeDeleted)