Skip to content

Commit 71f2cfc

Browse files
eliykatHinton
authored andcommitted
[EC-160] Give Provider Users access to all org ciphers and collections (#1959)
(cherry picked from commit ec9dd8e)
1 parent 32de198 commit 71f2cfc

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

src/Api/Controllers/CiphersController.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,19 @@ public async Task<ListResponseModel<CipherMiniDetailsResponseModel>> GetOrganiza
224224
throw new NotFoundException();
225225
}
226226

227-
var ciphers = await _cipherRepository.GetManyByUserIdAsync(userId, true);
228-
var orgCiphers = ciphers.Where(c => c.OrganizationId == orgIdGuid);
227+
IEnumerable<Cipher> orgCiphers;
228+
if (await _currentContext.OrganizationOwner(orgIdGuid))
229+
{
230+
// User may be a Provider for the organization, in which case GetManyByUserIdAsync won't return any results
231+
// But they have access to all organization ciphers, so we can safely get by orgId instead
232+
orgCiphers = await _cipherRepository.GetManyByOrganizationIdAsync(orgIdGuid);
233+
}
234+
else
235+
{
236+
var ciphers = await _cipherRepository.GetManyByUserIdAsync(userId, true);
237+
orgCiphers = ciphers.Where(c => c.OrganizationId == orgIdGuid);
238+
}
239+
229240
var orgCipherIds = orgCiphers.Select(c => c.Id);
230241

231242
var collectionCiphers = await _collectionCipherRepository.GetManyByOrganizationIdAsync(orgIdGuid);

src/Api/Controllers/CollectionsController.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,19 @@ public async Task<ListResponseModel<CollectionResponseModel>> Get(string orgId)
8787
throw new NotFoundException();
8888
}
8989

90-
var collections = await _collectionRepository.GetManyByUserIdAsync(_currentContext.UserId.Value);
91-
var orgCollections = collections.Where(c => c.OrganizationId == orgIdGuid);
90+
IEnumerable<Collection> orgCollections;
91+
if (await _currentContext.OrganizationOwner(orgIdGuid))
92+
{
93+
// User may be a Provider for the organization, in which case GetManyByUserIdAsync won't return any results
94+
// But they have access to all organization collections, so we can safely get by orgId instead
95+
orgCollections = await _collectionRepository.GetManyByOrganizationIdAsync(orgIdGuid);
96+
}
97+
else
98+
{
99+
var collections = await _collectionRepository.GetManyByUserIdAsync(_currentContext.UserId.Value);
100+
orgCollections = collections.Where(c => c.OrganizationId == orgIdGuid);
101+
}
102+
92103
var responses = orgCollections.Select(c => new CollectionResponseModel(c));
93104
return new ListResponseModel<CollectionResponseModel>(responses);
94105
}

0 commit comments

Comments
 (0)