From d18fe804e868a71a4a638d6973a25a3cd62ed5fb Mon Sep 17 00:00:00 2001 From: Halil ibrahim Kalkan Date: Tue, 26 Mar 2019 15:43:19 +0300 Subject: [PATCH] Remove TenantSwitchViewComponent. Refactor tenant selection --- .../DomainTenantResolveContributor.cs | 12 +++-- .../Pages/Abp/MultiTenancy/tenant-switch.js | 2 +- ....Abp.AspNetCore.Mvc.UI.MultiTenancy.csproj | 2 - .../AbpAspNetCoreMvcUiMultiTenancyModule.cs | 9 +--- .../Components/TenantSwitch/Default.cshtml | 17 ------- .../TenantSwitch/TenantSwitchViewComponent.cs | 51 ------------------- .../Components/_ViewImports.cshtml | 3 -- .../Mvc/UI/MultiTenancy/Localization/en.json | 8 +-- .../Mvc/UI/MultiTenancy/Localization/tr.json | 6 ++- .../MultiTenancyToolbarContributor.cs | 21 -------- ...ClaimsPrincipalTenantResolveContributor.cs | 5 +- 11 files changed, 24 insertions(+), 112 deletions(-) delete mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Volo/Abp/AspNetCore/Mvc/UI/MultiTenancy/Components/TenantSwitch/Default.cshtml delete mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Volo/Abp/AspNetCore/Mvc/UI/MultiTenancy/Components/TenantSwitch/TenantSwitchViewComponent.cs delete mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Volo/Abp/AspNetCore/Mvc/UI/MultiTenancy/Components/_ViewImports.cshtml delete mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Volo/Abp/AspNetCore/Mvc/UI/MultiTenancy/MultiTenancyToolbarContributor.cs diff --git a/framework/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/DomainTenantResolveContributor.cs b/framework/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/DomainTenantResolveContributor.cs index e342cb8f40..61d47abcfd 100644 --- a/framework/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/DomainTenantResolveContributor.cs +++ b/framework/src/Volo.Abp.AspNetCore.MultiTenancy/Volo/Abp/AspNetCore/MultiTenancy/DomainTenantResolveContributor.cs @@ -9,23 +9,29 @@ namespace Volo.Abp.AspNetCore.MultiTenancy public class DomainTenantResolveContributor : HttpTenantResolveContributorBase { + private static readonly string[] ProtocolPrefixes = { "http://", "https://" }; + private readonly string _domainFormat; public DomainTenantResolveContributor(string domainFormat) { - _domainFormat = domainFormat.RemovePreFix("http://", "https://"); + _domainFormat = domainFormat.RemovePreFix(ProtocolPrefixes); } - protected override string GetTenantIdOrNameFromHttpContextOrNull(ITenantResolveContext context, HttpContext httpContext) + protected override string GetTenantIdOrNameFromHttpContextOrNull( + ITenantResolveContext context, + HttpContext httpContext) { if (httpContext.Request?.Host == null) { return null; } - var hostName = httpContext.Request.Host.Host.RemovePreFix("http://", "https://"); + var hostName = httpContext.Request.Host.Host.RemovePreFix(ProtocolPrefixes); var extractResult = FormattedStringValueExtracter.Extract(hostName, _domainFormat, ignoreCase: true); + context.Handled = true; + if (!extractResult.IsMatch) { return null; diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Pages/Abp/MultiTenancy/tenant-switch.js b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Pages/Abp/MultiTenancy/tenant-switch.js index 57a01a3740..6b9e348f1d 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Pages/Abp/MultiTenancy/tenant-switch.js +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Pages/Abp/MultiTenancy/tenant-switch.js @@ -3,7 +3,7 @@ var tenantSwitchModal = new abp.ModalManager(abp.appPath + 'Abp/MultiTenancy/TenantSwitchModal'); $(function() { - $('#TenantSwitchToolbarLink').click(function(e) { + $('#AbpTenantSwitchLink').click(function(e) { e.preventDefault(); tenantSwitchModal.open(); }); diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy.csproj b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy.csproj index f8bbf69c9a..d0015b0e57 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy.csproj +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy.csproj @@ -18,11 +18,9 @@ - - diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Volo/Abp/AspNetCore/Mvc/UI/MultiTenancy/AbpAspNetCoreMvcUiMultiTenancyModule.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Volo/Abp/AspNetCore/Mvc/UI/MultiTenancy/AbpAspNetCoreMvcUiMultiTenancyModule.cs index 13b58dd32d..484bd657d9 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Volo/Abp/AspNetCore/Mvc/UI/MultiTenancy/AbpAspNetCoreMvcUiMultiTenancyModule.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Volo/Abp/AspNetCore/Mvc/UI/MultiTenancy/AbpAspNetCoreMvcUiMultiTenancyModule.cs @@ -1,11 +1,9 @@ -using Microsoft.Extensions.DependencyInjection; -using Volo.Abp.AspNetCore.MultiTenancy; +using Volo.Abp.AspNetCore.MultiTenancy; using Volo.Abp.AspNetCore.Mvc.Localization; using Volo.Abp.AspNetCore.Mvc.UI.Bundling; using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy.Localization; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared; using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Bundling; -using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Toolbars; using Volo.Abp.Localization; using Volo.Abp.Modularity; using Volo.Abp.VirtualFileSystem; @@ -36,11 +34,6 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy options.FileSets.AddEmbedded(); }); - Configure(options => - { - options.Contributors.Add(new MultiTenancyToolbarContributor()); - }); - Configure(options => { options.Resources diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Volo/Abp/AspNetCore/Mvc/UI/MultiTenancy/Components/TenantSwitch/Default.cshtml b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Volo/Abp/AspNetCore/Mvc/UI/MultiTenancy/Components/TenantSwitch/Default.cshtml deleted file mode 100644 index 515d4cc7dc..0000000000 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Volo/Abp/AspNetCore/Mvc/UI/MultiTenancy/Components/TenantSwitch/Default.cshtml +++ /dev/null @@ -1,17 +0,0 @@ -@using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy.Components.TenantSwitch -@model TenantSwitchViewComponent.TenantSwitchViewModel -@if (!Model.CurrentUser.IsAuthenticated) -{ - -} \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Volo/Abp/AspNetCore/Mvc/UI/MultiTenancy/Components/TenantSwitch/TenantSwitchViewComponent.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Volo/Abp/AspNetCore/Mvc/UI/MultiTenancy/Components/TenantSwitch/TenantSwitchViewComponent.cs deleted file mode 100644 index f17a066c57..0000000000 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Volo/Abp/AspNetCore/Mvc/UI/MultiTenancy/Components/TenantSwitch/TenantSwitchViewComponent.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Volo.Abp.MultiTenancy; -using Volo.Abp.Users; - -namespace Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy.Components.TenantSwitch -{ - public class TenantSwitchViewComponent : AbpViewComponent - { - /// - /// -1,000,000 - /// - public const int Order = -1_000_000; - - protected ITenantStore TenantStore { get; } - protected ICurrentTenant CurrentTenant { get; } - protected ICurrentUser CurrentUser { get; } - - public TenantSwitchViewComponent( - ITenantStore tenantStore, - ICurrentTenant currentTenant, - ICurrentUser currentUser) - { - TenantStore = tenantStore; - CurrentTenant = currentTenant; - CurrentUser = currentUser; - } - - public async Task InvokeAsync() - { - var model = new TenantSwitchViewModel - { - CurrentUser = CurrentUser - }; - - if (CurrentTenant.Id.HasValue) - { - model.Tenant = await TenantStore.FindAsync(CurrentTenant.GetId()); - } - - return View("~/Volo/Abp/AspNetCore/Mvc/UI/MultiTenancy/Components/TenantSwitch/Default.cshtml", model); - } - - public class TenantSwitchViewModel - { - public TenantConfiguration Tenant { get; set; } - - public ICurrentUser CurrentUser { get; set; } - } - } -} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Volo/Abp/AspNetCore/Mvc/UI/MultiTenancy/Components/_ViewImports.cshtml b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Volo/Abp/AspNetCore/Mvc/UI/MultiTenancy/Components/_ViewImports.cshtml deleted file mode 100644 index 225780c2c2..0000000000 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Volo/Abp/AspNetCore/Mvc/UI/MultiTenancy/Components/_ViewImports.cshtml +++ /dev/null @@ -1,3 +0,0 @@ -@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers -@addTagHelper *, Volo.Abp.AspNetCore.Mvc.UI.Bootstrap -@addTagHelper *, Volo.Abp.AspNetCore.Mvc.UI.Bundling \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Volo/Abp/AspNetCore/Mvc/UI/MultiTenancy/Localization/en.json b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Volo/Abp/AspNetCore/Mvc/UI/MultiTenancy/Localization/en.json index 2f19b5eb1f..a934bc87b0 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Volo/Abp/AspNetCore/Mvc/UI/MultiTenancy/Localization/en.json +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Volo/Abp/AspNetCore/Mvc/UI/MultiTenancy/Localization/en.json @@ -1,9 +1,11 @@ -{ +{ "culture": "en", "texts": { "GivenTenantIsNotAvailable": "Given tenant is not available: {0}", - "SwitchTenant": "Switch tenant", + "Tenant": "Tenant", + "Switch": "Switch", "Name": "Name", - "SwitchTenantHint": "Leave the name field blank to switch to the host side." + "SwitchTenantHint": "Leave the name field blank to switch to the host side.", + "NotSelected": "Seçili değil" } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Volo/Abp/AspNetCore/Mvc/UI/MultiTenancy/Localization/tr.json b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Volo/Abp/AspNetCore/Mvc/UI/MultiTenancy/Localization/tr.json index 5bbd020497..93cf964f6f 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Volo/Abp/AspNetCore/Mvc/UI/MultiTenancy/Localization/tr.json +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Volo/Abp/AspNetCore/Mvc/UI/MultiTenancy/Localization/tr.json @@ -2,8 +2,10 @@ "culture": "tr", "texts": { "GivenTenantIsNotAvailable": "İstenilen müşteri bulunamadı: {0}", - "SwitchTenant": "Müşteri değiştir", + "Tenant": "Müşteri", + "Switch": "Değiştir", "Name": "İsim", - "SwitchTenantHint": "Host tarafına geçmek için isim alanını boş bırakın." + "SwitchTenantHint": "Host tarafına geçmek için isim alanını boş bırakın.", + "NotSelected": "Not selected" } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Volo/Abp/AspNetCore/Mvc/UI/MultiTenancy/MultiTenancyToolbarContributor.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Volo/Abp/AspNetCore/Mvc/UI/MultiTenancy/MultiTenancyToolbarContributor.cs deleted file mode 100644 index d6a6f54b61..0000000000 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy/Volo/Abp/AspNetCore/Mvc/UI/MultiTenancy/MultiTenancyToolbarContributor.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.Threading.Tasks; -using Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy.Components.TenantSwitch; -using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Toolbars; - -namespace Volo.Abp.AspNetCore.Mvc.UI.MultiTenancy -{ - public class MultiTenancyToolbarContributor : IToolbarContributor - { - public Task ConfigureToolbarAsync(IToolbarConfigurationContext context) - { - if (context.Toolbar.Name != StandardToolbars.Main) - { - return Task.CompletedTask; - } - - context.Toolbar.Items.Add(new ToolbarItem(typeof(TenantSwitchViewComponent), TenantSwitchViewComponent.Order)); - - return Task.CompletedTask; - } - } -} diff --git a/framework/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/CurrentClaimsPrincipalTenantResolveContributor.cs b/framework/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/CurrentClaimsPrincipalTenantResolveContributor.cs index 4a2709129a..425f6dcc1b 100644 --- a/framework/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/CurrentClaimsPrincipalTenantResolveContributor.cs +++ b/framework/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/CurrentClaimsPrincipalTenantResolveContributor.cs @@ -14,8 +14,11 @@ namespace Volo.Abp.MultiTenancy return; } - context.TenantIdOrName = principal.Claims.FirstOrDefault(c => c.Type == AbpClaimTypes.TenantId)?.Value; context.Handled = true; + context.TenantIdOrName = principal + .Claims + .FirstOrDefault(c => c.Type == AbpClaimTypes.TenantId) + ?.Value; } } } \ No newline at end of file