Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PM-5450] Add check for admin/org access for events #4705

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
21 changes: 19 additions & 2 deletions src/Events/Controllers/CollectController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,22 @@
private readonly ICipherRepository _cipherRepository;
private readonly IOrganizationRepository _organizationRepository;
private readonly IFeatureService _featureService;
private readonly IApplicationCacheService _applicationCacheService;

public CollectController(
ICurrentContext currentContext,
IEventService eventService,
ICipherRepository cipherRepository,
IOrganizationRepository organizationRepository,
IFeatureService featureService)
IFeatureService featureService,
IApplicationCacheService applicationCacheService)

Check warning on line 30 in src/Events/Controllers/CollectController.cs

View check run for this annotation

Codecov / codecov/patch

src/Events/Controllers/CollectController.cs#L29-L30

Added lines #L29 - L30 were not covered by tests
{
_currentContext = currentContext;
_eventService = eventService;
_cipherRepository = cipherRepository;
_organizationRepository = organizationRepository;
_featureService = featureService;
_applicationCacheService = applicationCacheService;

Check warning on line 37 in src/Events/Controllers/CollectController.cs

View check run for this annotation

Codecov / codecov/patch

src/Events/Controllers/CollectController.cs#L37

Added line #L37 was not covered by tests
}

[HttpPost]
Expand Down Expand Up @@ -77,7 +80,21 @@
}
if (cipher == null)
{
continue;
// When the user cannot access the cipher directly, check if the organization allows for
// admin/owners access to all collections and the user can access the cipher from that perspective.
if (!eventModel.OrganizationId.HasValue)
{
continue;

Check warning on line 87 in src/Events/Controllers/CollectController.cs

View check run for this annotation

Codecov / codecov/patch

src/Events/Controllers/CollectController.cs#L86-L87

Added lines #L86 - L87 were not covered by tests
}

cipher = await _cipherRepository.GetByIdAsync(eventModel.CipherId.Value);

Check warning on line 90 in src/Events/Controllers/CollectController.cs

View check run for this annotation

Codecov / codecov/patch

src/Events/Controllers/CollectController.cs#L90

Added line #L90 was not covered by tests
var cipherBelongsToOrg = cipher.OrganizationId == eventModel.OrganizationId;
var org = _currentContext.GetOrganization(eventModel.OrganizationId.Value);

Check warning on line 92 in src/Events/Controllers/CollectController.cs

View check run for this annotation

Codecov / codecov/patch

src/Events/Controllers/CollectController.cs#L92

Added line #L92 was not covered by tests

if (!cipherBelongsToOrg || org == null || cipher == null)
{
continue;

Check warning on line 96 in src/Events/Controllers/CollectController.cs

View check run for this annotation

Codecov / codecov/patch

src/Events/Controllers/CollectController.cs#L95-L96

Added lines #L95 - L96 were not covered by tests
}
}
if (!ciphersCache.ContainsKey(eventModel.CipherId.Value))
{
Expand Down
Loading