mirror of
https://github.com/bitwarden/server.git
synced 2025-07-02 00:22:50 -05:00
Switch to using Guid in the method
This commit is contained in:
@ -43,12 +43,10 @@ namespace Bit.Api.Controllers
|
|||||||
|
|
||||||
[HttpPost("{sponsoringOrgId}/families-for-enterprise")]
|
[HttpPost("{sponsoringOrgId}/families-for-enterprise")]
|
||||||
[SelfHosted(NotSelfHostedOnly = true)]
|
[SelfHosted(NotSelfHostedOnly = true)]
|
||||||
public async Task CreateSponsorship(string sponsoringOrgId, [FromBody] OrganizationSponsorshipRequestModel model)
|
public async Task CreateSponsorship(Guid sponsoringOrgId, [FromBody] OrganizationSponsorshipRequestModel model)
|
||||||
{
|
{
|
||||||
// TODO: validate has right to sponsor, send sponsorship email
|
|
||||||
var sponsoringOrgIdGuid = new Guid(sponsoringOrgId);
|
|
||||||
var requiredSponsoringProductType = StaticStore.GetSponsoredPlan(model.PlanSponsorshipType)?.SponsoringProductType;
|
var requiredSponsoringProductType = StaticStore.GetSponsoredPlan(model.PlanSponsorshipType)?.SponsoringProductType;
|
||||||
var sponsoringOrg = await _organizationRepository.GetByIdAsync(sponsoringOrgIdGuid);
|
var sponsoringOrg = await _organizationRepository.GetByIdAsync(sponsoringOrgId);
|
||||||
if (requiredSponsoringProductType == null ||
|
if (requiredSponsoringProductType == null ||
|
||||||
sponsoringOrg == null ||
|
sponsoringOrg == null ||
|
||||||
StaticStore.GetPlan(sponsoringOrg.PlanType).Product != requiredSponsoringProductType.Value)
|
StaticStore.GetPlan(sponsoringOrg.PlanType).Product != requiredSponsoringProductType.Value)
|
||||||
@ -56,7 +54,7 @@ namespace Bit.Api.Controllers
|
|||||||
throw new BadRequestException("Specified Organization cannot sponsor other organizations.");
|
throw new BadRequestException("Specified Organization cannot sponsor other organizations.");
|
||||||
}
|
}
|
||||||
|
|
||||||
var sponsoringOrgUser = await _organizationUserRepository.GetByOrganizationAsync(sponsoringOrgIdGuid, _currentContext.UserId ?? default);
|
var sponsoringOrgUser = await _organizationUserRepository.GetByOrganizationAsync(sponsoringOrgId, _currentContext.UserId ?? default);
|
||||||
if (sponsoringOrgUser == null || sponsoringOrgUser.Status != OrganizationUserStatusType.Confirmed)
|
if (sponsoringOrgUser == null || sponsoringOrgUser.Status != OrganizationUserStatusType.Confirmed)
|
||||||
{
|
{
|
||||||
throw new BadRequestException("Only confirmed users can sponsor other organizations.");
|
throw new BadRequestException("Only confirmed users can sponsor other organizations.");
|
||||||
@ -74,17 +72,15 @@ namespace Bit.Api.Controllers
|
|||||||
|
|
||||||
[HttpPost("{sponsoringOrgId}/families-for-enterprise/resend")]
|
[HttpPost("{sponsoringOrgId}/families-for-enterprise/resend")]
|
||||||
[SelfHosted(NotSelfHostedOnly = true)]
|
[SelfHosted(NotSelfHostedOnly = true)]
|
||||||
public async Task ResendSponsorshipOffer(string sponsoringOrgId)
|
public async Task ResendSponsorshipOffer(Guid sponsoringOrgId)
|
||||||
{
|
{
|
||||||
// TODO: validate has right to sponsor, send sponsorship email
|
var sponsoringOrg = await _organizationRepository.GetByIdAsync(sponsoringOrgId);
|
||||||
var sponsoringOrgIdGuid = new Guid(sponsoringOrgId);
|
|
||||||
var sponsoringOrg = await _organizationRepository.GetByIdAsync(sponsoringOrgIdGuid);
|
|
||||||
if (sponsoringOrg == null)
|
if (sponsoringOrg == null)
|
||||||
{
|
{
|
||||||
throw new BadRequestException("Cannot find the requested sponsoring organization.");
|
throw new BadRequestException("Cannot find the requested sponsoring organization.");
|
||||||
}
|
}
|
||||||
|
|
||||||
var sponsoringOrgUser = await _organizationUserRepository.GetByOrganizationAsync(sponsoringOrgIdGuid, _currentContext.UserId ?? default);
|
var sponsoringOrgUser = await _organizationUserRepository.GetByOrganizationAsync(sponsoringOrgId, _currentContext.UserId ?? default);
|
||||||
if (sponsoringOrgUser == null || sponsoringOrgUser.Status != OrganizationUserStatusType.Confirmed)
|
if (sponsoringOrgUser == null || sponsoringOrgUser.Status != OrganizationUserStatusType.Confirmed)
|
||||||
{
|
{
|
||||||
throw new BadRequestException("Only confirmed users can sponsor other organizations.");
|
throw new BadRequestException("Only confirmed users can sponsor other organizations.");
|
||||||
@ -146,11 +142,10 @@ namespace Bit.Api.Controllers
|
|||||||
[HttpDelete("{sponsoringOrganizationId}")]
|
[HttpDelete("{sponsoringOrganizationId}")]
|
||||||
[HttpPost("{sponsoringOrganizationId}/delete")]
|
[HttpPost("{sponsoringOrganizationId}/delete")]
|
||||||
[SelfHosted(NotSelfHostedOnly = true)]
|
[SelfHosted(NotSelfHostedOnly = true)]
|
||||||
public async Task RevokeSponsorship(string sponsoringOrganizationId)
|
public async Task RevokeSponsorship(Guid sponsoringOrganizationId)
|
||||||
{
|
{
|
||||||
var sponsoringOrganizationIdGuid = new Guid(sponsoringOrganizationId);
|
|
||||||
|
|
||||||
var orgUser = await _organizationUserRepository.GetByOrganizationAsync(sponsoringOrganizationIdGuid, _currentContext.UserId ?? default);
|
var orgUser = await _organizationUserRepository.GetByOrganizationAsync(sponsoringOrganizationId, _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.");
|
||||||
@ -181,17 +176,16 @@ namespace Bit.Api.Controllers
|
|||||||
[HttpDelete("sponsored/{sponsoredOrgId}")]
|
[HttpDelete("sponsored/{sponsoredOrgId}")]
|
||||||
[HttpPost("sponsored/{sponsoredOrgId}/remove")]
|
[HttpPost("sponsored/{sponsoredOrgId}/remove")]
|
||||||
[SelfHosted(NotSelfHostedOnly = true)]
|
[SelfHosted(NotSelfHostedOnly = true)]
|
||||||
public async Task RemoveSponsorship(string sponsoredOrgId)
|
public async Task RemoveSponsorship(Guid sponsoredOrgId)
|
||||||
{
|
{
|
||||||
var sponsoredOrgIdGuid = new Guid(sponsoredOrgId);
|
|
||||||
|
|
||||||
if (!await _currentContext.OrganizationOwner(sponsoredOrgIdGuid))
|
if (!await _currentContext.OrganizationOwner(sponsoredOrgId))
|
||||||
{
|
{
|
||||||
throw new BadRequestException("Only the owner of an organization can remove sponsorship.");
|
throw new BadRequestException("Only the owner of an organization can remove sponsorship.");
|
||||||
}
|
}
|
||||||
|
|
||||||
var existingOrgSponsorship = await _organizationSponsorshipRepository
|
var existingOrgSponsorship = await _organizationSponsorshipRepository
|
||||||
.GetBySponsoredOrganizationIdAsync(sponsoredOrgIdGuid);
|
.GetBySponsoredOrganizationIdAsync(sponsoredOrgId);
|
||||||
if (existingOrgSponsorship == null || existingOrgSponsorship.SponsoredOrganizationId == null)
|
if (existingOrgSponsorship == null || existingOrgSponsorship.SponsoredOrganizationId == null)
|
||||||
{
|
{
|
||||||
throw new BadRequestException("The requested organization is not currently being sponsored.");
|
throw new BadRequestException("The requested organization is not currently being sponsored.");
|
||||||
|
Reference in New Issue
Block a user