filterWidgetsByVisibility
Filters an array of dashboard widget definitions down to those visible to the current Nextcloud user. Drives the visibility logic inside useDashboardView but can also be called directly from any custom widget loader.
Signature
import { filterWidgetsByVisibility } from '@conduction/nextcloud-vue'
const visible = await filterWidgetsByVisibility(allWidgets)
Parameters
| Arg | Type | Description |
|---|---|---|
widgets | Array | Widget definitions. Each may have a visibility: { users, groups } block. |
Returns
Promise<Array> — a new array containing only widgets the current user is allowed to see.
Behaviour
- Empty input → returns
[]. - Fast path: if no widget declares
visibility, the original array is returned unchanged (no OCS request is made). - Otherwise, fetches the current user's groups via
getCurrentUserGroups(cached after the first call) and filters each widget viaisWidgetVisible.
Visibility semantics
For each widget:
- No
visibilityblock → visible to everyone. visibility.usersorvisibility.groupsboth empty → visible to everyone.- User ID in
visibility.users→ visible. - User's groups overlap with
visibility.groups→ visible. - Otherwise → hidden.
User and group lists combine with OR logic — either a user-ID match or a group match grants access.
Related
- useDashboardView — Primary consumer; re-runs this on mount and whenever widget definitions change.
- isWidgetVisible — Synchronous per-widget predicate.
- resetVisibilityCache — Clears the cached groups (tests, user switch).