1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-05 05:00:19 -05:00

add billing info to admin edit page

This commit is contained in:
Kyle Spearrin 2019-02-25 10:39:04 -05:00
parent b229985256
commit 7ee8c0a240
9 changed files with 106 additions and 6 deletions

View File

@ -16,4 +16,10 @@
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.5" />
</ItemGroup>
<ItemGroup>
<Content Update="Views\Shared\_BillingInformation.cshtml">
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
</ItemGroup>
</Project>

View File

@ -8,6 +8,7 @@ using System.Collections.Generic;
using Bit.Core.Models.Table;
using Bit.Core;
using Bit.Core.Utilities;
using Bit.Core.Services;
namespace Bit.Admin.Controllers
{
@ -16,15 +17,18 @@ namespace Bit.Admin.Controllers
{
private readonly IOrganizationRepository _organizationRepository;
private readonly IOrganizationUserRepository _organizationUserRepository;
private readonly IPaymentService _paymentService;
private readonly GlobalSettings _globalSettings;
public OrganizationsController(
IOrganizationRepository organizationRepository,
IOrganizationUserRepository organizationUserRepository,
IPaymentService paymentService,
GlobalSettings globalSettings)
{
_organizationRepository = organizationRepository;
_organizationUserRepository = organizationUserRepository;
_paymentService = paymentService;
_globalSettings = globalSettings;
}
@ -78,7 +82,8 @@ namespace Bit.Admin.Controllers
}
var users = await _organizationUserRepository.GetManyDetailsByOrganizationAsync(id);
return View(new OrganizationEditModel(organization, users, _globalSettings));
var billingInfo = await _paymentService.GetBillingAsync(organization);
return View(new OrganizationEditModel(organization, users, billingInfo, _globalSettings));
}
[HttpPost]

View File

@ -8,6 +8,7 @@ using System.Collections.Generic;
using Bit.Core.Models.Table;
using Bit.Core;
using Bit.Core.Utilities;
using Bit.Core.Services;
namespace Bit.Admin.Controllers
{
@ -16,15 +17,18 @@ namespace Bit.Admin.Controllers
{
private readonly IUserRepository _userRepository;
private readonly ICipherRepository _cipherRepository;
private readonly IPaymentService _paymentService;
private readonly GlobalSettings _globalSettings;
public UsersController(
IUserRepository userRepository,
ICipherRepository cipherRepository,
IPaymentService paymentService,
GlobalSettings globalSettings)
{
_userRepository = userRepository;
_cipherRepository = cipherRepository;
_paymentService = paymentService;
_globalSettings = globalSettings;
}
@ -74,7 +78,8 @@ namespace Bit.Admin.Controllers
}
var ciphers = await _cipherRepository.GetManyByUserIdAsync(id);
return View(new UserEditModel(user, ciphers, _globalSettings));
var billingInfo = await _paymentService.GetBillingAsync(user);
return View(new UserEditModel(user, ciphers, billingInfo, _globalSettings));
}
[HttpPost]

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Bit.Core;
using Bit.Core.Enums;
using Bit.Core.Models.Business;
using Bit.Core.Models.Data;
using Bit.Core.Models.Table;
using Bit.Core.Utilities;
@ -14,9 +15,10 @@ namespace Bit.Admin.Models
public OrganizationEditModel() { }
public OrganizationEditModel(Organization org, IEnumerable<OrganizationUserUserDetails> orgUsers,
GlobalSettings globalSettings)
BillingInfo billingInfo, GlobalSettings globalSettings)
: base(org, orgUsers)
{
BillingInfo = billingInfo;
BraintreeMerchantId = globalSettings.Braintree.MerchantId;
Name = org.Name;
@ -42,6 +44,7 @@ namespace Bit.Admin.Models
ExpirationDate = org.ExpirationDate;
}
public BillingInfo BillingInfo { get; set; }
public string RandomLicenseKey => CoreHelpers.SecureRandomString(20);
public string FourteenDayExpirationDate => DateTime.Now.AddDays(14).ToString("yyyy-MM-ddTHH:mm");
public string BraintreeMerchantId { get; set; }

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Bit.Core.Models.Table;
namespace Bit.Admin.Models
{
public class TransactionViewModel
{
public TransactionViewModel() { }
public TransactionViewModel(User user, IEnumerable<Cipher> ciphers)
{
}
}
}

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Bit.Core;
using Bit.Core.Models.Business;
using Bit.Core.Models.Table;
using Bit.Core.Utilities;
@ -11,9 +12,11 @@ namespace Bit.Admin.Models
{
public UserEditModel() { }
public UserEditModel(User user, IEnumerable<Cipher> ciphers, GlobalSettings globalSettings)
public UserEditModel(User user, IEnumerable<Cipher> ciphers, BillingInfo billingInfo,
GlobalSettings globalSettings)
: base(user, ciphers)
{
BillingInfo = billingInfo;
BraintreeMerchantId = globalSettings.Braintree.MerchantId;
Name = user.Name;
@ -28,6 +31,7 @@ namespace Bit.Admin.Models
PremiumExpirationDate = user.PremiumExpirationDate;
}
public BillingInfo BillingInfo { get; set; }
public string RandomLicenseKey => CoreHelpers.SecureRandomString(20);
public string OneYearExpirationDate => DateTime.Now.AddYears(1).ToString("yyyy-MM-ddTHH:mm");
public string BraintreeMerchantId { get; set; }

View File

@ -74,8 +74,10 @@
<h1>Organization <small>@Model.Organization.Name</small></h1>
<h2>Information</h2>
<h2>Organization Information</h2>
@await Html.PartialAsync("_ViewInformation", Model)
<h2>Billing Information</h2>
@await Html.PartialAsync("_BillingInformation", Model.BillingInfo)
<form method="post" id="edit-form">
<h2>General</h2>
<div class="row">

View File

@ -0,0 +1,54 @@
@model Bit.Core.Models.Business.BillingInfo
<dl class="row">
<dt class="col-sm-4 col-lg-3">Account @(Model.Balance <= 0 ? "Credit" : "Balance")</dt>
<dd class="col-sm-8 col-lg-9">@Math.Abs(Model.Balance).ToString("C")</dd>
<dt class="col-sm-4 col-lg-3">Invoices</dt>
<dd class="col-sm-8 col-lg-9">
@if(Model.Invoices?.Any() ?? false)
{
<table class="table">
<tbody>
@foreach(var invoice in Model.Invoices)
{
<tr>
<td>@invoice.Date</td>
<td><a target="_blank" href="@invoice.Url" title="View Invoice">@invoice.Number</a></td>
<td>@invoice.Amount.ToString("C")</td>
<td>@(invoice.Paid ? "Paid" : "Unpaid")</td>
</tr>
}
</tbody>
</table>
}
else
{
@: No invoices.
}
</dd>
<dt class="col-sm-4 col-lg-3">Transactions</dt>
<dd class="col-sm-8 col-lg-9">
@if(Model.Transactions?.Any() ?? false)
{
<table class="table">
<tbody>
@foreach(var transaction in Model.Transactions)
{
<tr>
<td>@transaction.CreatedDate</td>
<td>@transaction.Type.ToString()</td>
<td>@transaction.PaymentMethodType.ToString()</td>
<td>@transaction.Details</td>
<td>@transaction.Amount.ToString("C")</td>
</tr>
}
</tbody>
</table>
}
else
{
@: No transactions.
}
</dd>
</dl>

View File

@ -56,8 +56,10 @@
<h1>User <small>@Model.User.Email</small></h1>
<h2>Information</h2>
<h2>User Information</h2>
@await Html.PartialAsync("_ViewInformation", Model)
<h2>Billing Information</h2>
@await Html.PartialAsync("_BillingInformation", Model.BillingInfo)
<form method="post" id="edit-form">
<h2>General</h2>
<div class="row">