Skip to content

Commit

Permalink
Merge pull request #11 from kerli81/master
Browse files Browse the repository at this point in the history
Kirby 3.6 Issues solved
  • Loading branch information
sylvainjule authored Feb 23, 2022
2 parents be31b1d + 9580364 commit 5a00179
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
$user = kirby()->user();
if(!$user) return;

if (str_starts_with($path, "dialogs")
|| str_starts_with($path, "dropdowns")
|| str_starts_with($path, "search")) {
return;
}

$currentRole = $user->role()->name();

foreach(option('sylvainjule.bouncer.list') as $role => $options) {
Expand Down
24 changes: 24 additions & 0 deletions lib/bouncer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@

class Bouncer {

private static function getChildren($allowed, Kirby\Cms\Page $page) {
if (!$page->hasChildren()) {
return [];
}

$allowed = [];
$pages = $page->childrenAndDrafts();
foreach($pages as $p) {
$allowed[] = [
'title' => $p->title()->value(),
'path' => $p->panelUrl(true)
];


$children = Bouncer::getChildren($allowed, $p);
$allowed = array_merge($allowed, $children);
}

return $allowed;
}

public static function getAllowedPages($user, $fieldname, $extra = false) {
$kirby = kirby();
$allowed = [];
Expand All @@ -15,6 +36,9 @@ public static function getAllowedPages($user, $fieldname, $extra = false) {
'title' => $page->title()->value(),
'path' => $page->panelUrl(true)
];

$children = $extra ? Bouncer::getChildren($allowed, $page) : [];
$allowed = array_merge($allowed, $children);
}
}

Expand Down

0 comments on commit 5a00179

Please sign in to comment.