Skip to content

Conversation

@Eric-Wasson
Copy link

SF_agent_overview Agents overview page with sparse fieldsets applied
SF_tasks_overview Tasks overview page with sparse fieldsets applied. A bit more data gets returned than requested. This is because of the aggregatedData function, which doesn't skip the non-included data yet. There was a todo-comment about that already before my commit (now on line 594 in AbstractBaseAPI.class.php). That's something that I'll improve in the future.
SF_Tasks_with_several_SF Task overview page with sparse fieldsets applied for 3 different types of data: task, hashlist and hashType

@Eric-Wasson Eric-Wasson requested a review from jessevz October 27, 2025 13:09
@Eric-Wasson Eric-Wasson added the enhancement Enhancement of existing features / Small addition label Oct 27, 2025
@Eric-Wasson Eric-Wasson changed the title Implemented sparse fieldsets support on the backend Implemented sparse fieldsets support on the backend #1152 Oct 27, 2025
}

// If sparse fieldsets (https://jsonapi.org/format/#fetching-sparse-fieldsets) is used, return only the requested data
if (is_array($sparseFieldsets)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to put the three if statements into a single if statement

if ($keyspaceProgress >= $keyspace && $keyspaceProgress > 0) {
$status = 3;

if(is_array($sparseFieldsets) && array_key_exists('task', $sparseFieldsets) && in_array("searched", $sparseFieldsets['task']) ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the first part of the check: " if(is_array($sparseFieldsets) && array_key_exists('task', $sparseFieldsets)". is now done twice, I would say do that part as on outer if statement, and then afterwards just check individually for "searched" and "status"

elseif (count($activeAgents) > 0) {
$status = 1;

if(is_array($sparseFieldsets) && array_key_exists('task', $sparseFieldsets) && in_array("searched", $sparseFieldsets['task']) ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think "searched" here, should be "status".

@jessevz
Copy link
Contributor

jessevz commented Oct 28, 2025

With this code, will it be possible to simply return the entire object and only specify in the sparse fieldset that you also want some extra agregated data? If not I would suggest to use a different query structure for the aggregated data so that you can add aggregated data with just a few extra additions to your query

@Eric-Wasson
Copy link
Author

Thanks for the feedback! I've fixed the things you mentioned and for the aggregated data it's now possible to query it separately:

Task_overview_with_some_aggregate Task overview without sparse fieldsets but with selected aggregated data.
Both_SF_and_aggregate Task overview with sparse fieldsets and selected aggregated data.
SF_without_aggregate Task overview with sparse fieldsets and without specifying aggregated data fields.

@Eric-Wasson Eric-Wasson marked this pull request as ready for review November 12, 2025 12:09
@jessevz
Copy link
Contributor

jessevz commented Nov 27, 2025

Sorry for the late review, but i see that you use indexes in the examples you provide? like for example fields[agents][0] = agentname. what is the 0 used for? I cant see anything about it in the specs. Also When we want to merge this pull request, we should add a frontend pull request that will query for the aggregations where needed, otherwise some part of the ui will break

@Eric-Wasson
Copy link
Author

Eric-Wasson commented Nov 28, 2025

i see that you use indexes in the examples you provide

Since I used the Firefox devtools I made a slightly wrong implementation of the sparse fieldsets arrays. It's now fixed and can get used properly like this:

curl --compressed --header "Authorization: Bearer $TOKEN" -g 'http://localhost:8080/api/v2/ui/taskwrappers?page[size]=25&include=accessGroup,tasks,hashlist,hashType&filter[isArchived__eq]=false&fields[task]=attackCmd,isSmall&aggregate[task]=dispatched,status'

otherwise some part of the ui will break

What part do you mean would break? As far as I see everything works normally if you don't include the sparse fieldsets and aggregate fieldsets (the default there is to also return everything) in the query (which the frontend currently doesn't do). If you add the sparse fieldsets or aggregate fieldsets in the request then the response will change too.

@jessevz
Copy link
Contributor

jessevz commented Dec 2, 2025

Ah I see I thought that the aggregation would only happen if it is defined. That would be my preferred solution. But then I think its fine for now to merge it and later make a pull request to make it so that aggregations only happen when its queried for, and then also do a pull request in the frontend where these queries are altered. Can you fix the open merge conflicts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Enhancement of existing features / Small addition

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants