From bc003c4449b65794bb90e4ab54f7a7c70f1a7868 Mon Sep 17 00:00:00 2001 From: Oscar Hinton Date: Mon, 23 Aug 2021 14:32:29 +0200 Subject: [PATCH] Add support for managing organizations through providers using the business portal (#1521) --- .../Portal/EnterprisePortalCurrentContext.cs | 42 +++++++++++++++++++ src/Core/Context/CurrentContext.cs | 2 +- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/bitwarden_license/src/Portal/EnterprisePortalCurrentContext.cs b/bitwarden_license/src/Portal/EnterprisePortalCurrentContext.cs index 57914c7e9..892471eea 100644 --- a/bitwarden_license/src/Portal/EnterprisePortalCurrentContext.cs +++ b/bitwarden_license/src/Portal/EnterprisePortalCurrentContext.cs @@ -6,6 +6,7 @@ using Microsoft.Extensions.DependencyInjection; using Bit.Core.Repositories; using System.Linq; using System.Collections.Generic; +using Bit.Core.Enums; using Bit.Core.Models.Data; using Bit.Core.Utilities; @@ -70,6 +71,47 @@ namespace Bit.Portal Type = ou.Type }).ToList(); + // Add all provider orgs. + var providerOrgs = await GetProviderOrganizations(); + Organizations.AddRange(providerOrgs.Select(po => new CurrentContentOrganization + { + Id = po.OrganizationId, + Type = OrganizationUserType.Owner, + })); + // Yes this is ugly, but the business portal is deprecated. + OrganizationsDetails.AddRange(providerOrgs.Select(pu => new OrganizationUserOrganizationDetails + { + OrganizationId = pu.OrganizationId, + UserId = pu.UserId, + Name = pu.Name, + UsePolicies = pu.UsePolicies, + UseSso = pu.UseSso, + UseGroups = pu.UseGroups, + UseDirectory = pu.UseDirectory, + UseEvents = pu.UseEvents, + UseTotp = pu.UseTotp, + Use2fa = pu.Use2fa, + UseApi = pu.UseApi, + UseResetPassword = pu.UseResetPassword, + SelfHost = pu.SelfHost, + UsersGetPremium = pu.UsersGetPremium, + Seats = pu.Seats, + MaxCollections = pu.MaxCollections, + MaxStorageGb = pu.MaxStorageGb, + Key = pu.Key, + Status = OrganizationUserStatusType.Confirmed, + Type = OrganizationUserType.Owner, + Enabled = pu.Enabled, + SsoExternalId = null, + Identifier = pu.Identifier, + Permissions = null, + ResetPasswordKey = null, + PublicKey = pu.PublicKey, + PrivateKey = pu.PrivateKey, + ProviderId = pu.ProviderId, + ProviderName = pu.ProviderName, + })); + if (SelectedOrganizationId == null && HttpContext.Request.Cookies.ContainsKey("SelectedOrganization") && Guid.TryParse(HttpContext.Request.Cookies["SelectedOrganization"], out var selectedOrgId)) { diff --git a/src/Core/Context/CurrentContext.cs b/src/Core/Context/CurrentContext.cs index e78368356..6d224ff2b 100644 --- a/src/Core/Context/CurrentContext.cs +++ b/src/Core/Context/CurrentContext.cs @@ -441,7 +441,7 @@ namespace Bit.Core.Context }; } - private async Task> GetProviderOrganizations() + protected async Task> GetProviderOrganizations() { if (_providerUserOrganizations == null) {