Browse Source

Merge pull request #8736 from abpframework/enisn/rel-4.3/cms-kit/public-website

Add GetUrlOrDefaultAsync to IAppUrlProvider
pull/8737/head
Halil İbrahim Kalkan 6 years ago
committed by GitHub
parent
commit
389ff3a707
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 48
      framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/Urls/AppUrlProvider.cs
  2. 2
      framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/Urls/IAppUrlProvider.cs

48
framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/Urls/AppUrlProvider.cs

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using JetBrains.Annotations;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.MultiTenancy; using Volo.Abp.MultiTenancy;
@ -42,36 +43,24 @@ namespace Volo.Abp.UI.Navigation.Urls
return Options.RedirectAllowedUrls.Any(url.StartsWith); return Options.RedirectAllowedUrls.Any(url.StartsWith);
} }
protected virtual Task<string> GetConfiguredUrl(string appName, string urlName) protected virtual async Task<string> GetConfiguredUrl(string appName, string urlName)
{ {
var app = Options.Applications[appName]; var url = await GetUrlOrNullAsync(appName, urlName);
if (!url.IsNullOrEmpty())
if (urlName.IsNullOrEmpty())
{ {
if (app.RootUrl.IsNullOrEmpty()) return url;
{
throw new AbpException(
$"RootUrl for the application '{appName}' was not configured. Use {nameof(AppUrlOptions)} to configure it!"
);
}
return Task.FromResult(app.RootUrl);
} }
var url = app.Urls.GetOrDefault(urlName); if (!urlName.IsNullOrEmpty())
if (url.IsNullOrEmpty())
{ {
throw new AbpException( throw new AbpException(
$"Url, named '{urlName}', for the application '{appName}' was not configured. Use {nameof(AppUrlOptions)} to configure it!" $"Url, named '{urlName}', for the application '{appName}' was not configured. Use {nameof(AppUrlOptions)} to configure it!"
); );
} }
if (app.RootUrl == null) throw new AbpException(
{ $"RootUrl for the application '{appName}' was not configured. Use {nameof(AppUrlOptions)} to configure it!"
return Task.FromResult(url); );
}
return Task.FromResult(app.RootUrl.EnsureEndsWith('/') + url);
} }
protected virtual async Task<string> ReplacePlaceHoldersAsync(string url) protected virtual async Task<string> ReplacePlaceHoldersAsync(string url)
@ -118,5 +107,24 @@ namespace Volo.Abp.UI.Navigation.Urls
return CurrentTenant.Name; return CurrentTenant.Name;
} }
public Task<string> GetUrlOrNullAsync([NotNull] string appName, [CanBeNull] string urlName = null)
{
var app = Options.Applications[appName];
if (urlName.IsNullOrEmpty())
{
return Task.FromResult(app.RootUrl);
}
var url = app.Urls.GetOrDefault(urlName);
if (app.RootUrl == null)
{
return Task.FromResult(url);
}
return Task.FromResult(app.RootUrl.EnsureEndsWith('/') + url);
}
} }
} }

2
framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/Urls/IAppUrlProvider.cs

@ -7,6 +7,8 @@ namespace Volo.Abp.UI.Navigation.Urls
{ {
Task<string> GetUrlAsync([NotNull] string appName, [CanBeNull] string urlName = null); Task<string> GetUrlAsync([NotNull] string appName, [CanBeNull] string urlName = null);
Task<string> GetUrlOrNullAsync([NotNull] string appName, [CanBeNull] string urlName = null);
bool IsRedirectAllowedUrl(string url); bool IsRedirectAllowedUrl(string url);
} }
} }

Loading…
Cancel
Save