Skip to content

Commit

Permalink
Add check for current menu existence in RenderCrud
Browse files Browse the repository at this point in the history
  • Loading branch information
nadar committed Nov 8, 2023
1 parent 0750447 commit 971ef5c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/ngrest/render/RenderCrud.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ public function getViewPath()
*/
public function render()
{
$currentMenu = Yii::$app->adminmenu->getApiDetail($this->getConfig()->getApiEndpoint(), Yii::$app->request->get('pool'));

if (!$currentMenu) {
throw new InvalidConfigException("The current menu item does not exists or you have no permissions to access this area.");
}

return $this->view->render('crud', [
'canCreate' => $this->can(Auth::CAN_CREATE),
'canUpdate' => $this->can(Auth::CAN_UPDATE),
Expand All @@ -116,7 +122,7 @@ public function render()
'modelSelection' => $this->getModelSelection(),
'hasActiveSelections' => count($this->config->getActiveSelections()),
'relationCall' => $this->getRelationCall(), // this is currently only used for the crud relation view file, there for split the RenderCrud into two sepeare renderes.
'currentMenu' => Yii::$app->adminmenu->getApiDetail($this->getConfig()->getApiEndpoint(), Yii::$app->request->get('pool')),
'currentMenu' => $currentMenu,
'downloadAttributes' => $this->generateDownloadAttributes(),
], $this);
}
Expand Down

0 comments on commit 971ef5c

Please sign in to comment.