Merge pull request #3917 from sbwalker/dev
fix page Path so it supports the specification of external Urls, querystrings, and anchors
This commit is contained in:
commit
75b9a8a826
|
@ -256,8 +256,9 @@
|
|||
{
|
||||
_pageId = Int32.Parse(PageState.QueryString["id"]);
|
||||
_parent = await PageService.GetPageAsync(_pageId);
|
||||
if (_parent != null)
|
||||
if (_parent != null && !UserSecurity.IsAuthorized(PageState.User, RoleNames.Admin))
|
||||
{
|
||||
// non-admins are authorized to create child pages of current page
|
||||
_parentid = _parent.PageId.ToString();
|
||||
}
|
||||
}
|
||||
|
@ -375,10 +376,18 @@
|
|||
page.SiteId = PageState.Page.SiteId;
|
||||
page.Name = _name;
|
||||
|
||||
// path can be a link to an external url
|
||||
if (!_path.Contains("://"))
|
||||
{
|
||||
if (string.IsNullOrEmpty(_path))
|
||||
{
|
||||
_path = _name;
|
||||
}
|
||||
|
||||
var fragment = (_path.Contains("?")) ? _path.Substring(_path.IndexOf("?")) : "";
|
||||
fragment = (_path.Contains("#")) ? _path.Substring(_path.IndexOf("#")) : "";
|
||||
_path = (!string.IsNullOrEmpty(fragment)) ? _path.Replace(fragment, "") : _path;
|
||||
|
||||
if (_path.Contains("/"))
|
||||
{
|
||||
if (_path.EndsWith("/") && _path != "/")
|
||||
|
@ -387,16 +396,13 @@
|
|||
}
|
||||
_path = _path.Substring(_path.LastIndexOf("/") + 1);
|
||||
}
|
||||
|
||||
if (_parentid == "-1")
|
||||
{
|
||||
page.ParentId = null;
|
||||
page.Path = Utilities.GetFriendlyUrl(_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
page.ParentId = Int32.Parse(_parentid);
|
||||
var parent = PageState.Pages.Where(item => item.PageId == page.ParentId).FirstOrDefault();
|
||||
Page parent = PageState.Pages.FirstOrDefault(item => item.PageId == page.ParentId);
|
||||
if (parent.Path == string.Empty)
|
||||
{
|
||||
page.Path = Utilities.GetFriendlyUrl(parent.Name) + "/" + Utilities.GetFriendlyUrl(_path);
|
||||
|
@ -406,6 +412,21 @@
|
|||
page.Path = parent.Path + "/" + Utilities.GetFriendlyUrl(_path);
|
||||
}
|
||||
}
|
||||
page.Path += fragment;
|
||||
}
|
||||
else
|
||||
{
|
||||
page.Path = _path;
|
||||
}
|
||||
|
||||
if (_parentid == "-1")
|
||||
{
|
||||
page.ParentId = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
page.ParentId = Int32.Parse(_parentid);
|
||||
}
|
||||
|
||||
var _pages = await PageService.GetPagesAsync(PageState.Site.SiteId);
|
||||
if (_pages.Any(item => item.Path == page.Path))
|
||||
|
@ -474,11 +495,18 @@
|
|||
await logger.LogInformation("Page Added {Page}", page);
|
||||
if (!string.IsNullOrEmpty(PageState.ReturnUrl))
|
||||
{
|
||||
NavigationManager.NavigateTo(page.Path); // redirect to new page
|
||||
NavigationManager.NavigateTo(PageState.ReturnUrl, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
NavigationManager.NavigateTo(NavigateUrl()); // redirect to page management
|
||||
if (!page.Path.Contains("://"))
|
||||
{
|
||||
NavigationManager.NavigateTo(page.Path); // redirect to new page created
|
||||
}
|
||||
else
|
||||
{
|
||||
NavigationManager.NavigateTo(NavigateUrl("admin/pages"));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -380,7 +380,7 @@
|
|||
}
|
||||
else
|
||||
{
|
||||
if (_path.Contains("/"))
|
||||
if (_path.Contains("/") & !_path.Contains("://"))
|
||||
{
|
||||
_path = _path.Substring(_path.LastIndexOf("/") + 1);
|
||||
}
|
||||
|
@ -518,10 +518,18 @@
|
|||
|
||||
_page.Name = _name;
|
||||
|
||||
// path can be a link to an external url
|
||||
if (!_path.Contains("://"))
|
||||
{
|
||||
if (string.IsNullOrEmpty(_path))
|
||||
{
|
||||
_path = _name;
|
||||
}
|
||||
|
||||
var fragment = (_path.Contains("?")) ? _path.Substring(_path.IndexOf("?")) : "";
|
||||
fragment = (_path.Contains("#")) ? _path.Substring(_path.IndexOf("#")) : "";
|
||||
_path = (!string.IsNullOrEmpty(fragment)) ? _path.Replace(fragment, "") : _path;
|
||||
|
||||
if (_path.Contains("/"))
|
||||
{
|
||||
if (_path.EndsWith("/") && _path != "/")
|
||||
|
@ -530,15 +538,12 @@
|
|||
}
|
||||
_path = _path.Substring(_path.LastIndexOf("/") + 1);
|
||||
}
|
||||
|
||||
if (_parentid == "-1")
|
||||
{
|
||||
_page.ParentId = null;
|
||||
_page.Path = Utilities.GetFriendlyUrl(_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
_page.ParentId = Int32.Parse(_parentid);
|
||||
Page parent = PageState.Pages.FirstOrDefault(item => item.PageId == _page.ParentId);
|
||||
if (parent.Path == string.Empty)
|
||||
{
|
||||
|
@ -549,6 +554,21 @@
|
|||
_page.Path = parent.Path + "/" + Utilities.GetFriendlyUrl(_path);
|
||||
}
|
||||
}
|
||||
_page.Path += fragment;
|
||||
}
|
||||
else
|
||||
{
|
||||
_page.Path = _path;
|
||||
}
|
||||
|
||||
if (_parentid == "-1")
|
||||
{
|
||||
_page.ParentId = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
_page.ParentId = Int32.Parse(_parentid);
|
||||
}
|
||||
|
||||
var _pages = await PageService.GetPagesAsync(PageState.Site.SiteId);
|
||||
if (_pages.Any(item => item.Path == _page.Path && item.PageId != _page.PageId))
|
||||
|
@ -638,7 +658,14 @@
|
|||
}
|
||||
else
|
||||
{
|
||||
NavigationManager.NavigateTo(NavigateUrl(), true);
|
||||
if (!_page.Path.Contains("://"))
|
||||
{
|
||||
NavigationManager.NavigateTo(NavigateUrl(), true); // redirect to page being edited
|
||||
}
|
||||
else
|
||||
{
|
||||
NavigationManager.NavigateTo(NavigateUrl("admin/pages"));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -55,12 +55,32 @@ namespace Oqtane.Shared
|
|||
return (urlparameters, querystring, anchor);
|
||||
}
|
||||
|
||||
private static (string Path, string Parameters) ParsePath(string path, string parameters)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
if (path.Contains('?'))
|
||||
{
|
||||
parameters = "?" + path.Split('?').Last();
|
||||
path = path.Split('?').First();
|
||||
}
|
||||
if (path.Contains('#'))
|
||||
{
|
||||
parameters = "#" + path.Split('#').Last();
|
||||
path = path.Split('#').First();
|
||||
}
|
||||
}
|
||||
return (path, parameters);
|
||||
}
|
||||
|
||||
public static string NavigateUrl(string alias, string path, string parameters)
|
||||
{
|
||||
string urlparameters;
|
||||
string querystring;
|
||||
string anchor;
|
||||
|
||||
// parse path (in case parameters are embedded in path)
|
||||
(path, parameters) = ParsePath(path, parameters);
|
||||
// parse parameters
|
||||
(urlparameters, querystring, anchor) = ParseParameters(parameters);
|
||||
if (!string.IsNullOrEmpty(urlparameters))
|
||||
|
|
Loading…
Reference in New Issue
Block a user