Skip to main content

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

ArgTypeDescription
widgetsArrayWidget 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

  1. Empty input → returns [].
  2. Fast path: if no widget declares visibility, the original array is returned unchanged (no OCS request is made).
  3. Otherwise, fetches the current user's groups via getCurrentUserGroups (cached after the first call) and filters each widget via isWidgetVisible.

Visibility semantics

For each widget:

  • No visibility block → visible to everyone.
  • visibility.users or visibility.groups both 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.