mirror of
https://github.com/bitwarden/server.git
synced 2025-04-15 01:58:14 -05:00
use directory bit on orgs
This commit is contained in:
parent
c362f88246
commit
2ad365706c
@ -11,6 +11,7 @@ namespace Bit.Core.Models.Api
|
|||||||
Id = organization.OrganizationId.ToString();
|
Id = organization.OrganizationId.ToString();
|
||||||
Name = organization.Name;
|
Name = organization.Name;
|
||||||
UseGroups = organization.UseGroups;
|
UseGroups = organization.UseGroups;
|
||||||
|
UseDirectory = organization.UseDirectory;
|
||||||
Seats = organization.Seats;
|
Seats = organization.Seats;
|
||||||
MaxCollections = organization.MaxCollections;
|
MaxCollections = organization.MaxCollections;
|
||||||
Key = organization.Key;
|
Key = organization.Key;
|
||||||
@ -22,6 +23,7 @@ namespace Bit.Core.Models.Api
|
|||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public bool UseGroups { get; set; }
|
public bool UseGroups { get; set; }
|
||||||
|
public bool UseDirectory { get; set; }
|
||||||
public int Seats { get; set; }
|
public int Seats { get; set; }
|
||||||
public int MaxCollections { get; set; }
|
public int MaxCollections { get; set; }
|
||||||
public string Key { get; set; }
|
public string Key { get; set; }
|
||||||
|
@ -8,6 +8,7 @@ namespace Bit.Core.Models.Data
|
|||||||
public Guid? UserId { get; set; }
|
public Guid? UserId { get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public bool UseGroups { get; set; }
|
public bool UseGroups { get; set; }
|
||||||
|
public bool UseDirectory { get; set; }
|
||||||
public int Seats { get; set; }
|
public int Seats { get; set; }
|
||||||
public int MaxCollections { get; set; }
|
public int MaxCollections { get; set; }
|
||||||
public string Key { get; set; }
|
public string Key { get; set; }
|
||||||
|
@ -12,6 +12,7 @@ namespace Bit.Core.Models.StaticStore
|
|||||||
public bool CanBuyAdditionalSeats { get; set; }
|
public bool CanBuyAdditionalSeats { get; set; }
|
||||||
public short? MaxAdditionalSeats { get; set; }
|
public short? MaxAdditionalSeats { get; set; }
|
||||||
public bool UseGroups { get; set; }
|
public bool UseGroups { get; set; }
|
||||||
|
public bool UseDirectory { get; set; }
|
||||||
public decimal BasePrice { get; set; }
|
public decimal BasePrice { get; set; }
|
||||||
public decimal SeatPrice { get; set; }
|
public decimal SeatPrice { get; set; }
|
||||||
public short? MaxCollections { get; set; }
|
public short? MaxCollections { get; set; }
|
||||||
|
@ -15,6 +15,7 @@ namespace Bit.Core.Models.Table
|
|||||||
public short? Seats { get; set; }
|
public short? Seats { get; set; }
|
||||||
public short? MaxCollections { get; set; }
|
public short? MaxCollections { get; set; }
|
||||||
public bool UseGroups { get; set; }
|
public bool UseGroups { get; set; }
|
||||||
|
public bool UseDirectory { get; set; }
|
||||||
public string StripeCustomerId { get; set; }
|
public string StripeCustomerId { get; set; }
|
||||||
public string StripeSubscriptionId { get; set; }
|
public string StripeSubscriptionId { get; set; }
|
||||||
public bool Enabled { get; set; } = true;
|
public bool Enabled { get; set; } = true;
|
||||||
|
@ -576,9 +576,11 @@ namespace Bit.Core.Services
|
|||||||
Seats = (short)(plan.BaseSeats + signup.AdditionalSeats),
|
Seats = (short)(plan.BaseSeats + signup.AdditionalSeats),
|
||||||
MaxCollections = plan.MaxCollections,
|
MaxCollections = plan.MaxCollections,
|
||||||
UseGroups = plan.UseGroups,
|
UseGroups = plan.UseGroups,
|
||||||
|
UseDirectory = plan.UseDirectory,
|
||||||
Plan = plan.Name,
|
Plan = plan.Name,
|
||||||
StripeCustomerId = customer?.Id,
|
StripeCustomerId = customer?.Id,
|
||||||
StripeSubscriptionId = subscription?.Id,
|
StripeSubscriptionId = subscription?.Id,
|
||||||
|
Enabled = true,
|
||||||
CreationDate = DateTime.UtcNow,
|
CreationDate = DateTime.UtcNow,
|
||||||
RevisionDate = DateTime.UtcNow
|
RevisionDate = DateTime.UtcNow
|
||||||
};
|
};
|
||||||
@ -939,19 +941,19 @@ namespace Bit.Core.Services
|
|||||||
throw new NotFoundException();
|
throw new NotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!organization.UseGroups)
|
if(!organization.UseDirectory)
|
||||||
{
|
{
|
||||||
throw new BadRequestException("Organization cannot use groups.");
|
throw new BadRequestException("Organization cannot use directory syncing.");
|
||||||
}
|
}
|
||||||
|
|
||||||
var newUsersSet = new HashSet<string>(newUsers.Select(u => u.ExternalId));
|
var newUsersSet = new HashSet<string>(newUsers?.Select(u => u.ExternalId) ?? new List<string>());
|
||||||
var existingUsers = await _organizationUserRepository.GetManyDetailsByOrganizationAsync(organizationId);
|
var existingUsers = await _organizationUserRepository.GetManyDetailsByOrganizationAsync(organizationId);
|
||||||
var existingExternalUsers = existingUsers.Where(u => !string.IsNullOrWhiteSpace(u.ExternalId)).ToList();
|
var existingExternalUsers = existingUsers.Where(u => !string.IsNullOrWhiteSpace(u.ExternalId)).ToList();
|
||||||
var existingExternalUsersIdDict = existingExternalUsers.ToDictionary(u => u.ExternalId, u => u.Id);
|
var existingExternalUsersIdDict = existingExternalUsers.ToDictionary(u => u.ExternalId, u => u.Id);
|
||||||
|
|
||||||
// Users
|
// Users
|
||||||
// Remove Users
|
// Remove Users
|
||||||
if(removeUserExternalIds.Any())
|
if(removeUserExternalIds?.Any() ?? false)
|
||||||
{
|
{
|
||||||
var removeUsersSet = new HashSet<string>(removeUserExternalIds);
|
var removeUsersSet = new HashSet<string>(removeUserExternalIds);
|
||||||
var existingUsersDict = existingExternalUsers.ToDictionary(u => u.ExternalId);
|
var existingUsersDict = existingExternalUsers.ToDictionary(u => u.ExternalId);
|
||||||
@ -969,7 +971,7 @@ namespace Bit.Core.Services
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add new users
|
// Add new users
|
||||||
if(newUsers.Any())
|
if(newUsers?.Any() ?? false)
|
||||||
{
|
{
|
||||||
var existingUsersSet = new HashSet<string>(existingExternalUsers.Select(u => u.ExternalId));
|
var existingUsersSet = new HashSet<string>(existingExternalUsers.Select(u => u.ExternalId));
|
||||||
var usersToAdd = newUsersSet.Except(existingUsersSet).ToList();
|
var usersToAdd = newUsersSet.Except(existingUsersSet).ToList();
|
||||||
@ -1026,6 +1028,11 @@ namespace Bit.Core.Services
|
|||||||
// Groups
|
// Groups
|
||||||
if(groups?.Any() ?? false)
|
if(groups?.Any() ?? false)
|
||||||
{
|
{
|
||||||
|
if(!organization.UseGroups)
|
||||||
|
{
|
||||||
|
throw new BadRequestException("Organization cannot use groups.");
|
||||||
|
}
|
||||||
|
|
||||||
var groupsDict = groups.ToDictionary(g => g.Group.ExternalId);
|
var groupsDict = groups.ToDictionary(g => g.Group.ExternalId);
|
||||||
var existingGroups = await _groupRepository.GetManyByOrganizationIdAsync(organizationId);
|
var existingGroups = await _groupRepository.GetManyByOrganizationIdAsync(organizationId);
|
||||||
var existingExternalGroups = existingGroups.Where(u => !string.IsNullOrWhiteSpace(u.ExternalId)).ToList();
|
var existingExternalGroups = existingGroups.Where(u => !string.IsNullOrWhiteSpace(u.ExternalId)).ToList();
|
||||||
|
@ -152,7 +152,8 @@ namespace Bit.Core.Utilities
|
|||||||
StripeSeatPlanId = "enterprise-org-seat-monthly",
|
StripeSeatPlanId = "enterprise-org-seat-monthly",
|
||||||
UpgradeSortOrder = 3,
|
UpgradeSortOrder = 3,
|
||||||
TrialPeriodDays = 7,
|
TrialPeriodDays = 7,
|
||||||
UseGroups = true
|
UseGroups = true,
|
||||||
|
UseDirectory = true
|
||||||
},
|
},
|
||||||
new Plan
|
new Plan
|
||||||
{
|
{
|
||||||
@ -166,7 +167,8 @@ namespace Bit.Core.Utilities
|
|||||||
StripeSeatPlanId = "enterprise-org-seat-annually",
|
StripeSeatPlanId = "enterprise-org-seat-annually",
|
||||||
UpgradeSortOrder = 3,
|
UpgradeSortOrder = 3,
|
||||||
TrialPeriodDays = 7,
|
TrialPeriodDays = 7,
|
||||||
UseGroups = true
|
UseGroups = true,
|
||||||
|
UseDirectory = true
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
@Seats SMALLINT,
|
@Seats SMALLINT,
|
||||||
@MaxCollections SMALLINT,
|
@MaxCollections SMALLINT,
|
||||||
@UseGroups BIT,
|
@UseGroups BIT,
|
||||||
|
@UseDirectory BIT,
|
||||||
@StripeCustomerId VARCHAR(50),
|
@StripeCustomerId VARCHAR(50),
|
||||||
@StripeSubscriptionId VARCHAR(50),
|
@StripeSubscriptionId VARCHAR(50),
|
||||||
@Enabled BIT,
|
@Enabled BIT,
|
||||||
@ -28,6 +29,7 @@ BEGIN
|
|||||||
[Seats],
|
[Seats],
|
||||||
[MaxCollections],
|
[MaxCollections],
|
||||||
[UseGroups],
|
[UseGroups],
|
||||||
|
[UseDirectory],
|
||||||
[StripeCustomerId],
|
[StripeCustomerId],
|
||||||
[StripeSubscriptionId],
|
[StripeSubscriptionId],
|
||||||
[Enabled],
|
[Enabled],
|
||||||
@ -45,6 +47,7 @@ BEGIN
|
|||||||
@Seats,
|
@Seats,
|
||||||
@MaxCollections,
|
@MaxCollections,
|
||||||
@UseGroups,
|
@UseGroups,
|
||||||
|
@UseDirectory,
|
||||||
@StripeCustomerId,
|
@StripeCustomerId,
|
||||||
@StripeSubscriptionId,
|
@StripeSubscriptionId,
|
||||||
@Enabled,
|
@Enabled,
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
@Seats SMALLINT,
|
@Seats SMALLINT,
|
||||||
@MaxCollections SMALLINT,
|
@MaxCollections SMALLINT,
|
||||||
@UseGroups BIT,
|
@UseGroups BIT,
|
||||||
|
@UseDirectory BIT,
|
||||||
@StripeCustomerId VARCHAR(50),
|
@StripeCustomerId VARCHAR(50),
|
||||||
@StripeSubscriptionId VARCHAR(50),
|
@StripeSubscriptionId VARCHAR(50),
|
||||||
@Enabled BIT,
|
@Enabled BIT,
|
||||||
@ -29,6 +30,7 @@ BEGIN
|
|||||||
[Seats] = @Seats,
|
[Seats] = @Seats,
|
||||||
[MaxCollections] = @MaxCollections,
|
[MaxCollections] = @MaxCollections,
|
||||||
[UseGroups] = @UseGroups,
|
[UseGroups] = @UseGroups,
|
||||||
|
[UseDirectory] = @UseDirectory,
|
||||||
[StripeCustomerId] = @StripeCustomerId,
|
[StripeCustomerId] = @StripeCustomerId,
|
||||||
[StripeSubscriptionId] = @StripeSubscriptionId,
|
[StripeSubscriptionId] = @StripeSubscriptionId,
|
||||||
[Enabled] = @Enabled,
|
[Enabled] = @Enabled,
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
[Seats] SMALLINT NULL,
|
[Seats] SMALLINT NULL,
|
||||||
[MaxCollections] SMALLINT NULL,
|
[MaxCollections] SMALLINT NULL,
|
||||||
[UseGroups] BIT NOT NULL,
|
[UseGroups] BIT NOT NULL,
|
||||||
|
[UseDirectory] BIT NOT NULL,
|
||||||
[StripeCustomerId] VARCHAR (50) NULL,
|
[StripeCustomerId] VARCHAR (50) NULL,
|
||||||
[StripeSubscriptionId] VARCHAR (50) NULL,
|
[StripeSubscriptionId] VARCHAR (50) NULL,
|
||||||
[Enabled] BIT NOT NULL,
|
[Enabled] BIT NOT NULL,
|
||||||
|
@ -6,6 +6,7 @@ SELECT
|
|||||||
O.[Name],
|
O.[Name],
|
||||||
O.[Enabled],
|
O.[Enabled],
|
||||||
O.[UseGroups],
|
O.[UseGroups],
|
||||||
|
O.[UseDirectory],
|
||||||
O.[Seats],
|
O.[Seats],
|
||||||
O.[MaxCollections],
|
O.[MaxCollections],
|
||||||
OU.[Key],
|
OU.[Key],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user