mirror of
https://github.com/bitwarden/server
synced 2025-12-25 04:33:26 +00:00
Add PlanSponsorshipType to db model
This commit is contained in:
@@ -64,7 +64,7 @@ namespace Bit.Api.Controllers
|
||||
throw new BadRequestException("Can only sponsor one organization per Organization User.");
|
||||
}
|
||||
|
||||
await _organizationsSponsorshipService.OfferSponsorshipAsync(sponsoringOrg, sponsoringOrgUser, model.sponsoredEmail);
|
||||
await _organizationsSponsorshipService.OfferSponsorshipAsync(sponsoringOrg, sponsoringOrgUser, model.PlanSponsorshipType, model.sponsoredEmail);
|
||||
}
|
||||
|
||||
[HttpPost("sponsored/redeem/families-for-enterprise")]
|
||||
|
||||
10
src/Core/Enums/PlanSponsorshipType.cs
Normal file
10
src/Core/Enums/PlanSponsorshipType.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Bit.Core.Enums
|
||||
{
|
||||
public enum PlanSponsorshipType : byte
|
||||
{
|
||||
[Display(Name = "Families For Enterprise")]
|
||||
FamiliesForEnterprise = 0,
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,18 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Utilities;
|
||||
|
||||
namespace Bit.Core.Models.Api.Request
|
||||
{
|
||||
public class OrganizationSponsorshipRequestModel
|
||||
{
|
||||
[Required]
|
||||
public PlanSponsorshipType PlanSponsorshipType { get; set; }
|
||||
|
||||
[Required]
|
||||
public Guid OrganizationUserId { get; set; }
|
||||
|
||||
[Required]
|
||||
[StringLength(256)]
|
||||
[StrictEmailAddress]
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Utilities;
|
||||
|
||||
namespace Bit.Core.Models.Table
|
||||
@@ -15,6 +16,7 @@ namespace Bit.Core.Models.Table
|
||||
public Guid? SponsoredOrganizationId { get; set; }
|
||||
[MaxLength(256)]
|
||||
public string OfferedToEmail { get; set; }
|
||||
public PlanSponsorshipType? PlanSponsorshipType { get; set; }
|
||||
[Required]
|
||||
public bool CloudSponsor { get; set; }
|
||||
public DateTime? LastSyncDate { get; set; }
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Threading.Tasks;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models.Table;
|
||||
|
||||
namespace Bit.Core.Services
|
||||
@@ -6,7 +7,7 @@ namespace Bit.Core.Services
|
||||
public interface IOrganizationSponsorshipService
|
||||
{
|
||||
Task<bool> ValidateRedemptionTokenAsync(string encryptedToken);
|
||||
Task OfferSponsorshipAsync(Organization sponsoringOrg, OrganizationUser sponsoringOrgUser, string sponsoredEmail);
|
||||
Task OfferSponsorshipAsync(Organization sponsoringOrg, OrganizationUser sponsoringOrgUser, PlanSponsorshipType sponsorshipType, string sponsoredEmail);
|
||||
Task SetUpSponsorshipAsync(OrganizationSponsorship sponsorship, Organization sponsoredOrganization);
|
||||
Task RemoveSponsorshipAsync(OrganizationSponsorship sponsorship);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models.Table;
|
||||
using Bit.Core.Repositories;
|
||||
using Microsoft.AspNetCore.DataProtection;
|
||||
@@ -38,25 +39,31 @@ namespace Bit.Core.Services
|
||||
|
||||
if (dataParts[0].Equals(FamiliesForEnterpriseTokenName))
|
||||
{
|
||||
if (!Guid.TryParse(dataParts[1], out Guid sponsorshipId))
|
||||
if (!Guid.TryParse(dataParts[1], out Guid sponsorshipId) ||
|
||||
!Enum.TryParse<PlanSponsorshipType>(dataParts[2], true, out var sponsorshipType))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var sponsorship = await _organizationSponsorshipRepository.GetByIdAsync(sponsorshipId);
|
||||
return sponsorship != null;
|
||||
if (sponsorship == null || sponsorship.PlanSponsorshipType != sponsorshipType)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private string RedemptionToken(Guid sponsorshipId) =>
|
||||
private string RedemptionToken(Guid sponsorshipId, PlanSponsorshipType sponsorshipType) =>
|
||||
string.Concat(
|
||||
TokenClearTextPrefix,
|
||||
_dataProtector.Protect($"{FamiliesForEnterpriseTokenName} {sponsorshipId}")
|
||||
_dataProtector.Protect($"{FamiliesForEnterpriseTokenName} {sponsorshipId} {sponsorshipType}")
|
||||
);
|
||||
|
||||
public async Task OfferSponsorshipAsync(Organization sponsoringOrg, OrganizationUser sponsoringOrgUser, string sponsoredEmail)
|
||||
public async Task OfferSponsorshipAsync(Organization sponsoringOrg, OrganizationUser sponsoringOrgUser, PlanSponsorshipType sponsorshipType, string sponsoredEmail)
|
||||
{
|
||||
var sponsorship = new OrganizationSponsorship
|
||||
{
|
||||
|
||||
@@ -5,6 +5,7 @@ CREATE PROCEDURE [dbo].[OrganizationSponsorship_Create]
|
||||
@SponsoringOrganizationUserID UNIQUEIDENTIFIER,
|
||||
@SponsoredOrganizationId UNIQUEIDENTIFIER,
|
||||
@OfferedToEmail NVARCHAR(256),
|
||||
@PlanSponsorshipType TINYINT,
|
||||
@CloudSponsor BIT,
|
||||
@LastSyncDate DATETIME2 (7),
|
||||
@TimesRenewedWithoutValidation TINYINT,
|
||||
@@ -21,6 +22,7 @@ BEGIN
|
||||
[SponsoringOrganizationUserID],
|
||||
[SponsoredOrganizationId],
|
||||
[OfferedToEmail],
|
||||
[PlanSponsorshipType],
|
||||
[CloudSponsor],
|
||||
[LastSyncDate],
|
||||
[TimesRenewedWithoutValidation],
|
||||
@@ -34,6 +36,7 @@ BEGIN
|
||||
@SponsoringOrganizationUserID,
|
||||
@SponsoredOrganizationId,
|
||||
@OfferedToEmail,
|
||||
@PlanSponsorshipType,
|
||||
@CloudSponsor,
|
||||
@LastSyncDate,
|
||||
@TimesRenewedWithoutValidation,
|
||||
|
||||
@@ -5,6 +5,7 @@ CREATE PROCEDURE [dbo].[OrganizationSponsorship_Update]
|
||||
@SponsoringOrganizationUserID UNIQUEIDENTIFIER,
|
||||
@SponsoredOrganizationId UNIQUEIDENTIFIER,
|
||||
@OfferedToEmail NVARCHAR(256),
|
||||
@PlanSponsorshipType TINYINT,
|
||||
@CloudSponsor BIT,
|
||||
@LastSyncDate DATETIME2 (7),
|
||||
@TimesRenewedWithoutValidation TINYINT,
|
||||
@@ -21,6 +22,7 @@ BEGIN
|
||||
[SponsoringOrganizationUserID] = @SponsoringOrganizationUserID,
|
||||
[SponsoredOrganizationId] = @SponsoredOrganizationId,
|
||||
[OfferedToEmail] = @OfferedToEmail,
|
||||
[PlanSponsorshipType] = @PlanSponsorshipType,
|
||||
[CloudSponsor] = @CloudSponsor,
|
||||
[LastSyncDate] = @LastSyncDate,
|
||||
[TimesRenewedWithoutValidation] = @TimesRenewedWithoutValidation,
|
||||
|
||||
@@ -2,9 +2,10 @@ CREATE TABLE [dbo].[OrganizationSponsorship] (
|
||||
[Id] UNIQUEIDENTIFIER NOT NULL,
|
||||
[InstallationId] UNIQUEIDENTIFIER NULL,
|
||||
[SponsoringOrganizationId] UNIQUEIDENTIFIER NOT NULL,
|
||||
[SponsorginOrganizationUserID] UNIQUEIDENTIFIER NOT NULL,
|
||||
[SponsoringOrganizationUserID] UNIQUEIDENTIFIER NOT NULL,
|
||||
[SponsoredOrganizationId] UNIQUEIDENTIFIER NULL,
|
||||
[OfferedToEmail] NVARCHAR (256) NULL,
|
||||
[PlanSponsorshipType] TINYINT NULL,
|
||||
[CloudSponsor] BIT NULL,
|
||||
[LastSyncDate] DATETIME2 (7) NULL,
|
||||
[TimesRenewedWithoutValidation] TINYINT DEFAULT 0,
|
||||
|
||||
Reference in New Issue
Block a user