// 2. Check if user has permission to view the collection
let user_role = check_access(
*collection_id,
AssetType::Collection,
*user_id,
IdentityType::User,
).await?;
if user_role.is_none() {
return Err(anyhow!("User does not have permission to view this collection"));
}
// 3. Get all permissions for the collection
let permissions = list_shares(
*collection_id,
AssetType::Collection,
).await?;
Ok(permissions)
}
```
### Sharing Library Integration
This endpoint leverages the following functions from the sharing library:
1.`check_access` from `@[api/libs/sharing/src]/check_asset_permission.rs`:
```rust
pub async fn check_access(
asset_id: Uuid,
asset_type: AssetType,
identity_id: Uuid,
identity_type: IdentityType,
) -> Result<Option<AssetPermissionRole>>
```
This function is used to verify that the user has permission to view the collection. It returns the user's role for the asset, or None if they don't have access.
2.`list_shares` from `@[api/libs/sharing/src]/list_asset_permissions.rs`:
```rust
pub async fn list_shares(
asset_id: Uuid,
asset_type: AssetType,
) -> Result<Vec<AssetPermissionWithUser>>
```
This function retrieves all permissions for a specified asset, including user information. It filters out soft-deleted permissions and returns a structured response.
3. The `AssetPermissionWithUser` type from `@[api/libs/sharing/src]/types.rs`:
```rust
pub struct AssetPermissionWithUser {
pub permission: SerializableAssetPermission,
pub user: Option<UserInfo>,
}
```
This type combines permission data with user information for a comprehensive response.
### Error Handling
The handler will return appropriate error responses:
- 404 Not Found - If the collection doesn't exist
- 403 Forbidden - If the user doesn't have permission to view the collection
- 500 Internal Server Error - For database errors or other unexpected issues