1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-22 12:15:36 +01:00

use directory bit on orgs

This commit is contained in:
Kyle Spearrin 2017-05-20 15:31:16 -04:00
parent c362f88246
commit 2ad365706c
10 changed files with 28 additions and 7 deletions

View File

@ -11,6 +11,7 @@ namespace Bit.Core.Models.Api
Id = organization.OrganizationId.ToString();
Name = organization.Name;
UseGroups = organization.UseGroups;
UseDirectory = organization.UseDirectory;
Seats = organization.Seats;
MaxCollections = organization.MaxCollections;
Key = organization.Key;
@ -22,6 +23,7 @@ namespace Bit.Core.Models.Api
public string Id { get; set; }
public string Name { get; set; }
public bool UseGroups { get; set; }
public bool UseDirectory { get; set; }
public int Seats { get; set; }
public int MaxCollections { get; set; }
public string Key { get; set; }

View File

@ -8,6 +8,7 @@ namespace Bit.Core.Models.Data
public Guid? UserId { get; set; }
public string Name { get; set; }
public bool UseGroups { get; set; }
public bool UseDirectory { get; set; }
public int Seats { get; set; }
public int MaxCollections { get; set; }
public string Key { get; set; }

View File

@ -12,6 +12,7 @@ namespace Bit.Core.Models.StaticStore
public bool CanBuyAdditionalSeats { get; set; }
public short? MaxAdditionalSeats { get; set; }
public bool UseGroups { get; set; }
public bool UseDirectory { get; set; }
public decimal BasePrice { get; set; }
public decimal SeatPrice { get; set; }
public short? MaxCollections { get; set; }

View File

@ -15,6 +15,7 @@ namespace Bit.Core.Models.Table
public short? Seats { get; set; }
public short? MaxCollections { get; set; }
public bool UseGroups { get; set; }
public bool UseDirectory { get; set; }
public string StripeCustomerId { get; set; }
public string StripeSubscriptionId { get; set; }
public bool Enabled { get; set; } = true;

View File

@ -576,9 +576,11 @@ namespace Bit.Core.Services
Seats = (short)(plan.BaseSeats + signup.AdditionalSeats),
MaxCollections = plan.MaxCollections,
UseGroups = plan.UseGroups,
UseDirectory = plan.UseDirectory,
Plan = plan.Name,
StripeCustomerId = customer?.Id,
StripeSubscriptionId = subscription?.Id,
Enabled = true,
CreationDate = DateTime.UtcNow,
RevisionDate = DateTime.UtcNow
};
@ -939,19 +941,19 @@ namespace Bit.Core.Services
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 existingExternalUsers = existingUsers.Where(u => !string.IsNullOrWhiteSpace(u.ExternalId)).ToList();
var existingExternalUsersIdDict = existingExternalUsers.ToDictionary(u => u.ExternalId, u => u.Id);
// Users
// Remove Users
if(removeUserExternalIds.Any())
if(removeUserExternalIds?.Any() ?? false)
{
var removeUsersSet = new HashSet<string>(removeUserExternalIds);
var existingUsersDict = existingExternalUsers.ToDictionary(u => u.ExternalId);
@ -969,7 +971,7 @@ namespace Bit.Core.Services
}
// Add new users
if(newUsers.Any())
if(newUsers?.Any() ?? false)
{
var existingUsersSet = new HashSet<string>(existingExternalUsers.Select(u => u.ExternalId));
var usersToAdd = newUsersSet.Except(existingUsersSet).ToList();
@ -1026,6 +1028,11 @@ namespace Bit.Core.Services
// Groups
if(groups?.Any() ?? false)
{
if(!organization.UseGroups)
{
throw new BadRequestException("Organization cannot use groups.");
}
var groupsDict = groups.ToDictionary(g => g.Group.ExternalId);
var existingGroups = await _groupRepository.GetManyByOrganizationIdAsync(organizationId);
var existingExternalGroups = existingGroups.Where(u => !string.IsNullOrWhiteSpace(u.ExternalId)).ToList();

View File

@ -152,7 +152,8 @@ namespace Bit.Core.Utilities
StripeSeatPlanId = "enterprise-org-seat-monthly",
UpgradeSortOrder = 3,
TrialPeriodDays = 7,
UseGroups = true
UseGroups = true,
UseDirectory = true
},
new Plan
{
@ -166,7 +167,8 @@ namespace Bit.Core.Utilities
StripeSeatPlanId = "enterprise-org-seat-annually",
UpgradeSortOrder = 3,
TrialPeriodDays = 7,
UseGroups = true
UseGroups = true,
UseDirectory = true
}
};

View File

@ -8,6 +8,7 @@
@Seats SMALLINT,
@MaxCollections SMALLINT,
@UseGroups BIT,
@UseDirectory BIT,
@StripeCustomerId VARCHAR(50),
@StripeSubscriptionId VARCHAR(50),
@Enabled BIT,
@ -28,6 +29,7 @@ BEGIN
[Seats],
[MaxCollections],
[UseGroups],
[UseDirectory],
[StripeCustomerId],
[StripeSubscriptionId],
[Enabled],
@ -45,6 +47,7 @@ BEGIN
@Seats,
@MaxCollections,
@UseGroups,
@UseDirectory,
@StripeCustomerId,
@StripeSubscriptionId,
@Enabled,

View File

@ -8,6 +8,7 @@
@Seats SMALLINT,
@MaxCollections SMALLINT,
@UseGroups BIT,
@UseDirectory BIT,
@StripeCustomerId VARCHAR(50),
@StripeSubscriptionId VARCHAR(50),
@Enabled BIT,
@ -29,6 +30,7 @@ BEGIN
[Seats] = @Seats,
[MaxCollections] = @MaxCollections,
[UseGroups] = @UseGroups,
[UseDirectory] = @UseDirectory,
[StripeCustomerId] = @StripeCustomerId,
[StripeSubscriptionId] = @StripeSubscriptionId,
[Enabled] = @Enabled,

View File

@ -8,6 +8,7 @@
[Seats] SMALLINT NULL,
[MaxCollections] SMALLINT NULL,
[UseGroups] BIT NOT NULL,
[UseDirectory] BIT NOT NULL,
[StripeCustomerId] VARCHAR (50) NULL,
[StripeSubscriptionId] VARCHAR (50) NULL,
[Enabled] BIT NOT NULL,

View File

@ -6,6 +6,7 @@ SELECT
O.[Name],
O.[Enabled],
O.[UseGroups],
O.[UseDirectory],
O.[Seats],
O.[MaxCollections],
OU.[Key],