File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,8 @@ class Permissions
20
20
21
21
protected string $ panel = 'user ' ;
22
22
23
+ protected array $ excludePermissions = [];
24
+
23
25
public function __construct ()
24
26
{
25
27
$ this ->splitter = config ('permission-generator.route-name-splitter-needle ' );
@@ -37,6 +39,13 @@ public function panel(string $panel)
37
39
return $ this ;
38
40
}
39
41
42
+ public function exclude (array $ permissions )
43
+ {
44
+ $ this ->excludePermissions = $ permissions ;
45
+
46
+ return $ this ;
47
+ }
48
+
40
49
public function fromResources (array $ resources )
41
50
{
42
51
if ($ this ->hasCachedPermissions ()) {
@@ -59,7 +68,7 @@ public function fromRoutes()
59
68
return $ this ;
60
69
}
61
70
62
- $ routePermissionGenerator = (new RoutePermissionGenerator ($ this ->panel ))->generate ();
71
+ $ routePermissionGenerator = (new RoutePermissionGenerator ($ this ->panel ))->exclude ( $ this -> excludePermissions )-> generate ();
63
72
64
73
$ this ->permissions = $ routePermissionGenerator ['permissions ' ];
65
74
$ this ->onlyPermissionsNames = $ routePermissionGenerator ['only_permission_names ' ];
Original file line number Diff line number Diff line change @@ -14,11 +14,26 @@ class RoutePermissionGenerator
14
14
15
15
private string $ panel ;
16
16
17
+ protected array $ excludePermissions = [];
18
+
17
19
public function __construct (string $ panel = 'user ' )
18
20
{
19
21
$ this ->panel = $ panel ;
20
22
}
21
23
24
+ /**
25
+ * Exclude specific permissions from the permission list.
26
+ *
27
+ * @param array $permissions exclude permissions on demand.
28
+ * @return $this
29
+ */
30
+ public function exclude (array $ permissions )
31
+ {
32
+ $ this ->excludePermissions = $ permissions ;
33
+
34
+ return $ this ;
35
+ }
36
+
22
37
public function generate ()
23
38
{
24
39
$ this ->permissionGenerateControllers = config (
@@ -35,6 +50,8 @@ public function generate()
35
50
36
51
$ globalExcludedRoutes = config ("permission-generator.exclude-routes.panels. {$ this ->panel }" , []);
37
52
53
+ $ excludedRoutes = array_merge ($ globalExcludedRoutes , $ this ->excludePermissions );
54
+
38
55
$ routes = Route::getRoutes ();
39
56
40
57
$ onlyPermissionNames = [];
@@ -45,7 +62,7 @@ public function generate()
45
62
$ routeName = $ route ->getName ();
46
63
47
64
// exclude routes which defined in the config
48
- if (in_array ($ routeName , $ globalExcludedRoutes )) {
65
+ if (in_array ($ routeName , $ excludedRoutes )) {
49
66
continue ;
50
67
}
51
68
You can’t perform that action at this time.
0 commit comments