fix #935 Basic connection string management for tenants.

pull/1002/head
maliming 7 years ago
parent 33f9424a09
commit c46307907b

@ -1,10 +1,16 @@
using System;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
namespace Volo.Abp.TenantManagement
{
public interface ITenantAppService : IAsyncCrudAppService<TenantDto, Guid, GetTenantsInput, TenantCreateDto, TenantUpdateDto>
{
//TODO: Manage connection strings
Task<string> GetDefaultConnectionStringAsync(Guid id);
Task SetDefaultConnectionStringAsync(Guid id, string defaultConnectionString);
Task RemoveDefaultConnectionStringAsync(Guid id);
}
}

@ -79,5 +79,23 @@ namespace Volo.Abp.TenantManagement
await TenantRepository.DeleteAsync(tenant);
}
public async Task<string> GetDefaultConnectionStringAsync(Guid id)
{
var tenant = await TenantRepository.GetAsync(id);
return tenant?.FindDefaultConnectionString();
}
public async Task SetDefaultConnectionStringAsync(Guid id, string defaultConnectionString)
{
var tenant = await TenantRepository.GetAsync(id);
tenant.SetDefaultConnectionString(defaultConnectionString);
}
public async Task RemoveDefaultConnectionStringAsync(Guid id)
{
var tenant = await TenantRepository.GetAsync(id);
tenant.RemoveDefaultConnectionString();
}
}
}

@ -32,6 +32,33 @@ namespace Volo.Abp.TenantManagement
return FindConnectionString(Data.ConnectionStrings.DefaultConnectionStringName);
}
public virtual void SetDefaultConnectionString(string defaultConnectionString)
{
var defaultConnectionStringName =
ConnectionStrings.FirstOrDefault(x => x.Name == Data.ConnectionStrings.DefaultConnectionStringName);
if (defaultConnectionStringName != null)
{
defaultConnectionStringName.SetValue(defaultConnectionString);
}
else
{
ConnectionStrings.Add(new TenantConnectionString(Id, Data.ConnectionStrings.DefaultConnectionStringName,
defaultConnectionString));
}
}
public virtual void RemoveDefaultConnectionString()
{
var defaultConnectionStringName =
ConnectionStrings.FirstOrDefault(x => x.Name == Data.ConnectionStrings.DefaultConnectionStringName);
if (defaultConnectionStringName != null)
{
ConnectionStrings.Remove(defaultConnectionStringName);
}
}
[CanBeNull]
public virtual string FindConnectionString(string name)
{

@ -42,5 +42,21 @@ namespace Volo.Abp.TenantManagement
{
return _service.DeleteAsync(id);
}
[HttpPost]
public Task<string> GetDefaultConnectionStringAsync(Guid id)
{
return _service.GetDefaultConnectionStringAsync(id);
}
public Task SetDefaultConnectionStringAsync(Guid id, string defaultConnectionString)
{
return _service.SetDefaultConnectionStringAsync(id, defaultConnectionString);
}
public Task RemoveDefaultConnectionStringAsync(Guid id)
{
return _service.RemoveDefaultConnectionStringAsync(id);
}
}
}

@ -6,6 +6,9 @@
"NewTenant": "New tenant",
"TenantName": "Tenant name",
"DisplayName:TenantName": "Tenant name",
"TenantDeletionConfirmationMessage": "Tenant '{0}' will be deleted. Do you confirm that?"
"TenantDeletionConfirmationMessage": "Tenant '{0}' will be deleted. Do you confirm that?",
"ConnectionStrings": "Connection Strings",
"DisplayName:DefaultConnectionString": "Default Connection String",
"DisplayName:UseSharedDatabase": "Use the Shared Database"
}
}

@ -6,6 +6,9 @@
"NewTenant": "Novo Inquilino",
"TenantName": "Inquilino",
"DisplayName:TenantName": "Inquilino",
"TenantDeletionConfirmationMessage": "Inquilino '{0}' será excluído. Tem certeza?"
"TenantDeletionConfirmationMessage": "Inquilino '{0}' será excluído. Tem certeza?",
"ConnectionStrings": "Cordas de Conexão",
"DisplayName:DefaultConnectionString": "String de Conexão Padrão",
"DisplayName:UseSharedDatabase": "Use o banco de dados compartilhado"
}
}

@ -6,6 +6,9 @@
"NewTenant": "Yeni müşteri",
"TenantName": "Müşteri adı",
"DisplayName:TenantName": "Müşteri adı",
"TenantDeletionConfirmationMessage": "'{0}' isimli müşteri silinecektir. Onaylıyor musunuz?"
"TenantDeletionConfirmationMessage": "'{0}' isimli müşteri silinecektir. Onaylıyor musunuz?",
"ConnectionStrings": "Bağlantı dizeleri",
"DisplayName:DefaultConnectionString": "Varsayılan Bağlantı Dize",
"DisplayName:UseSharedDatabase": "Paylaşılan Veritabanını kullanın"
}
}

@ -1,11 +1,14 @@
{
"culture": "zh-Hans",
"texts": {
"Menu:TenantManagement": "租户管理",
"Tenants": "租户",
"NewTenant": "新租户",
"TenantName": "租户名称",
"DisplayName:TenantName": "租户名称",
"TenantDeletionConfirmationMessage": "租户 '{0}' 将被删除. 你确定吗?"
}
}
"culture": "zh-Hans",
"texts": {
"Menu:TenantManagement": "租户管理",
"Tenants": "租户",
"NewTenant": "新租户",
"TenantName": "租户名称",
"DisplayName:TenantName": "租户名称",
"TenantDeletionConfirmationMessage": "租户 '{0}' 将被删除. 你确定吗?",
"ConnectionStrings": "连接字符串",
"DisplayName:DefaultConnectionString": "默认连接字符串",
"DisplayName:UseSharedDatabase": "使用共享数据库"
}
}

@ -0,0 +1,35 @@
@page
@using Microsoft.Extensions.Localization
@using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Modal
@using Volo.Abp.TenantManagement.Localization
@using Volo.Abp.TenantManagement.Web.Pages.TenantManagement.Tenants
@model ConnectionStringsModal
@inject IStringLocalizer<AbpTenantManagementResource> L
@{
Layout = null;
}
<form method="post" asp-page="/TenantManagement/Tenants/ConnectionStringsModal">
<abp-modal>
<abp-modal-header title="@L["ConnectionStrings"]"></abp-modal-header>
<abp-modal-body>
<abp-input asp-for="Tenant.Id"></abp-input>
<abp-input asp-for="Tenant.UseSharedDatabase"></abp-input>
<div id="Tenant_DefaultConnectionString_Wrap" class="@(Model.Tenant.UseSharedDatabase ? "d-none" : "")" >
<abp-input asp-for="Tenant.DefaultConnectionString"></abp-input>
</div>
</abp-modal-body>
<abp-modal-footer buttons="@(AbpModalButtons.Cancel|AbpModalButtons.Save)"></abp-modal-footer>
</abp-modal>
</form>
<script>
$("#Tenant_UseSharedDatabase").change(function() {
$("#Tenant_DefaultConnectionString_Wrap").toggleClass("d-none");
$(this).val($(this).prop("checked"));
});
</script>

@ -0,0 +1,62 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc.UI.RazorPages;
namespace Volo.Abp.TenantManagement.Web.Pages.TenantManagement.Tenants
{
public class ConnectionStringsModal : AbpPageModel
{
[BindProperty]
public TenantInfoModel Tenant { get; set; }
private readonly ITenantAppService _tenantAppService;
public ConnectionStringsModal(ITenantAppService tenantAppService)
{
_tenantAppService = tenantAppService;
}
public async Task OnGetAsync(Guid id)
{
var defaultConnectionString = await _tenantAppService.GetDefaultConnectionStringAsync(id);
Tenant = new TenantInfoModel()
{
Id = id,
DefaultConnectionString = defaultConnectionString,
UseSharedDatabase = defaultConnectionString.IsNullOrWhiteSpace()
};
}
public async Task<IActionResult> OnPostAsync()
{
ValidateModel();
if (Tenant.UseSharedDatabase || Tenant.DefaultConnectionString.IsNullOrWhiteSpace())
{
await _tenantAppService.RemoveDefaultConnectionStringAsync(Tenant.Id);
}
else
{
await _tenantAppService.SetDefaultConnectionStringAsync(Tenant.Id, Tenant.DefaultConnectionString);
}
return NoContent();
}
public class TenantInfoModel
{
[HiddenInput]
public Guid Id { get; set; }
[Display(Name = "DisplayName:UseSharedDatabase")]
public bool UseSharedDatabase { get; set; }
[StringLength(TenantConnectionStringConsts.MaxNameLength)]
[Display(Name = "DisplayName:DefaultConnectionString")]
public string DefaultConnectionString { get; set; }
}
}
}

@ -1,9 +1,10 @@
(function () {
(function () {
var l = abp.localization.getResource('AbpTenantManagement');
var _tenantAppService = volo.abp.tenantManagement.tenant;
var _editModal = new abp.ModalManager(abp.appPath + 'TenantManagement/Tenants/EditModal');
var _connectionStringsModal = new abp.ModalManager(abp.appPath + 'TenantManagement/Tenants/ConnectionStringsModal');
var _createModal = new abp.ModalManager(abp.appPath + 'TenantManagement/Tenants/CreateModal');
var _featuresModal = new abp.ModalManager(abp.appPath + 'FeatureManagement/FeatureManagementModal');
@ -28,6 +29,17 @@
});
}
},
{
text: l('ConnectionStrings'),
visible: function () {
return true; //TODO: Check permission
},
action: function (data) {
_connectionStringsModal.open({
id: data.record.id
});
}
},
{
text: l('Features'),
visible: function () {

Loading…
Cancel
Save