mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 23:52:50 -05:00
use policies property for orgs
This commit is contained in:
@ -28,6 +28,7 @@ namespace Bit.Admin.Models
|
||||
Plan = org.Plan;
|
||||
Seats = org.Seats;
|
||||
MaxCollections = org.MaxCollections;
|
||||
UsePolicies = org.UsePolicies;
|
||||
UseGroups = org.UseGroups;
|
||||
UseDirectory = org.UseDirectory;
|
||||
UseEvents = org.UseEvents;
|
||||
@ -67,6 +68,8 @@ namespace Bit.Admin.Models
|
||||
public short? Seats { get; set; }
|
||||
[Display(Name = "Max. Collections")]
|
||||
public short? MaxCollections { get; set; }
|
||||
[Display(Name = "Policies")]
|
||||
public bool UsePolicies { get; set; }
|
||||
[Display(Name = "Groups")]
|
||||
public bool UseGroups { get; set; }
|
||||
[Display(Name = "Directory")]
|
||||
@ -107,6 +110,7 @@ namespace Bit.Admin.Models
|
||||
existingOrganization.Plan = Plan;
|
||||
existingOrganization.Seats = Seats;
|
||||
existingOrganization.MaxCollections = MaxCollections;
|
||||
existingOrganization.UsePolicies = UsePolicies;
|
||||
existingOrganization.UseGroups = UseGroups;
|
||||
existingOrganization.UseDirectory = UseDirectory;
|
||||
existingOrganization.UseEvents = UseEvents;
|
||||
|
@ -21,6 +21,7 @@
|
||||
document.getElementById('@(nameof(Model.MaxCollections))').value = '';
|
||||
document.getElementById('@(nameof(Model.MaxStorageGb))').value = '1';
|
||||
// Features
|
||||
document.getElementById('@(nameof(Model.UsePolicies))').checked = true;
|
||||
document.getElementById('@(nameof(Model.UseGroups))').checked = true;
|
||||
document.getElementById('@(nameof(Model.UseDirectory))').checked = true;
|
||||
document.getElementById('@(nameof(Model.UseEvents))').checked = true;
|
||||
@ -160,6 +161,10 @@
|
||||
<input type="checkbox" class="form-check-input" asp-for="UseGroups">
|
||||
<label class="form-check-label" asp-for="UseGroups"></label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input type="checkbox" class="form-check-input" asp-for="UsePolicies">
|
||||
<label class="form-check-label" asp-for="UsePolicies"></label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input type="checkbox" class="form-check-input" asp-for="UseDirectory">
|
||||
<label class="form-check-label" asp-for="UseDirectory"></label>
|
||||
|
@ -30,6 +30,7 @@ namespace Bit.Core.Models.Api
|
||||
Seats = organization.Seats;
|
||||
MaxCollections = organization.MaxCollections;
|
||||
MaxStorageGb = organization.MaxStorageGb;
|
||||
UsePolicies = organization.UsePolicies;
|
||||
UseGroups = organization.UseGroups;
|
||||
UseDirectory = organization.UseDirectory;
|
||||
UseEvents = organization.UseEvents;
|
||||
@ -54,6 +55,7 @@ namespace Bit.Core.Models.Api
|
||||
public short? Seats { get; set; }
|
||||
public short? MaxCollections { get; set; }
|
||||
public short? MaxStorageGb { get; set; }
|
||||
public bool UsePolicies { get; set; }
|
||||
public bool UseGroups { get; set; }
|
||||
public bool UseDirectory { get; set; }
|
||||
public bool UseEvents { get; set; }
|
||||
|
@ -19,7 +19,7 @@ namespace Bit.Core.Models.Business
|
||||
public OrganizationLicense(Organization org, SubscriptionInfo subscriptionInfo, Guid installationId,
|
||||
ILicensingService licenseService)
|
||||
{
|
||||
Version = 5;
|
||||
Version = 5; // TODO: bump to version 6
|
||||
LicenseKey = org.LicenseKey;
|
||||
InstallationId = installationId;
|
||||
Id = org.Id;
|
||||
@ -31,6 +31,7 @@ namespace Bit.Core.Models.Business
|
||||
PlanType = org.PlanType;
|
||||
Seats = org.Seats;
|
||||
MaxCollections = org.MaxCollections;
|
||||
UsePolicies = org.UsePolicies;
|
||||
UseGroups = org.UseGroups;
|
||||
UseEvents = org.UseEvents;
|
||||
UseDirectory = org.UseDirectory;
|
||||
@ -98,6 +99,7 @@ namespace Bit.Core.Models.Business
|
||||
public PlanType PlanType { get; set; }
|
||||
public short? Seats { get; set; }
|
||||
public short? MaxCollections { get; set; }
|
||||
public bool UsePolicies { get; set; }
|
||||
public bool UseGroups { get; set; }
|
||||
public bool UseEvents { get; set; }
|
||||
public bool UseDirectory { get; set; }
|
||||
@ -120,7 +122,7 @@ namespace Bit.Core.Models.Business
|
||||
public byte[] GetDataBytes(bool forHash = false)
|
||||
{
|
||||
string data = null;
|
||||
if(Version >= 1 && Version <= 5)
|
||||
if(Version >= 1 && Version <= 6)
|
||||
{
|
||||
var props = typeof(OrganizationLicense)
|
||||
.GetProperties(BindingFlags.Public | BindingFlags.Instance)
|
||||
@ -135,6 +137,8 @@ namespace Bit.Core.Models.Business
|
||||
(Version >= 4 || !p.Name.Equals(nameof(Use2fa))) &&
|
||||
// UseApi was added in Version 5
|
||||
(Version >= 5 || !p.Name.Equals(nameof(UseApi))) &&
|
||||
// UsePolicies was added in Version 6
|
||||
(Version >= 6 || !p.Name.Equals(nameof(UsePolicies))) &&
|
||||
(
|
||||
!forHash ||
|
||||
(
|
||||
@ -171,7 +175,7 @@ namespace Bit.Core.Models.Business
|
||||
return false;
|
||||
}
|
||||
|
||||
if(Version >= 1 && Version <= 5)
|
||||
if(Version >= 1 && Version <= 6)
|
||||
{
|
||||
return InstallationId == globalSettings.Installation.Id && SelfHost;
|
||||
}
|
||||
@ -188,7 +192,7 @@ namespace Bit.Core.Models.Business
|
||||
return false;
|
||||
}
|
||||
|
||||
if(Version >= 1 && Version <= 5)
|
||||
if(Version >= 1 && Version <= 6)
|
||||
{
|
||||
var valid =
|
||||
globalSettings.Installation.Id == InstallationId &&
|
||||
@ -223,6 +227,11 @@ namespace Bit.Core.Models.Business
|
||||
valid = organization.UseApi == UseApi;
|
||||
}
|
||||
|
||||
if(valid && Version >= 6)
|
||||
{
|
||||
valid = organization.UsePolicies == UsePolicies;
|
||||
}
|
||||
|
||||
return valid;
|
||||
}
|
||||
else
|
||||
|
@ -15,6 +15,7 @@ namespace Bit.Core.Models.StaticStore
|
||||
public short? MaxAdditionalSeats { get; set; }
|
||||
public bool CanBuyPremiumAccessAddon { get; set; }
|
||||
public bool UseGroups { get; set; }
|
||||
public bool UsePolicies { get; set; }
|
||||
public bool UseDirectory { get; set; }
|
||||
public bool UseEvents { get; set; }
|
||||
public bool UseTotp { get; set; }
|
||||
|
@ -24,6 +24,7 @@ namespace Bit.Core.Models.Table
|
||||
public PlanType PlanType { get; set; }
|
||||
public short? Seats { get; set; }
|
||||
public short? MaxCollections { get; set; }
|
||||
public bool UsePolicies { get; set; }
|
||||
public bool UseGroups { get; set; }
|
||||
public bool UseDirectory { get; set; }
|
||||
public bool UseEvents { get; set; }
|
||||
|
@ -33,6 +33,7 @@ namespace Bit.Core.Services
|
||||
private readonly IInstallationRepository _installationRepository;
|
||||
private readonly IApplicationCacheService _applicationCacheService;
|
||||
private readonly IPaymentService _paymentService;
|
||||
private readonly IPolicyRepository _policyRepository;
|
||||
private readonly GlobalSettings _globalSettings;
|
||||
|
||||
public OrganizationService(
|
||||
@ -51,6 +52,7 @@ namespace Bit.Core.Services
|
||||
IInstallationRepository installationRepository,
|
||||
IApplicationCacheService applicationCacheService,
|
||||
IPaymentService paymentService,
|
||||
IPolicyRepository policyRepository,
|
||||
GlobalSettings globalSettings)
|
||||
{
|
||||
_organizationRepository = organizationRepository;
|
||||
@ -68,6 +70,7 @@ namespace Bit.Core.Services
|
||||
_installationRepository = installationRepository;
|
||||
_applicationCacheService = applicationCacheService;
|
||||
_paymentService = paymentService;
|
||||
_policyRepository = policyRepository;
|
||||
_globalSettings = globalSettings;
|
||||
}
|
||||
|
||||
@ -193,6 +196,16 @@ namespace Bit.Core.Services
|
||||
}
|
||||
}
|
||||
|
||||
if(!newPlan.UsePolicies && organization.UsePolicies)
|
||||
{
|
||||
var policies = await _policyRepository.GetManyByOrganizationIdAsync(organization.Id);
|
||||
if(policies.Any(p => p.Enabled))
|
||||
{
|
||||
throw new BadRequestException($"Your new plan does not allow the policies feature. " +
|
||||
$"Disable your policies.");
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Check storage?
|
||||
|
||||
string paymentIntentClientSecret = null;
|
||||
@ -453,6 +466,7 @@ namespace Bit.Core.Services
|
||||
MaxCollections = plan.MaxCollections,
|
||||
MaxStorageGb = !plan.MaxStorageGb.HasValue ?
|
||||
(short?)null : (short)(plan.MaxStorageGb.Value + signup.AdditionalStorageGb),
|
||||
UsePolicies = plan.UsePolicies,
|
||||
UseGroups = plan.UseGroups,
|
||||
UseEvents = plan.UseEvents,
|
||||
UseDirectory = plan.UseDirectory,
|
||||
@ -524,6 +538,7 @@ namespace Bit.Core.Services
|
||||
Seats = license.Seats,
|
||||
MaxCollections = license.MaxCollections,
|
||||
MaxStorageGb = _globalSettings.SelfHosted ? 10240 : license.MaxStorageGb, // 10 TB
|
||||
UsePolicies = license.UsePolicies,
|
||||
UseGroups = license.UseGroups,
|
||||
UseDirectory = license.UseDirectory,
|
||||
UseEvents = license.UseEvents,
|
||||
@ -675,6 +690,16 @@ namespace Bit.Core.Services
|
||||
}
|
||||
}
|
||||
|
||||
if(!license.UsePolicies && organization.UsePolicies)
|
||||
{
|
||||
var policies = await _policyRepository.GetManyByOrganizationIdAsync(organization.Id);
|
||||
if(policies.Any(p => p.Enabled))
|
||||
{
|
||||
throw new BadRequestException($"Your organization currently has {policies.Count} enabled " +
|
||||
$"policies. Your new license does not allow for the use of policies. Disable all policies.");
|
||||
}
|
||||
}
|
||||
|
||||
var dir = $"{_globalSettings.LicenseDirectory}/organization";
|
||||
Directory.CreateDirectory(dir);
|
||||
System.IO.File.WriteAllText($"{dir}/{organization.Id}.json",
|
||||
|
@ -75,6 +75,7 @@ namespace Bit.Core.Utilities
|
||||
services.AddSingleton<IInstallationRepository, SqlServerRepos.InstallationRepository>();
|
||||
services.AddSingleton<IMaintenanceRepository, SqlServerRepos.MaintenanceRepository>();
|
||||
services.AddSingleton<ITransactionRepository, SqlServerRepos.TransactionRepository>();
|
||||
services.AddSingleton<IPolicyRepository, SqlServerRepos.PolicyRepository>();
|
||||
}
|
||||
|
||||
if(globalSettings.SelfHosted)
|
||||
@ -105,6 +106,7 @@ namespace Bit.Core.Utilities
|
||||
services.AddScoped<IOrganizationService, OrganizationService>();
|
||||
services.AddScoped<ICollectionService, CollectionService>();
|
||||
services.AddScoped<IGroupService, GroupService>();
|
||||
services.AddScoped<IPolicyService, PolicyService>();
|
||||
services.AddScoped<Services.IEventService, EventService>();
|
||||
services.AddSingleton<IDeviceService, DeviceService>();
|
||||
services.AddSingleton<IAppleIapService, AppleIapService>();
|
||||
|
@ -164,6 +164,7 @@ namespace Bit.Core.Utilities
|
||||
StripeStoragePlanId = "storage-gb-monthly",
|
||||
UpgradeSortOrder = 3,
|
||||
TrialPeriodDays = 7,
|
||||
UsePolicies = true,
|
||||
UseGroups = true,
|
||||
UseDirectory = true,
|
||||
UseEvents = true,
|
||||
@ -187,6 +188,7 @@ namespace Bit.Core.Utilities
|
||||
StripeStoragePlanId = "storage-gb-annually",
|
||||
UpgradeSortOrder = 3,
|
||||
TrialPeriodDays = 7,
|
||||
UsePolicies = true,
|
||||
UseGroups = true,
|
||||
UseDirectory = true,
|
||||
UseEvents = true,
|
||||
|
@ -12,6 +12,7 @@
|
||||
@PlanType TINYINT,
|
||||
@Seats SMALLINT,
|
||||
@MaxCollections SMALLINT,
|
||||
@UsePolicies BIT,
|
||||
@UseGroups BIT,
|
||||
@UseDirectory BIT,
|
||||
@UseEvents BIT,
|
||||
@ -51,6 +52,7 @@ BEGIN
|
||||
[PlanType],
|
||||
[Seats],
|
||||
[MaxCollections],
|
||||
[UsePolicies],
|
||||
[UseGroups],
|
||||
[UseDirectory],
|
||||
[UseEvents],
|
||||
@ -87,6 +89,7 @@ BEGIN
|
||||
@PlanType,
|
||||
@Seats,
|
||||
@MaxCollections,
|
||||
@UsePolicies,
|
||||
@UseGroups,
|
||||
@UseDirectory,
|
||||
@UseEvents,
|
||||
|
@ -12,6 +12,7 @@
|
||||
@PlanType TINYINT,
|
||||
@Seats SMALLINT,
|
||||
@MaxCollections SMALLINT,
|
||||
@UsePolicies BIT,
|
||||
@UseGroups BIT,
|
||||
@UseDirectory BIT,
|
||||
@UseEvents BIT,
|
||||
@ -51,6 +52,7 @@ BEGIN
|
||||
[PlanType] = @PlanType,
|
||||
[Seats] = @Seats,
|
||||
[MaxCollections] = @MaxCollections,
|
||||
[UsePolicies] = @UsePolicies,
|
||||
[UseGroups] = @UseGroups,
|
||||
[UseDirectory] = @UseDirectory,
|
||||
[UseEvents] = @UseEvents,
|
||||
|
@ -12,6 +12,7 @@
|
||||
[PlanType] TINYINT NOT NULL,
|
||||
[Seats] SMALLINT NULL,
|
||||
[MaxCollections] SMALLINT NULL,
|
||||
[UsePolicies] BIT NOT NULL,
|
||||
[UseGroups] BIT NOT NULL,
|
||||
[UseDirectory] BIT NOT NULL,
|
||||
[UseEvents] BIT NOT NULL,
|
||||
|
Reference in New Issue
Block a user