Skip to content

Commit eae68e5

Browse files
author
Nur Alam
committed
header or section ksort bug fixed, permission ignore from controller constructor added
1 parent b4febd1 commit eae68e5

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

src/Contracts/WithPermissionGenerator.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,12 @@ public function getExcludeMethods(): array;
2828
* @return string
2929
*/
3030
public function getAppendTo(): string;
31+
32+
/**
33+
* All permissions ignored if true
34+
*
35+
* @return bool
36+
*/
37+
public function isPermissionsIgnored(): bool;
38+
3139
}

src/Permissions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ protected function sectionPermissions()
177177
}
178178
}
179179

180-
if (!empty($sectionWisePermissions)) {
180+
if (!empty($sectionWisePermissions) && array_key_exists($section, $sectionWisePermissions)) {
181181
ksort($sectionWisePermissions[$section]['permissions']);
182182
}
183183
}

src/Services/RoutePermissionGenerator.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ public function generate()
8787

8888
// if the controller use the WithPermissible interface then find the excluded routes
8989
if ($controllerInstance instanceof WithPermissionGenerator) {
90+
if ($controllerInstance->isPermissionsIgnored()) {
91+
continue;
92+
}
93+
9094
$controllerMethod = $actionExtract[1];
9195

9296
$excludeMethods = $controllerInstance->getExcludeMethods();
@@ -96,7 +100,7 @@ public function generate()
96100
}
97101
}
98102

99-
// check is the current route store in onlyPermissionNames in order to avoid duplicacy
103+
// check is the current route store in onlyPermissionNames in order to avoid duplicity
100104
if (in_array($routeName, $onlyPermissionNames)) {
101105
continue;
102106
}

src/Traits/PermissionGenerator.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ trait PermissionGenerator
88
{
99
private $title = '';
1010

11+
private $ignore = false;
12+
1113
private $excludeMethods = [];
1214

1315
private $appendTo = '';
@@ -54,6 +56,19 @@ protected function permissionsAppendTo(string $key)
5456
return $this;
5557
}
5658

59+
/**
60+
* Permission ignored when value true
61+
*
62+
* @param boolean $ignore
63+
* @return void
64+
*/
65+
protected function permissionsIgnoreWhen(bool $ignore)
66+
{
67+
$this->ignore = $ignore;
68+
69+
return $this;
70+
}
71+
5772
/**
5873
* @return string
5974
*/
@@ -77,4 +92,9 @@ public function getAppendTo(): string
7792
{
7893
return $this->appendTo;
7994
}
95+
96+
public function isPermissionsIgnored(): bool
97+
{
98+
return $this->ignore;
99+
}
80100
}

0 commit comments

Comments
 (0)