This repository has been archived by the owner on Apr 10, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrating Authority package with filter & macro
- Loading branch information
Showing
16 changed files
with
193 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
namespace Zeropingheroes\LanagerCore\Models; | ||
|
||
use Illuminate\Auth\UserInterface; | ||
|
||
class Permission extends BaseModel | ||
{ | ||
// | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
namespace Zeropingheroes\LanagerCore\Models; | ||
|
||
use Illuminate\Auth\UserInterface; | ||
|
||
class Role extends BaseModel | ||
{ | ||
// | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
return array( | ||
|
||
'initialize' => function($authority) | ||
{ | ||
// Allowed verbs: create, read, update, delete | ||
// Allowed aliases: manage | ||
|
||
// Add an alias for full resourceful CRUD | ||
$authority->addAlias('manage', array('create', 'read', 'update', 'delete')); | ||
|
||
// Get the currently logged in user | ||
$user = $authority->getCurrentUser(); | ||
|
||
// If there is a user currently logged in, assign permissions based on roles | ||
if( is_object($user) ) | ||
{ | ||
if( $user->hasRole('SuperAdmin') ) | ||
{ | ||
$authority->allow('manage', 'all'); | ||
} | ||
|
||
if( $user->hasRole('InfoPageAdmin') ) | ||
{ | ||
$authority->allow('manage', 'InfoPage'); | ||
} | ||
|
||
} | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
/* | ||
|-------------------------------------------------------------------------- | ||
| Filters | ||
|-------------------------------------------------------------------------- | ||
*/ | ||
|
||
Route::filter('authority', function($route, $request) | ||
{ | ||
// Get request details | ||
$routeName = explode('.', Route::currentRouteName()); | ||
$resource = $routeName[0]; | ||
$action = $routeName[1]; | ||
$item = $route->getParameter($resource); | ||
|
||
// Replace laravel-style route action names with their CRUD equivalents | ||
$actionsToReplace = array('store', 'show', 'index', 'edit', 'destroy'); | ||
$replaceWithAction = array('create', 'read', 'read', 'update', 'delete'); | ||
$action = str_replace($actionsToReplace, $replaceWithAction, $action); | ||
|
||
// Check if user is forbidden from performing $action on $resource $item | ||
if(Authority::cannot($action, $resource, $item)) | ||
{ | ||
return App::abort(403, 'You do not have permission to '.$action.' '.$resource.' '.$item); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
@if(!empty($infoPages)) | ||
@foreach($infoPages as $infoPage) | ||
<li><a href="{{route('info.show',$infoPage->id)}}">{{{$infoPage->title}}}</a></li> | ||
<li><a href="{{ route('infoPage.show',$infoPage->id) }}">{{{ $infoPage->title }}}</a></li> | ||
@endforeach | ||
@endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters