Skip to content

Commit 28f0320

Browse files
author
Nur Alam
committed
bug fixed, permission generate by resources
1 parent a1f09f6 commit 28f0320

File tree

4 files changed

+49
-16
lines changed

4 files changed

+49
-16
lines changed

config/permission-generator.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@
5959
*/
6060
'card-size-class' => 'col-md-3 col-lg-3 col-sm-12',
6161

62-
62+
/**
63+
* These tage used to generate permissions on given resources
64+
*
65+
* [Ex: create-posts,'edit-posts','view-list-posts' etc]
66+
*/
6367
'resource-permission-tags' => [
6468
'create',
6569
'edit',

src/Html/Builder.php

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ class Builder
1616

1717
protected $url = null;
1818

19+
protected string $source = 'routes';
20+
21+
protected array $resources = [];
22+
1923
/**
2024
* @param string $roleName
2125
* @param array $rolePermissions
@@ -37,6 +41,33 @@ public function withRolePermissions(
3741
return $this;
3842
}
3943

44+
/**
45+
* Permissions generate from route names
46+
*
47+
* @return Builder
48+
*/
49+
public function fromRoutes()
50+
{
51+
$this->source = 'routes';
52+
53+
return $this;
54+
}
55+
56+
/**
57+
* Permissions generate from resources
58+
*
59+
* @param array $resources
60+
* @return Builder
61+
*/
62+
public function fromResources(array $resources)
63+
{
64+
$this->source = 'resources';
65+
66+
$this->resources = $resources;
67+
68+
return $this;
69+
}
70+
4071
/**
4172
* @param string $view
4273
* @param array $data
@@ -52,10 +83,11 @@ public function view(string $view, array $data = [])
5283

5384
protected function render(array $permissions = []): string
5485
{
86+
5587
return View::make(
5688
'permission-generator::permission',
5789
[
58-
'permissions' => Permissions::make()->fromRoutes()->get(),
90+
'permissions' => $this->resolvePermissions(),
5991
'roleName' => $this->roleName,
6092
'rolePermissions' => $this->rolePermissions,
6193
]
@@ -66,4 +98,13 @@ protected function scripts(): string
6698
{
6799
return View::make('permission-generator::scripts', ['url' => $this->url])->render();
68100
}
101+
102+
protected function resolvePermissions(): array
103+
{
104+
if ($this->source == 'routes') {
105+
return Permissions::make()->fromRoutes()->get();
106+
}
107+
108+
return Permissions::make()->fromResources($this->resources)->get();
109+
}
69110
}

src/Permissions.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ public static function make(): Permissions
2727
return new self();
2828
}
2929

30-
public function fromAttributes(){
31-
32-
}
33-
3430
public function fromResources(array $resources)
3531
{
3632
if ($this->hasCachedPermissions()) {
@@ -43,7 +39,7 @@ public function fromResources(array $resources)
4339
$this->onlyPermissionsNames = $resourceGenerator['only_permission_names'];
4440

4541
$this->customPermissions();
46-
// $this->cachePermissions();
42+
$this->cachePermissions();
4743

4844
return $this;
4945
}
@@ -60,7 +56,7 @@ public function fromRoutes()
6056
$this->onlyPermissionsNames = $routePermissionGenerator['only_permission_names'];
6157

6258
$this->customPermissions();
63-
//$this->cachePermissions();
59+
$this->cachePermissions();
6460

6561
return $this;
6662
}

src/Services/AttributePermissionGenerator.php

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)