Skip to main content

Overview

The CollectionService manages collections within organizations. Collections are organization-level groupings of vault items that allow teams to share and organize ciphers. Unlike folders (which are personal), collections are shared across organization members with specific access permissions. Source: libs/admin-console/src/common/collections/services/default-collection.service.ts

Key Features

  • Manage organization collections
  • Encrypt and decrypt collection data
  • Handle collection permissions (read, edit, manage)
  • Transform collections into nested tree structures
  • Group collections by organization
  • Observable-based reactive state management

Observables

encryptedCollections$

Observable that emits encrypted collections for a user.
Parameters:
  • userId: UserId - The user ID to get collections for
Returns: Observable of encrypted collection objects, or null if not loaded

decryptedCollections$

Observable that emits decrypted collection views for a user.
Parameters:
  • userId: UserId - The user ID to get collection views for
Returns: Observable of decrypted collection views sorted by name Example:

defaultUserCollection$

Observable for the default collection of a user in an organization.
Parameters:
  • userId: UserId - The user ID
  • orgId: OrganizationId - The organization ID
Returns: Observable that emits the default collection or undefined Example:

Core Methods

encrypt

Encrypts a collection view for storage.
Parameters:
  • model: CollectionView - The collection view to encrypt
  • userId: UserId - The user ID (used to get organization key)
Returns: Promise resolving to encrypted collection Example:

decryptMany$

Decrypts multiple collections using organization keys.
Parameters:
  • collections: Collection[] - Array of encrypted collections
  • orgKeys: Record<OrganizationId, OrgKey> - Map of organization IDs to org keys
Returns: Observable of decrypted collection views sorted by name
This method will soon be made private. Use decryptedCollections$ observable instead.

CRUD Operations

upsert

Inserts or updates a collection in storage.
Parameters:
  • collection: CollectionData - The collection data to upsert
  • userId: UserId - The user ID
Behavior:
  • Updates both encrypted and decrypted state
  • Automatically decrypts the collection using organization key
  • Merges with existing collections
Example:

replace

Replaces all collections for a user.
Parameters:
  • collections: { [id: string]: CollectionData } - Object mapping collection IDs to collection data
  • userId: UserId - The user ID
Note: This is typically used during sync operations. It clears decrypted state, forcing re-decryption on next access.

delete

Deletes one or more collections.
Parameters:
  • ids: CollectionId[] - Array of collection IDs to delete
  • userId: UserId - The user ID
Behavior:
  • Removes from both encrypted and decrypted state
  • Does not affect ciphers (they may become unassigned)
Example:

Tree Structure Methods

getAllNested

Transforms collections into a nested tree structure.
Parameters:
  • collections: CollectionView[] - Flat array of collections
Returns: Array of tree nodes with nested structure based on collection names Nesting Behavior:
  • Collections are nested based on / delimiter in names
  • Example: "Team/Engineering/Backend" creates a 3-level tree
  • Collections are grouped by organization first
Example:

getNested

Retrieves a specific collection as a tree node with its hierarchy.
Parameters:
  • collections: CollectionView[] - Flat array of collections
  • id: string - The collection ID to find
Returns: Tree node containing the collection and its position in the hierarchy
Deprecated as of August 30, 2022. Moved to Vault Filter Service. Will be removed when Desktop and Browser are updated.

groupByOrganization

Groups collections by their organization ID.
Parameters:
  • collections: CollectionView[] - Array of collections to group
Returns: Map with organization IDs as keys and arrays of collections as values Example:

Collection Types

CollectionView

Decrypted collection view with permissions.
Properties:
  • id: CollectionId - Unique collection identifier
  • organizationId: OrganizationId - Parent organization ID
  • name: string - Collection name (supports / for nesting)
  • readOnly: boolean - If true, items cannot be edited
  • hidePasswords: boolean - If true, passwords are hidden from view
  • manage: boolean - If true, user can manage the collection
  • assigned: boolean - If true, user is directly assigned to collection
  • type: CollectionType - Collection type (SharedCollection, DefaultUserCollection, etc.)
Permission Methods:

canEditItems

Checks if user can edit items within the collection.
Returns: true if user can edit items based on:
  • Organization canEditAllCiphers permission
  • Collection manage permission
  • Collection assigned and not readOnly

canEdit

Checks if user can edit the collection itself (permissions, name, etc.).
Returns: true if user has manage permission and it’s not a default collection

canDelete

Checks if user can delete the collection from individual vault.
Note: Does not include admin permissions. See CollectionAdminView.canDelete for admin access.

Collection

Encrypted collection domain object.

CollectionData

Raw collection data for storage.

Collection Types Enum

SharedCollection: Standard organization collection shared among members DefaultUserCollection: Special collection automatically created for new organization members

Usage Examples

Listing User Collections

Creating Nested Collection Structure

Checking Collection Permissions

Filtering Collections by Organization

Assigning Cipher to Collections

Implementation Notes

Nesting Delimiter

The service uses / as the nesting delimiter:
Collection names like "Parent/Child/Grandchild" create a 3-level hierarchy.

Observable Caching

The service caches decrypted collection observables per user:
This prevents redundant decryption operations.

Automatic Decryption

When accessing decryptedCollections$, the service:
  1. Checks if decrypted state exists
  2. If not, fetches encrypted collections and org keys
  3. Decrypts all collections with appropriate org keys
  4. Caches the result
  5. Emits sorted collection views
  • Cipher Service - Manages items that can be assigned to collections
  • Folder Service - Personal organization (vs. org collections)
  • Organization Service - Manages organization data and permissions

See Also

  • Collection Admin Service - Extended permissions for organization admins
  • Vault Filter Service - Filtering and searching across collections