Skip to content

Commit

Permalink
header or section ksort bug fixed, permission ignore from controller …
Browse files Browse the repository at this point in the history
…constructor added
  • Loading branch information
Nur Alam committed Oct 4, 2024
1 parent b4febd1 commit eae68e5
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/Contracts/WithPermissionGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,12 @@ public function getExcludeMethods(): array;
* @return string
*/
public function getAppendTo(): string;

/**
* All permissions ignored if true
*
* @return bool
*/
public function isPermissionsIgnored(): bool;

}
2 changes: 1 addition & 1 deletion src/Permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ protected function sectionPermissions()
}
}

if (!empty($sectionWisePermissions)) {
if (!empty($sectionWisePermissions) && array_key_exists($section, $sectionWisePermissions)) {
ksort($sectionWisePermissions[$section]['permissions']);
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/Services/RoutePermissionGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ public function generate()

// if the controller use the WithPermissible interface then find the excluded routes
if ($controllerInstance instanceof WithPermissionGenerator) {
if ($controllerInstance->isPermissionsIgnored()) {
continue;
}

$controllerMethod = $actionExtract[1];

$excludeMethods = $controllerInstance->getExcludeMethods();
Expand All @@ -96,7 +100,7 @@ public function generate()
}
}

// check is the current route store in onlyPermissionNames in order to avoid duplicacy
// check is the current route store in onlyPermissionNames in order to avoid duplicity
if (in_array($routeName, $onlyPermissionNames)) {
continue;
}
Expand Down
20 changes: 20 additions & 0 deletions src/Traits/PermissionGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ trait PermissionGenerator
{
private $title = '';

private $ignore = false;

private $excludeMethods = [];

private $appendTo = '';
Expand Down Expand Up @@ -54,6 +56,19 @@ protected function permissionsAppendTo(string $key)
return $this;
}

/**
* Permission ignored when value true
*
* @param boolean $ignore
* @return void
*/
protected function permissionsIgnoreWhen(bool $ignore)
{
$this->ignore = $ignore;

return $this;
}

/**
* @return string
*/
Expand All @@ -77,4 +92,9 @@ public function getAppendTo(): string
{
return $this->appendTo;
}

public function isPermissionsIgnored(): bool
{
return $this->ignore;
}
}

0 comments on commit eae68e5

Please sign in to comment.