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-18564] Added policy validation before creating or sending org sponsorship invite #5459

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@
public async Task CreateSponsorship(Guid sponsoringOrgId, [FromBody] OrganizationSponsorshipCreateRequestModel model)
{
var sponsoringOrg = await _organizationRepository.GetByIdAsync(sponsoringOrgId);
var freeFamiliesSponsorshipPolicy = await _policyRepository.GetByOrganizationIdTypeAsync(sponsoringOrgId,
PolicyType.FreeFamiliesSponsorshipPolicy);

Check warning on line 80 in src/Api/Billing/Controllers/OrganizationSponsorshipsController.cs

View check run for this annotation

Codecov / codecov/patch

src/Api/Billing/Controllers/OrganizationSponsorshipsController.cs#L79-L80

Added lines #L79 - L80 were not covered by tests

if (freeFamiliesSponsorshipPolicy?.Enabled == true)
{
throw new BadRequestException("Free Bitwarden Families sponsorship has been disabled by your organization administrator.");

Check warning on line 84 in src/Api/Billing/Controllers/OrganizationSponsorshipsController.cs

View check run for this annotation

Codecov / codecov/patch

src/Api/Billing/Controllers/OrganizationSponsorshipsController.cs#L83-L84

Added lines #L83 - L84 were not covered by tests
}

var sponsorship = await _createSponsorshipCommand.CreateSponsorshipAsync(
sponsoringOrg,
Expand All @@ -89,6 +96,14 @@
[SelfHosted(NotSelfHostedOnly = true)]
public async Task ResendSponsorshipOffer(Guid sponsoringOrgId)
{
var freeFamiliesSponsorshipPolicy = await _policyRepository.GetByOrganizationIdTypeAsync(sponsoringOrgId,
PolicyType.FreeFamiliesSponsorshipPolicy);

Check warning on line 100 in src/Api/Billing/Controllers/OrganizationSponsorshipsController.cs

View check run for this annotation

Codecov / codecov/patch

src/Api/Billing/Controllers/OrganizationSponsorshipsController.cs#L99-L100

Added lines #L99 - L100 were not covered by tests

if (freeFamiliesSponsorshipPolicy?.Enabled == true)
{
throw new BadRequestException("Free Bitwarden Families sponsorship has been disabled by your organization administrator.");

Check warning on line 104 in src/Api/Billing/Controllers/OrganizationSponsorshipsController.cs

View check run for this annotation

Codecov / codecov/patch

src/Api/Billing/Controllers/OrganizationSponsorshipsController.cs#L103-L104

Added lines #L103 - L104 were not covered by tests
}

var sponsoringOrgUser = await _organizationUserRepository
.GetByOrganizationAsync(sponsoringOrgId, _currentContext.UserId ?? default);

Expand Down Expand Up @@ -135,6 +150,14 @@
throw new BadRequestException("Can only redeem sponsorship for an organization you own.");
}

var freeFamiliesSponsorshipPolicy = await _policyRepository.GetByOrganizationIdTypeAsync(
model.SponsoredOrganizationId, PolicyType.FreeFamiliesSponsorshipPolicy);

if (freeFamiliesSponsorshipPolicy?.Enabled == true)
{
throw new BadRequestException("Free Bitwarden Families sponsorship has been disabled by your organization administrator.");

Check warning on line 158 in src/Api/Billing/Controllers/OrganizationSponsorshipsController.cs

View check run for this annotation

Codecov / codecov/patch

src/Api/Billing/Controllers/OrganizationSponsorshipsController.cs#L157-L158

Added lines #L157 - L158 were not covered by tests
}

await _setUpSponsorshipCommand.SetUpSponsorshipAsync(
sponsorship,
await _organizationRepository.GetByIdAsync(model.SponsoredOrganizationId));
Expand Down
Loading