mirror of
https://github.com/bitwarden/server.git
synced 2025-07-01 16:12:49 -05:00
Use organization and auth to find organization sponsorship
This commit is contained in:
@ -116,21 +116,21 @@ namespace Bit.Api.Controllers
|
|||||||
await _organizationsSponsorshipService.SetUpSponsorshipAsync(existingSponsorshipOffer, organizationToSponsor);
|
await _organizationsSponsorshipService.SetUpSponsorshipAsync(existingSponsorshipOffer, organizationToSponsor);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpDelete("{sponsoringOrgUserId}")]
|
[HttpDelete("{sponsoringOrganizationId}")]
|
||||||
[HttpPost("{sponsoringOrgUserId}/delete")]
|
[HttpPost("{sponsoringOrganizationId}/delete")]
|
||||||
[SelfHosted(NotSelfHostedOnly = true)]
|
[SelfHosted(NotSelfHostedOnly = true)]
|
||||||
public async Task RevokeSponsorship(string sponsoringOrgUserId)
|
public async Task RevokeSponsorship(string sponsoringOrganizationId)
|
||||||
{
|
{
|
||||||
var sponsoringOrgUserIdGuid = new Guid(sponsoringOrgUserId);
|
var sponsoringOrganizationIdGuid = new Guid(sponsoringOrganizationId);
|
||||||
|
|
||||||
var orgUser = await _organizationUserRepository.GetByIdAsync(sponsoringOrgUserIdGuid);
|
var orgUser = await _organizationUserRepository.GetByOrganizationAsync(sponsoringOrganizationIdGuid, _currentContext.UserId ?? default);
|
||||||
if (_currentContext.UserId != orgUser?.UserId)
|
if (_currentContext.UserId != orgUser?.UserId)
|
||||||
{
|
{
|
||||||
throw new BadRequestException("Can only revoke a sponsorship you granted.");
|
throw new BadRequestException("Can only revoke a sponsorship you granted.");
|
||||||
}
|
}
|
||||||
|
|
||||||
var existingOrgSponsorship = await _organizationSponsorshipRepository
|
var existingOrgSponsorship = await _organizationSponsorshipRepository
|
||||||
.GetBySponsoringOrganizationUserIdAsync(sponsoringOrgUserIdGuid);
|
.GetBySponsoringOrganizationUserIdAsync(orgUser.Id);
|
||||||
if (existingOrgSponsorship == null || existingOrgSponsorship.SponsoredOrganizationId == null)
|
if (existingOrgSponsorship == null || existingOrgSponsorship.SponsoredOrganizationId == null)
|
||||||
{
|
{
|
||||||
throw new BadRequestException("You are not currently sponsoring an organization.");
|
throw new BadRequestException("You are not currently sponsoring an organization.");
|
||||||
|
Reference in New Issue
Block a user