1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-02 00:22:50 -05:00

Families for enterprise/stripe integrations (#1699)

* Add PlanSponsorshipType to static store

* Add sponsorship type to token and creates sponsorship

* PascalCase properties

* Require sponsorship for remove

* Create subscription sponsorship helper class

* Handle Sponsored subscription changes

* Add sponsorship id to subscription metadata

* Make sponsoring references nullable

This state indicates that a sponsorship has lapsed, but was not able to
be reverted for billing reasons

* WIP: Validate and remove subscriptions

* Update sponsorships on organization and org user delete

* Add friendly name to organization sponsorship
This commit is contained in:
Matt Gibson
2021-11-08 17:01:09 -06:00
committed by Justin Baur
parent 143be4273b
commit 45f6ec1781
42 changed files with 1060 additions and 188 deletions

View File

@ -10,7 +10,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace Bit.PostgresMigrations.Migrations
{
[DbContext(typeof(DatabaseContext))]
[Migration("20211104164532_OrganizationSponsorship")]
[Migration("20211108225011_OrganizationSponsorship")]
partial class OrganizationSponsorship
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -599,6 +599,10 @@ namespace Bit.PostgresMigrations.Migrations
b.Property<bool>("CloudSponsor")
.HasColumnType("boolean");
b.Property<string>("FriendlyName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<Guid?>("InstallationId")
.HasColumnType("uuid");
@ -615,10 +619,10 @@ namespace Bit.PostgresMigrations.Migrations
b.Property<Guid?>("SponsoredOrganizationId")
.HasColumnType("uuid");
b.Property<Guid>("SponsoringOrganizationId")
b.Property<Guid?>("SponsoringOrganizationId")
.HasColumnType("uuid");
b.Property<Guid>("SponsoringOrganizationUserId")
b.Property<Guid?>("SponsoringOrganizationUserId")
.HasColumnType("uuid");
b.Property<DateTime?>("SponsorshipLapsedDate")
@ -1365,9 +1369,7 @@ namespace Bit.PostgresMigrations.Migrations
b.HasOne("Bit.Core.Models.EntityFramework.Organization", "SponsoringOrganization")
.WithMany()
.HasForeignKey("SponsoringOrganizationId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
.HasForeignKey("SponsoringOrganizationId");
b.Navigation("Installation");

View File

@ -20,9 +20,10 @@ namespace Bit.PostgresMigrations.Migrations
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
InstallationId = table.Column<Guid>(type: "uuid", nullable: true),
SponsoringOrganizationId = table.Column<Guid>(type: "uuid", nullable: false),
SponsoringOrganizationUserId = table.Column<Guid>(type: "uuid", nullable: false),
SponsoringOrganizationId = table.Column<Guid>(type: "uuid", nullable: true),
SponsoringOrganizationUserId = table.Column<Guid>(type: "uuid", nullable: true),
SponsoredOrganizationId = table.Column<Guid>(type: "uuid", nullable: true),
FriendlyName = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
OfferedToEmail = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
PlanSponsorshipType = table.Column<byte>(type: "smallint", nullable: true),
CloudSponsor = table.Column<bool>(type: "boolean", nullable: false),
@ -50,7 +51,7 @@ namespace Bit.PostgresMigrations.Migrations
column: x => x.SponsoringOrganizationId,
principalTable: "Organization",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateIndex(

View File

@ -597,6 +597,10 @@ namespace Bit.PostgresMigrations.Migrations
b.Property<bool>("CloudSponsor")
.HasColumnType("boolean");
b.Property<string>("FriendlyName")
.HasMaxLength(256)
.HasColumnType("character varying(256)");
b.Property<Guid?>("InstallationId")
.HasColumnType("uuid");
@ -613,10 +617,10 @@ namespace Bit.PostgresMigrations.Migrations
b.Property<Guid?>("SponsoredOrganizationId")
.HasColumnType("uuid");
b.Property<Guid>("SponsoringOrganizationId")
b.Property<Guid?>("SponsoringOrganizationId")
.HasColumnType("uuid");
b.Property<Guid>("SponsoringOrganizationUserId")
b.Property<Guid?>("SponsoringOrganizationUserId")
.HasColumnType("uuid");
b.Property<DateTime?>("SponsorshipLapsedDate")
@ -1363,9 +1367,7 @@ namespace Bit.PostgresMigrations.Migrations
b.HasOne("Bit.Core.Models.EntityFramework.Organization", "SponsoringOrganization")
.WithMany()
.HasForeignKey("SponsoringOrganizationId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
.HasForeignKey("SponsoringOrganizationId");
b.Navigation("Installation");

View File

@ -5,9 +5,10 @@ ALTER TABLE "User" ADD "UsesCryptoAgent" boolean NOT NULL DEFAULT FALSE;
CREATE TABLE "OrganizationSponsorship" (
"Id" uuid NOT NULL,
"InstallationId" uuid NULL,
"SponsoringOrganizationId" uuid NOT NULL,
"SponsoringOrganizationUserId" uuid NOT NULL,
"SponsoringOrganizationId" uuid NULL,
"SponsoringOrganizationUserId" uuid NULL,
"SponsoredOrganizationId" uuid NULL,
"FriendlyName" character varying(256) NULL,
"OfferedToEmail" character varying(256) NULL,
"PlanSponsorshipType" smallint NULL,
"CloudSponsor" boolean NOT NULL,
@ -17,7 +18,7 @@ CREATE TABLE "OrganizationSponsorship" (
CONSTRAINT "PK_OrganizationSponsorship" PRIMARY KEY ("Id"),
CONSTRAINT "FK_OrganizationSponsorship_Installation_InstallationId" FOREIGN KEY ("InstallationId") REFERENCES "Installation" ("Id") ON DELETE RESTRICT,
CONSTRAINT "FK_OrganizationSponsorship_Organization_SponsoredOrganizationId" FOREIGN KEY ("SponsoredOrganizationId") REFERENCES "Organization" ("Id") ON DELETE RESTRICT,
CONSTRAINT "FK_OrganizationSponsorship_Organization_SponsoringOrganization~" FOREIGN KEY ("SponsoringOrganizationId") REFERENCES "Organization" ("Id") ON DELETE CASCADE
CONSTRAINT "FK_OrganizationSponsorship_Organization_SponsoringOrganization~" FOREIGN KEY ("SponsoringOrganizationId") REFERENCES "Organization" ("Id") ON DELETE RESTRICT
);
CREATE INDEX "IX_OrganizationSponsorship_InstallationId" ON "OrganizationSponsorship" ("InstallationId");
@ -27,6 +28,6 @@ CREATE INDEX "IX_OrganizationSponsorship_SponsoredOrganizationId" ON "Organizati
CREATE INDEX "IX_OrganizationSponsorship_SponsoringOrganizationId" ON "OrganizationSponsorship" ("SponsoringOrganizationId");
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20211104164532_OrganizationSponsorship', '5.0.9');
VALUES ('20211108225011_OrganizationSponsorship', '5.0.9');
COMMIT;