Skip to content

Commit

Permalink
Merge pull request #6729 from getkirby/fix/page-rules-move-one-more-time
Browse files Browse the repository at this point in the history
Fix `PageRules::move()` one more time
  • Loading branch information
bastianallgeier authored Oct 9, 2024
2 parents bf53acf + f33453d commit 927d925
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
15 changes: 9 additions & 6 deletions src/Cms/PageRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ public static function move(Page $page, Site|Page $parent): bool
$parent->blueprint()->sections(),
fn ($section) =>
$section->type() === 'pages' &&
$section->parent() === $parent
$section->parent()->is($parent)
);

// check if the parent has at least one pages section
Expand All @@ -385,17 +385,20 @@ public static function move(Page $page, Site|Page $parent): bool
]);
}

// go through all allowed blueprints and
// add the name to the allow list
// go through all allowed templates and
// add the name to the allowlist
foreach ($sections as $section) {
foreach ($section->blueprints() as $blueprint) {
$allowed[] = $blueprint['name'];
foreach ($section->templates() as $template) {
$allowed[] = $template;
}
}

// check if the template of this page is allowed as subpage type
// for the potential new parent
if (in_array($page->intendedTemplate()->name(), $allowed) === false) {
if (
$allowed !== [] &&
in_array($page->intendedTemplate()->name(), $allowed) === false
) {
throw new PermissionException([
'key' => 'page.move.template',
'data' => [
Expand Down
4 changes: 3 additions & 1 deletion tests/Cms/Pages/PageRulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,7 @@ public function testMoveWithInvalidTemplate()
'related' => [
'type' => 'pages',
'parent' => 'site.find("parent-a")',
'create' => 'album',
'templates' => ['article']
]
]
Expand Down Expand Up @@ -1000,6 +1001,7 @@ public function testMoveWithParentWithNoTemplateRestrictions()
[
'slug' => 'parent-b',
'template' => 'photography',
'create' => 'album'
]
]
],
Expand All @@ -1008,7 +1010,7 @@ public function testMoveWithParentWithNoTemplateRestrictions()
'pages/photography' => [
'sections' => [
'albums' => [
'type' => 'pages',
'type' => 'pages'
]
]
]
Expand Down

0 comments on commit 927d925

Please sign in to comment.