Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions firewalldb/actions_kvdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,13 @@ func (db *BoltDB) ListActions(ctx context.Context, query *ListActionsQuery,
)
}
if opts.groupID != session.EmptyID {
actions, err := db.listGroupActions(ctx, opts.groupID, filterFn)
var reversed bool
if query != nil {
reversed = query.Reversed
}
actions, err := db.listGroupActions(
ctx, opts.groupID, filterFn, reversed,
)
if err != nil {
return nil, 0, 0, err
}
Expand Down Expand Up @@ -439,11 +445,11 @@ func (db *BoltDB) listSessionActions(sessionID session.ID,
//
// TODO: update to allow for pagination.
func (db *BoltDB) listGroupActions(ctx context.Context, groupID session.ID,
filterFn listActionsFilterFn) ([]*Action, error) {
filterFn listActionsFilterFn, reversed bool) ([]*Action, error) {

if filterFn == nil {
filterFn = func(a *Action, reversed bool) (bool, bool) {
return true, true
return true, reversed
}
}

Expand Down Expand Up @@ -482,9 +488,18 @@ func (db *BoltDB) listGroupActions(ctx context.Context, groupID session.ID,
return err
}

include, cont := filterFn(action, false)
include, cont := filterFn(action, reversed)
if include {
actions = append(actions, action)
if !reversed {
actions = append(
actions, action,
)
} else {
actions = append(
[]*Action{action},
actions...,
)
}
}

if !cont {
Expand Down
12 changes: 11 additions & 1 deletion firewalldb/actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,12 +497,22 @@ func TestListGroupActions(t *testing.T) {
_, err = db.AddAction(ctx, action2Req)
require.NoError(t, err)

// There should now be actions in the group.
// There should now be two actions in the group.
al, _, _, err = db.ListActions(ctx, nil, WithActionGroupID(group1))
require.NoError(t, err)
require.Len(t, al, 2)
assertEqualActions(t, action1, al[0])
assertEqualActions(t, action2, al[1])

// Try the reversed query too.
al, _, _, err = db.ListActions(
ctx, &ListActionsQuery{Reversed: true},
WithActionGroupID(group1),
)
require.NoError(t, err)
require.Len(t, al, 2)
assertEqualActions(t, action2, al[0])
assertEqualActions(t, action1, al[1])
}

func assertEqualActions(t *testing.T, expected, got *Action) {
Expand Down
Loading