Skip to content

Commit

Permalink
Merge pull request #3940 from sbwalker/dev
Browse files Browse the repository at this point in the history
fix #3936 - parent page default when adding new pages
  • Loading branch information
sbwalker authored Mar 4, 2024
2 parents ad12d42 + f893cf2 commit db2015f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
23 changes: 11 additions & 12 deletions Oqtane.Client/Modules/Admin/Pages/Add.razor
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,8 @@
{
_pageId = Int32.Parse(PageState.QueryString["id"]);
_parent = await PageService.GetPageAsync(_pageId);
if (_parent != null && !UserSecurity.IsAuthorized(PageState.User, RoleNames.Admin))
if (_parent != null)
{
// non-admins are authorized to create child pages of current page
_parentid = _parent.PageId.ToString();
}
}
Expand Down Expand Up @@ -376,6 +375,15 @@
page.SiteId = PageState.Page.SiteId;
page.Name = _name;

if (_parentid == "-1")
{
page.ParentId = null;
}
else
{
page.ParentId = Int32.Parse(_parentid);
}

// path can be a link to an external url
if (!_path.Contains("://"))
{
Expand All @@ -400,7 +408,7 @@
}
else
{
Page parent = PageState.Pages.FirstOrDefault(item => item.PageId == Int32.Parse(_parentid));
Page parent = PageState.Pages.FirstOrDefault(item => item.PageId == page.ParentId);
if (parent.Path == string.Empty)
{
page.Path = Utilities.GetFriendlyUrl(parent.Name) + "/" + Utilities.GetFriendlyUrl(_path);
Expand All @@ -417,15 +425,6 @@
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))
{
Expand Down
20 changes: 10 additions & 10 deletions Oqtane.Client/Modules/Admin/Pages/Edit.razor
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,15 @@

_page.Name = _name;

if (_parentid == "-1")
{
_page.ParentId = null;
}
else
{
_page.ParentId = Int32.Parse(_parentid);
}

// path can be a link to an external url
if (!_path.Contains("://"))
{
Expand All @@ -542,7 +551,7 @@
}
else
{
Page parent = PageState.Pages.FirstOrDefault(item => item.PageId == Int32.Parse(_parentid));
Page parent = PageState.Pages.FirstOrDefault(item => item.PageId == _page.ParentId);
if (parent.Path == string.Empty)
{
_page.Path = Utilities.GetFriendlyUrl(parent.Name) + "/" + Utilities.GetFriendlyUrl(_path);
Expand All @@ -559,15 +568,6 @@
_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))
{
Expand Down

0 comments on commit db2015f

Please sign in to comment.