Skip to content

Add hasChildren field to folder search API to support accurate UI tree rendering #36459

Description

@freddyDOTCMS

Description

The GET /api/v1/folder/search endpoint returns folder data but does not indicate whether a folder has sub-folders visible to the current user. UI tree components rely on this signal to decide whether to render an expand arrow — without it, they either make a second request per folder (N+1 problem) or render expand arrows on all folders, including leaf folders. When a user clicks to expand a leaf folder, nothing loads, which is a confusing and broken experience.

The fix is to add a hasChildren boolean field to the response, computed per-page in a single batch query and filtered by the current user's permissions. No schema migration is required.

Changes required

Each folder entry in the GET /api/v1/folder/search response will include a new hasChildren boolean field:

{
  "id": "...",
  "name": "blog",
  "path": "/content/blog/",
  "addChildrenAllowed": true,
  "hasChildren": true
}

No other fields are removed or modified. The endpoint contract is fully backwards-compatible — consumers that do not use hasChildren are unaffected.

Acceptance Criteria

  • GET /api/v1/folder/search response includes a hasChildren boolean on each folder entry
  • hasChildren is true only if at least one child folder exists and is visible to the current user based on their permissions
  • hasChildren is false for leaf folders or folders where all children are hidden from the current user by permissions
  • The children check is performed in batch — a single query per page, not one per folder
  • Existing folder search behavior, pagination, and filtering are unaffected

Additional Context

  • No database schema changes required
  • Permission filtering should use permissionAPI.filterCollection (batch) rather than per-item doesUserHavePermission calls

Metadata

Metadata

Assignees

Type

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions