Skip to content

Commit cd31c0e

Browse files
committed
Merge branch 'master' of github.com:bitwarden/server into feature/additional-item-types
2 parents 8452d04 + bbb55ef commit cd31c0e

File tree

317 files changed

+18708
-1645
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

317 files changed

+18708
-1645
lines changed

.config/dotnet-tools.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@
2727
]
2828
}
2929
}
30-
}
30+
}

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@
1616

1717
* **file.ext:** Description of what was changed and why
1818

19-
## Testing requirements
20-
<!--What functionality requires testing by QA? This includes testing new behavior and regression testing-->
21-
22-
23-
2419
## Before you submit
2520
- [ ] I have checked for formatting errors (`dotnet tool run dotnet-format --check`) (required)
2621
- [ ] If making database changes - I have also updated Entity Framework queries and/or migrations

.vscode/launch.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"Identity",
4141
"Sso",
4242
"Icons",
43+
"Billing"
4344
],
4445
"presentation": {
4546
"hidden": false,
@@ -125,6 +126,28 @@
125126
"/Views": "${workspaceFolder}/Views"
126127
}
127128
},
129+
{
130+
"name": "Billing",
131+
"presentation": {
132+
"hidden": false,
133+
"group": "cloud",
134+
"order": 10
135+
},
136+
"requireExactSource": true,
137+
"type": "coreclr",
138+
"request": "launch",
139+
"preLaunchTask": "buildBilling",
140+
"program": "${workspaceFolder}/src/Billing/bin/Debug/net5.0/Billing.dll",
141+
"args": [],
142+
"cwd": "${workspaceFolder}/src/Billing",
143+
"stopAtEntry": false,
144+
"env": {
145+
"ASPNETCORE_ENVIRONMENT": "Development"
146+
},
147+
"sourceFileMap": {
148+
"/Views": "${workspaceFolder}/Views"
149+
}
150+
},
128151
{
129152
"name": "Admin",
130153
"presentation": {

.vscode/tasks.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,22 @@
8989
"isDefault": true
9090
}
9191
},
92+
{
93+
"label": "buildBilling",
94+
"command": "dotnet",
95+
"type": "process",
96+
"args": [
97+
"build",
98+
"${workspaceFolder}/src/Billing/Billing.csproj",
99+
"/property:GenerateFullPaths=true",
100+
"/consoleloggerparameters:NoSummary"
101+
],
102+
"problemMatcher": "$msCompile",
103+
"group": {
104+
"kind": "build",
105+
"isDefault": true
106+
}
107+
},
92108
{
93109
"label": "clean",
94110
"type": "shell",

bitwarden_license/src/Sso/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void ConfigureServices(IServiceCollection services)
7878
services.AddCustomIdentityServices(globalSettings);
7979

8080
// Services
81-
services.AddBaseServices();
81+
services.AddBaseServices(globalSettings);
8282
services.AddDefaultServices(globalSettings);
8383
services.AddCoreLocalizationServices();
8484
}

bitwarden_license/test/CmmCore.Test/packages.lock.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,15 @@
298298
"IdentityModel": "4.3.0"
299299
}
300300
},
301+
"Kralizek.AutoFixture.Extensions.MockHttp": {
302+
"type": "Transitive",
303+
"resolved": "1.2.0",
304+
"contentHash": "6zmks7/5mVczazv910N7V2EdiU6B+rY61lwdgVO0o2iZuTI6KI3T+Hgkrjv0eGOKYucq2OMC+gnAc5Ej2ajoTQ==",
305+
"dependencies": {
306+
"AutoFixture": "4.11.0",
307+
"RichardSzalay.MockHttp": "6.0.0"
308+
}
309+
},
301310
"libsodium": {
302311
"type": "Transitive",
303312
"resolved": "1.0.18",
@@ -1598,6 +1607,11 @@
15981607
"System.Diagnostics.DiagnosticSource": "4.7.1"
15991608
}
16001609
},
1610+
"RichardSzalay.MockHttp": {
1611+
"type": "Transitive",
1612+
"resolved": "6.0.0",
1613+
"contentHash": "bStGNqIX/MGYtML7K3EzdsE/k5HGVAcg7XgN23TQXGXqxNC9fvYFR94fA0sGM5hAT36R+BBGet6ZDQxXL/IPxg=="
1614+
},
16011615
"runtime.debian.8-x64.runtime.native.System.Security.Cryptography.OpenSsl": {
16021616
"type": "Transitive",
16031617
"resolved": "4.3.2",
@@ -3547,6 +3561,7 @@
35473561
"AutoFixture.AutoNSubstitute": "4.14.0",
35483562
"AutoFixture.Xunit2": "4.14.0",
35493563
"Core": "1.47.1",
3564+
"Kralizek.AutoFixture.Extensions.MockHttp": "1.2.0",
35503565
"Microsoft.NET.Test.Sdk": "16.6.1",
35513566
"NSubstitute": "4.2.2",
35523567
"xunit": "2.4.1"
@@ -3599,6 +3614,7 @@
35993614
"AutoFixture.Xunit2": "4.14.0",
36003615
"Common": "1.47.1",
36013616
"Core": "1.47.1",
3617+
"Kralizek.AutoFixture.Extensions.MockHttp": "1.2.0",
36023618
"Microsoft.NET.Test.Sdk": "16.6.1",
36033619
"Moq": "4.16.1",
36043620
"NSubstitute": "4.2.2",

src/Admin/Controllers/OrganizationsController.cs

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using System.Threading.Tasks;
45
using Bit.Admin.Models;
56
using Bit.Core.Entities;
67
using Bit.Core.Enums;
78
using Bit.Core.Models.Business;
9+
using Bit.Core.Models.OrganizationConnectionConfigs;
10+
using Bit.Core.OrganizationFeatures.OrganizationSponsorships.FamiliesForEnterprise.Interfaces;
811
using Bit.Core.Repositories;
912
using Bit.Core.Services;
1013
using Bit.Core.Settings;
@@ -19,11 +22,14 @@ public class OrganizationsController : Controller
1922
{
2023
private readonly IOrganizationRepository _organizationRepository;
2124
private readonly IOrganizationUserRepository _organizationUserRepository;
25+
private readonly IOrganizationConnectionRepository _organizationConnectionRepository;
26+
private readonly ISelfHostedSyncSponsorshipsCommand _syncSponsorshipsCommand;
2227
private readonly ICipherRepository _cipherRepository;
2328
private readonly ICollectionRepository _collectionRepository;
2429
private readonly IGroupRepository _groupRepository;
2530
private readonly IPolicyRepository _policyRepository;
2631
private readonly IPaymentService _paymentService;
32+
private readonly ILicensingService _licensingService;
2733
private readonly IApplicationCacheService _applicationCacheService;
2834
private readonly GlobalSettings _globalSettings;
2935
private readonly IReferenceEventService _referenceEventService;
@@ -32,23 +38,29 @@ public class OrganizationsController : Controller
3238
public OrganizationsController(
3339
IOrganizationRepository organizationRepository,
3440
IOrganizationUserRepository organizationUserRepository,
41+
IOrganizationConnectionRepository organizationConnectionRepository,
42+
ISelfHostedSyncSponsorshipsCommand syncSponsorshipsCommand,
3543
ICipherRepository cipherRepository,
3644
ICollectionRepository collectionRepository,
3745
IGroupRepository groupRepository,
3846
IPolicyRepository policyRepository,
3947
IPaymentService paymentService,
48+
ILicensingService licensingService,
4049
IApplicationCacheService applicationCacheService,
4150
GlobalSettings globalSettings,
4251
IReferenceEventService referenceEventService,
4352
IUserService userService)
4453
{
4554
_organizationRepository = organizationRepository;
4655
_organizationUserRepository = organizationUserRepository;
56+
_organizationConnectionRepository = organizationConnectionRepository;
57+
_syncSponsorshipsCommand = syncSponsorshipsCommand;
4758
_cipherRepository = cipherRepository;
4859
_collectionRepository = collectionRepository;
4960
_groupRepository = groupRepository;
5061
_policyRepository = policyRepository;
5162
_paymentService = paymentService;
63+
_licensingService = licensingService;
5264
_applicationCacheService = applicationCacheService;
5365
_globalSettings = globalSettings;
5466
_referenceEventService = referenceEventService;
@@ -104,7 +116,8 @@ public async Task<IActionResult> View(Guid id)
104116
policies = await _policyRepository.GetManyByOrganizationIdAsync(id);
105117
}
106118
var users = await _organizationUserRepository.GetManyDetailsByOrganizationAsync(id);
107-
return View(new OrganizationViewModel(organization, users, ciphers, collections, groups, policies));
119+
var billingSyncConnection = _globalSettings.EnableCloudCommunication ? await _organizationConnectionRepository.GetByOrganizationIdTypeAsync(id, OrganizationConnectionType.CloudBillingSync) : null;
120+
return View(new OrganizationViewModel(organization, billingSyncConnection, users, ciphers, collections, groups, policies));
108121
}
109122

110123
[SelfHosted(NotSelfHostedOnly = true)]
@@ -130,8 +143,9 @@ public async Task<IActionResult> Edit(Guid id)
130143
}
131144
var users = await _organizationUserRepository.GetManyDetailsByOrganizationAsync(id);
132145
var billingInfo = await _paymentService.GetBillingAsync(organization);
146+
var billingSyncConnection = _globalSettings.EnableCloudCommunication ? await _organizationConnectionRepository.GetByOrganizationIdTypeAsync(id, OrganizationConnectionType.CloudBillingSync) : null;
133147
return View(new OrganizationEditModel(organization, users, ciphers, collections, groups, policies,
134-
billingInfo, _globalSettings));
148+
billingInfo, billingSyncConnection, _globalSettings));
135149
}
136150

137151
[HttpPost]
@@ -164,5 +178,40 @@ public async Task<IActionResult> Delete(Guid id)
164178

165179
return RedirectToAction("Index");
166180
}
181+
182+
public async Task<IActionResult> TriggerBillingSync(Guid id)
183+
{
184+
var organization = await _organizationRepository.GetByIdAsync(id);
185+
if (organization == null)
186+
{
187+
return RedirectToAction("Index");
188+
}
189+
var connection = (await _organizationConnectionRepository.GetEnabledByOrganizationIdTypeAsync(id, OrganizationConnectionType.CloudBillingSync)).FirstOrDefault();
190+
if (connection != null)
191+
{
192+
try
193+
{
194+
var config = connection.GetConfig<BillingSyncConfig>();
195+
await _syncSponsorshipsCommand.SyncOrganization(id, config.CloudOrganizationId, connection);
196+
TempData["ConnectionActivated"] = id;
197+
TempData["ConnectionError"] = null;
198+
}
199+
catch (Exception ex)
200+
{
201+
TempData["ConnectionError"] = ex.Message;
202+
}
203+
204+
if (_globalSettings.SelfHosted)
205+
{
206+
return RedirectToAction("View", new { id });
207+
}
208+
else
209+
{
210+
return RedirectToAction("Edit", new { id });
211+
}
212+
}
213+
return RedirectToAction("Index");
214+
}
215+
167216
}
168217
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using Bit.Core;
4+
using Bit.Core.Jobs;
5+
using Bit.Core.Repositories;
6+
using Bit.Core.Settings;
7+
using Microsoft.Extensions.Logging;
8+
using Quartz;
9+
10+
namespace Bit.Admin.Jobs
11+
{
12+
public class DatabaseExpiredSponsorshipsJob : BaseJob
13+
{
14+
private GlobalSettings _globalSettings;
15+
private readonly IMaintenanceRepository _maintenanceRepository;
16+
17+
public DatabaseExpiredSponsorshipsJob(
18+
IMaintenanceRepository maintenanceRepository,
19+
ILogger<DatabaseExpiredSponsorshipsJob> logger,
20+
GlobalSettings globalSettings)
21+
: base(logger)
22+
{
23+
_maintenanceRepository = maintenanceRepository;
24+
_globalSettings = globalSettings;
25+
}
26+
27+
protected override async Task ExecuteJobAsync(IJobExecutionContext context)
28+
{
29+
if (_globalSettings.SelfHosted && !_globalSettings.EnableCloudCommunication)
30+
{
31+
return;
32+
}
33+
_logger.LogInformation(Constants.BypassFiltersEventId, "Execute job task: DeleteExpiredSponsorshipsAsync");
34+
35+
// allow a 90 day grace period before deleting
36+
var deleteDate = DateTime.UtcNow.AddDays(-90);
37+
38+
await _maintenanceRepository.DeleteExpiredSponsorshipsAsync(deleteDate);
39+
_logger.LogInformation(Constants.BypassFiltersEventId, "Finished job task: DeleteExpiredSponsorshipsAsync");
40+
}
41+
}
42+
}

src/Admin/Jobs/JobsHostedService.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ public override async Task StartAsync(CancellationToken cancellationToken)
5555
.StartNow()
5656
.WithCronSchedule("0 0 0 ? * SUN", x => x.InTimeZone(timeZone))
5757
.Build();
58+
var everyMondayAtMidnightTrigger = TriggerBuilder.Create()
59+
.WithIdentity("EveryMondayAtMidnightTrigger")
60+
.StartNow()
61+
.WithCronSchedule("0 0 0 ? * MON", x => x.InTimeZone(timeZone))
62+
.Build();
5863
var everyDayAtMidnightUtc = TriggerBuilder.Create()
5964
.WithIdentity("EveryDayAtMidnightUtc")
6065
.StartNow()
@@ -67,7 +72,8 @@ public override async Task StartAsync(CancellationToken cancellationToken)
6772
new Tuple<Type, ITrigger>(typeof(DatabaseExpiredGrantsJob), everyFridayAt10pmTrigger),
6873
new Tuple<Type, ITrigger>(typeof(DatabaseUpdateStatisticsJob), everySaturdayAtMidnightTrigger),
6974
new Tuple<Type, ITrigger>(typeof(DatabaseRebuildlIndexesJob), everySundayAtMidnightTrigger),
70-
new Tuple<Type, ITrigger>(typeof(DeleteCiphersJob), everyDayAtMidnightUtc)
75+
new Tuple<Type, ITrigger>(typeof(DeleteCiphersJob), everyDayAtMidnightUtc),
76+
new Tuple<Type, ITrigger>(typeof(DatabaseExpiredSponsorshipsJob), everyMondayAtMidnightTrigger)
7177
};
7278

7379
if (!_globalSettings.SelfHosted)
@@ -88,6 +94,7 @@ public static void AddJobsServices(IServiceCollection services, bool selfHosted)
8894
services.AddTransient<DatabaseUpdateStatisticsJob>();
8995
services.AddTransient<DatabaseRebuildlIndexesJob>();
9096
services.AddTransient<DatabaseExpiredGrantsJob>();
97+
services.AddTransient<DatabaseExpiredSponsorshipsJob>();
9198
services.AddTransient<DeleteSendsJob>();
9299
services.AddTransient<DeleteCiphersJob>();
93100
}

src/Admin/Models/OrganizationEditModel.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using Bit.Core.Entities;
55
using Bit.Core.Enums;
66
using Bit.Core.Models.Business;
7-
using Bit.Core.Models.Data;
7+
using Bit.Core.Models.Data.Organizations.OrganizationUsers;
88
using Bit.Core.Settings;
99
using Bit.Core.Utilities;
1010

@@ -16,8 +16,9 @@ public OrganizationEditModel() { }
1616

1717
public OrganizationEditModel(Organization org, IEnumerable<OrganizationUserUserDetails> orgUsers,
1818
IEnumerable<Cipher> ciphers, IEnumerable<Collection> collections, IEnumerable<Group> groups,
19-
IEnumerable<Policy> policies, BillingInfo billingInfo, GlobalSettings globalSettings)
20-
: base(org, orgUsers, ciphers, collections, groups, policies)
19+
IEnumerable<Policy> policies, BillingInfo billingInfo, IEnumerable<OrganizationConnection> connections,
20+
GlobalSettings globalSettings)
21+
: base(org, connections, orgUsers, ciphers, collections, groups, policies)
2122
{
2223
BillingInfo = billingInfo;
2324
BraintreeMerchantId = globalSettings.Braintree.MerchantId;

0 commit comments

Comments
 (0)