2017 © Pedro Peláez
 

library laravel-lock-routes

Add route-based checks for Laravel Lock permissions.

image

foothing/laravel-lock-routes

Add route-based checks for Laravel Lock permissions.

  • Friday, June 23, 2017
  • by brazorf
  • Repository
  • 1 Watchers
  • 3 Stars
  • 70 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 13 % Grown

The README.md

Laravel Lock Routes

This is a Laravel 5 package that allows to bind Lock permissions to routes., (*1)

It implements a Lock provider for Laravel Wrappr., (*2)

Install

composer require foothing/laravel-lock-routes

Setup

Add the Wrappr service provider in yourconfig/app.php providers array., (*3)

'providers' => [
    // ...
    Foothing\Wrappr\WrapprServiceProvider::class
]

Publish package configuration and migration files, (*4)

php artisan vendor:publish --provider="Foothing\Wrappr\WrapprServiceProvider"

Update your config/wrappr.php, (*5)

'permissionsProvider' => 'Foothing\Wrappr\Lock\LockProvider',
'usersProvider' => 'Foothing\Wrappr\Providers\Users\DefaultProvider',

Middlewares

There are two middleware use cases. You can use within Laravel Router or with complex pattern routes. More info in the Wrappr documentation., (*6)

Enable Laravel Router Middleware

protected $routeMiddleware = [
    'wrappr.check' => 'Foothing\Wrappr\Middleware\CheckRoute',
];

Use the CheckRoute Middleware to control access to your routes like the following routes.php:, (*7)

Route::get('api/users', ['middleware:wrappr.check:admin.users', function() {
    // Access is allowed for the users with the 'admin.users' permission
}]);

The CheckRoute Middleware accepts 3 arguments: - the required permission - an optional resource name, i.e. 'user' - an optional resource identifier (integer), (*8)

Example:, (*9)

Route::get('api/users/{id?}', ['middleware:wrappr.check:read.users,user,1', function() {
    // Access is allowed for the users with the 'read.users' permission on
    // the 'user' resource with the {id} identifier
}]);

Also, the Middleware can handle your route arguments. Consider the following, (*10)

Route::get('api/users/{id?}', ['middleware:wrappr.check:read.users,user,{id}', function() {
    // Access is allowed for the users with the 'read.users' permission on
    // the 'user' resource with the {id} identifier
}]);

When you pass a resource identifier within the brackets, the middleware will try to retrieve the value from the http request automatically., (*11)

Enable custom routes Middleware

When you're not able to fine-control at routes definition level, there's an alternative way of handling permissions. Think about a global RESTful controller like the following:, (*12)

Route::controller('api/v1/{args?}', 'FooController');

Assume that your controller applies a variable pattern to handle the routes, like for example, (*13)

GET /api/v1/resources/users
GET /api/v1/resources/posts
POST /api/v1/services/publish/post

In this case you won't be able to bind permissions with the previous method, so the CheckPath middleware comes to help. In order to enable this behaviour you need some additional setup step., (*14)

Add the global Middleware to your App\Http\Kernel like this, (*15)

protected $middleware = [
    \Foothing\Wrappr\Middleware\CheckPath::class
];

Now you can configure your routes in the config file or programmatically following the Wrappr routes documentation., (*16)

ACL abstraction layer

If you want more decoupling from your app and the acl library (Lock in this case) you can use the acl manipulation methods that are implemented in the provider. See example:, (*17)

$this->provider = \App::make('Foothing\Wrappr\Providers\Permissions\PermissionProviderInterface');

// Returns all the user's permissions
$this->provider->user($user)->all();

// Returns all the role's permissions
$this->provider->role('admin')->all();

// Allow the user to edit post with id = 1
$this->provider->user($user)->grant('edit', 'post', 1);

// Revoke previous permission
$this->provider->user($user)->revoke('edit', 'post', 1);

// Return false.
$this->provider->check($user, 'edit', 'post', 1);

License

MIT, (*18)

The Versions

23/06 2017

dev-master

9999999-dev

Add route-based checks for Laravel Lock permissions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar brazorf

laravel permissions lock routes

23/06 2017

0.3.0

0.3.0.0

Add route-based checks for Laravel Lock permissions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar brazorf

laravel permissions lock routes

19/06 2017

0.2.0

0.2.0.0

Add route-based checks for Laravel Lock permissions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar brazorf

laravel permissions lock routes

25/03 2016

0.1.2

0.1.2.0

Add route-based checks for Laravel Lock permissions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar brazorf

laravel permissions lock routes

25/03 2016

dev-develop

dev-develop

Add route-based checks for Laravel Lock permissions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar brazorf

laravel permissions lock routes

25/03 2016

0.1.1

0.1.1.0

Add route-based checks for Laravel Lock permissions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar brazorf

laravel permissions lock routes

06/11 2015

dev-feature/travis

dev-feature/travis

Add route-based checks for Laravel Lock permissions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar brazorf

laravel permissions lock routes

05/11 2015

0.1.0

0.1.0.0

Add route-based checks for Laravel Lock permissions.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar brazorf

laravel permissions lock routes