Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
devmtm committed Jan 31, 2019
2 parents 7828094 + dad0a7b commit cb228db
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Fields/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct($name, $attribute = null, $resolveCallback = null)

public function options() {
return $this->withMeta([
'options' => \DC\PermissionTool\Models\Role::get()->map(function ($role) {
'options' => \DigitalCloud\PermissionTool\Models\Role::get()->map(function ($role) {
return [
'display' => $role->name,
'value' => $role->id,
Expand Down
20 changes: 20 additions & 0 deletions src/Policies/PermissionPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,26 @@ class PermissionPolicy
{
use HandlesAuthorization;

public function attachAnyRole()
{
return true;
}

public function detachRole()
{
return true;
}

public function attachAnyUser()
{
return true;
}

public function detachUser()
{
return true;
}

public function viewAny(): bool
{
return true;
Expand Down
20 changes: 20 additions & 0 deletions src/Policies/RolePolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,26 @@ class RolePolicy
{
use HandlesAuthorization;

public function attachAnyPermission()
{
return true;
}

public function detachPermission()
{
return true;
}

public function attachAnyUser()
{
return true;
}

public function detachUser()
{
return true;
}

public function viewAny(): bool
{
return true;
Expand Down
15 changes: 9 additions & 6 deletions src/Resources/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,15 @@ public function fields(Request $request)
}
$resourceName = strtolower(substr(strrchr($resource, "\\"), 1));
$resourcePermissions = [
"create $resourceName" => "create $resourceName",
"update $resourceName" => "update $resourceName",
"view $resourceName" => "view $resourceName",
"delete $resourceName" => "delete $resourceName",
"force delete $resourceName" => "force delete $resourceName",
"restore $resourceName" => "restore $resourceName"
"viewAny $resourceName" => "viewAny $resourceName",
"create $resourceName" => "create $resourceName",
"update $resourceName" => "update $resourceName",
"view $resourceName" => "view $resourceName",
"delete $resourceName" => "delete $resourceName",
"force delete $resourceName" => "force delete $resourceName",
"restore $resourceName" => "restore $resourceName",
"attach $resourceName" => "attach $resourceName",
"detach $resourceName" => "detach $resourceName"
];
foreach ($resourcePermissions as $resourcePermission) {
$dbPermision = \DigitalCloud\PermissionTool\Models\Permission::firstOrCreate(
Expand Down
9 changes: 8 additions & 1 deletion src/ToolServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@ public function boot()

Gate::policy(config('permission.models.permission'), PermissionPolicy::class);
Gate::policy(config('permission.models.role'), RolePolicy::class);


// Super admin all permissions
// Gate::before(function ($user, $ability) {
// if ($user->email == '[email protected]') {
// return true;
// }
// });

Nova::serving(function (ServingNova $event) {
//
});
Expand Down

0 comments on commit cb228db

Please sign in to comment.