| 151 | } |
| 152 | |
| 153 | pub fn list( |
| 154 | &self, |
| 155 | input: ListAssetsInput, |
| 156 | ctx: Option<&CallContext>, |
| 157 | ) -> ServiceResult<PaginatedData<Asset>> { |
| 158 | let mut assets = self.asset_repository.list(); |
| 159 | |
| 160 | if let Some(ctx) = ctx { |
| 161 | // filter out assets that the caller does not have access to read |
| 162 | retain_accessible_resources(ctx, &mut assets, |asset| { |
| 163 | Resource::Asset(crate::models::resource::ResourceAction::Read( |
| 164 | crate::models::resource::ResourceId::Id(asset.id), |
| 165 | )) |
| 166 | }); |
| 167 | } |
| 168 | |
| 169 | let result = paginated_items(PaginatedItemsArgs { |
| 170 | offset: input.paginate.to_owned().and_then(|p| p.offset), |
| 171 | limit: input.paginate.and_then(|p| p.limit), |
| 172 | default_limit: Some(Self::DEFAULT_LIST_ASSETS_LIMIT), |
| 173 | max_limit: Some(Self::MAX_LIST_ASSETS_LIMIT), |
| 174 | items: &assets, |
| 175 | })?; |
| 176 | |
| 177 | Ok(result) |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | #[cfg(test)] |