Skip to content

Commit

Permalink
fix: session delete action
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lfleischmann committed Oct 17, 2024
1 parent d0bc388 commit 42b1c94
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion backend/flow_api/flow/profile/action_session_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 42b1c94

Please sign in to comment.