(id: string, filter?: (c: CipherView) => boolean)
| 142 | } |
| 143 | |
| 144 | private async getCipher(id: string, filter?: (c: CipherView) => boolean) { |
| 145 | const activeUserId = await firstValueFrom(this.accountService.activeAccount$.pipe(getUserId)); |
| 146 | |
| 147 | let decCipher = await this.getCipherView(id, activeUserId); |
| 148 | if (decCipher == null) { |
| 149 | return Response.notFound(); |
| 150 | } |
| 151 | |
| 152 | if (Array.isArray(decCipher)) { |
| 153 | // Apply restricted ciphers filter |
| 154 | decCipher = await this.cliRestrictedItemTypesService.filterRestrictedCiphers(decCipher); |
| 155 | |
| 156 | if (decCipher.length === 0) { |
| 157 | return Response.error("Access to this item type is restricted by organizational policy."); |
| 158 | } |
| 159 | |
| 160 | if (filter != null) { |
| 161 | decCipher = decCipher.filter(filter); |
| 162 | } |
| 163 | |
| 164 | if (decCipher.length === 0) { |
| 165 | return Response.notFound(); |
| 166 | } |
| 167 | |
| 168 | if (decCipher.length === 1) { |
| 169 | decCipher = decCipher[0]; |
| 170 | } else { |
| 171 | return Response.multipleResults(decCipher.map((c) => c.id)); |
| 172 | } |
| 173 | } else { |
| 174 | const isCipherRestricted = |
| 175 | await this.cliRestrictedItemTypesService.isCipherRestricted(decCipher); |
| 176 | if (isCipherRestricted) { |
| 177 | return Response.error("Access to this item type is restricted by organizational policy."); |
| 178 | } |
| 179 | |
| 180 | // Apply filter if provided to single cipher |
| 181 | if (filter != null && !filter(decCipher)) { |
| 182 | return Response.notFound(); |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | await this.eventCollectionService.collect( |
| 187 | EventType.Cipher_ClientViewed, |
| 188 | decCipher.id, |
| 189 | true, |
| 190 | decCipher.organizationId, |
| 191 | ); |
| 192 | |
| 193 | const res = new CipherResponse(decCipher); |
| 194 | return Response.success(res); |
| 195 | } |
| 196 | |
| 197 | private async getUsername(id: string) { |
| 198 | const cipherResponse = await this.getCipher( |
no test coverage detected