mirror of
https://github.com/bitwarden/server.git
synced 2025-05-23 04:21:05 -05:00
Resolve the revoke for more than one Sponsorship (#5827)
This commit is contained in:
parent
8d2629fe58
commit
b48a09a338
@ -207,7 +207,7 @@ public class OrganizationSponsorshipsController : Controller
|
|||||||
[HttpDelete("{sponsoringOrganizationId}")]
|
[HttpDelete("{sponsoringOrganizationId}")]
|
||||||
[HttpPost("{sponsoringOrganizationId}/delete")]
|
[HttpPost("{sponsoringOrganizationId}/delete")]
|
||||||
[SelfHosted(NotSelfHostedOnly = true)]
|
[SelfHosted(NotSelfHostedOnly = true)]
|
||||||
public async Task RevokeSponsorship(Guid sponsoringOrganizationId, [FromQuery] bool isAdminInitiated = false)
|
public async Task RevokeSponsorship(Guid sponsoringOrganizationId)
|
||||||
{
|
{
|
||||||
|
|
||||||
var orgUser = await _organizationUserRepository.GetByOrganizationAsync(sponsoringOrganizationId, _currentContext.UserId ?? default);
|
var orgUser = await _organizationUserRepository.GetByOrganizationAsync(sponsoringOrganizationId, _currentContext.UserId ?? default);
|
||||||
@ -217,11 +217,25 @@ public class OrganizationSponsorshipsController : Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
var existingOrgSponsorship = await _organizationSponsorshipRepository
|
var existingOrgSponsorship = await _organizationSponsorshipRepository
|
||||||
.GetBySponsoringOrganizationUserIdAsync(orgUser.Id, isAdminInitiated);
|
.GetBySponsoringOrganizationUserIdAsync(orgUser.Id);
|
||||||
|
|
||||||
await _revokeSponsorshipCommand.RevokeSponsorshipAsync(existingOrgSponsorship);
|
await _revokeSponsorshipCommand.RevokeSponsorshipAsync(existingOrgSponsorship);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Authorize("Application")]
|
||||||
|
[HttpDelete("{sponsoringOrgId}/{sponsoredFriendlyName}/revoke")]
|
||||||
|
[SelfHosted(NotSelfHostedOnly = true)]
|
||||||
|
public async Task AdminInitiatedRevokeSponsorshipAsync(Guid sponsoringOrgId, string sponsoredFriendlyName)
|
||||||
|
{
|
||||||
|
var sponsorships = await _organizationSponsorshipRepository.GetManyBySponsoringOrganizationAsync(sponsoringOrgId);
|
||||||
|
var existingOrgSponsorship = sponsorships.FirstOrDefault(s => s.FriendlyName != null && s.FriendlyName.Equals(sponsoredFriendlyName, StringComparison.OrdinalIgnoreCase));
|
||||||
|
if (existingOrgSponsorship == null)
|
||||||
|
{
|
||||||
|
throw new BadRequestException("The specified sponsored organization could not be found under the given sponsoring organization.");
|
||||||
|
}
|
||||||
|
await _revokeSponsorshipCommand.RevokeSponsorshipAsync(existingOrgSponsorship);
|
||||||
|
}
|
||||||
|
|
||||||
[Authorize("Application")]
|
[Authorize("Application")]
|
||||||
[HttpDelete("sponsored/{sponsoredOrgId}")]
|
[HttpDelete("sponsored/{sponsoredOrgId}")]
|
||||||
[HttpPost("sponsored/{sponsoredOrgId}/remove")]
|
[HttpPost("sponsored/{sponsoredOrgId}/remove")]
|
||||||
|
@ -84,4 +84,16 @@ public class SelfHostedOrganizationSponsorshipsController : Controller
|
|||||||
|
|
||||||
await _revokeSponsorshipCommand.RevokeSponsorshipAsync(existingOrgSponsorship);
|
await _revokeSponsorshipCommand.RevokeSponsorshipAsync(existingOrgSponsorship);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpDelete("{sponsoringOrgId}/{sponsoredFriendlyName}/revoke")]
|
||||||
|
public async Task AdminInitiatedRevokeSponsorshipAsync(Guid sponsoringOrgId, string sponsoredFriendlyName)
|
||||||
|
{
|
||||||
|
var sponsorships = await _organizationSponsorshipRepository.GetManyBySponsoringOrganizationAsync(sponsoringOrgId);
|
||||||
|
var existingOrgSponsorship = sponsorships.FirstOrDefault(s => s.FriendlyName != null && s.FriendlyName.Equals(sponsoredFriendlyName, StringComparison.OrdinalIgnoreCase));
|
||||||
|
if (existingOrgSponsorship == null)
|
||||||
|
{
|
||||||
|
throw new BadRequestException("The specified sponsored organization could not be found under the given sponsoring organization.");
|
||||||
|
}
|
||||||
|
await _revokeSponsorshipCommand.RevokeSponsorshipAsync(existingOrgSponsorship);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user