parent
8edf70e280
commit
7430c78a0f
|
@ -0,0 +1,46 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Lauthz\Commands;
|
||||||
|
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Lauthz\Facades\Enforcer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PolicyAdd class.
|
||||||
|
*/
|
||||||
|
class GroupAdd extends Command {
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'group:add
|
||||||
|
{policy : the rule separated by commas}';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Adds a role inheritance rule to the current policy.';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle() {
|
||||||
|
$params = explode(',', $this->argument('policy'));
|
||||||
|
array_walk($params, function (&$value) {
|
||||||
|
$value = trim($value);
|
||||||
|
});
|
||||||
|
$ret = Enforcer::addGroupingPolicy(...$params);
|
||||||
|
if ($ret) {
|
||||||
|
$this->info('Grouping `' . implode(', ', $params) . '` created');
|
||||||
|
} else {
|
||||||
|
$this->error('Grouping `' . implode(', ', $params) . '` creation failed');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ret ? 0 : 1;
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,29 +2,28 @@
|
||||||
|
|
||||||
namespace Lauthz;
|
namespace Lauthz;
|
||||||
|
|
||||||
|
use Illuminate\Support\ServiceProvider;
|
||||||
use Lauthz\Models\Rule;
|
use Lauthz\Models\Rule;
|
||||||
use Lauthz\Observers\RuleObserver;
|
use Lauthz\Observers\RuleObserver;
|
||||||
use Illuminate\Support\ServiceProvider;
|
|
||||||
|
|
||||||
class LauthzServiceProvider extends ServiceProvider
|
class LauthzServiceProvider extends ServiceProvider {
|
||||||
{
|
|
||||||
/**
|
/**
|
||||||
* Perform post-registration booting of services.
|
* Perform post-registration booting of services.
|
||||||
*/
|
*/
|
||||||
public function boot()
|
public function boot() {
|
||||||
{
|
|
||||||
if ($this->app->runningInConsole()) {
|
if ($this->app->runningInConsole()) {
|
||||||
$this->publishes([__DIR__.'/../database/migrations' => database_path('migrations')], 'laravel-lauthz-migrations');
|
$this->publishes([__DIR__ . '/../database/migrations' => database_path('migrations')], 'laravel-lauthz-migrations');
|
||||||
$this->publishes([__DIR__.'/../config/lauthz-rbac-model.conf' => config_path('lauthz-rbac-model.conf')], 'laravel-lauthz-config');
|
$this->publishes([__DIR__ . '/../config/lauthz-rbac-model.conf' => config_path('lauthz-rbac-model.conf')], 'laravel-lauthz-config');
|
||||||
$this->publishes([__DIR__.'/../config/lauthz.php' => config_path('lauthz.php')], 'laravel-lauthz-config');
|
$this->publishes([__DIR__ . '/../config/lauthz.php' => config_path('lauthz.php')], 'laravel-lauthz-config');
|
||||||
|
|
||||||
$this->commands([
|
$this->commands([
|
||||||
|
Commands\GroupAdd::class,
|
||||||
Commands\PolicyAdd::class,
|
Commands\PolicyAdd::class,
|
||||||
Commands\RoleAssign::class,
|
Commands\RoleAssign::class,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->mergeConfigFrom(__DIR__.'/../config/lauthz.php', 'lauthz');
|
$this->mergeConfigFrom(__DIR__ . '/../config/lauthz.php', 'lauthz');
|
||||||
|
|
||||||
$this->bootObserver();
|
$this->bootObserver();
|
||||||
}
|
}
|
||||||
|
@ -34,16 +33,14 @@ class LauthzServiceProvider extends ServiceProvider
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
protected function bootObserver()
|
protected function bootObserver() {
|
||||||
{
|
|
||||||
Rule::observe(new RuleObserver());
|
Rule::observe(new RuleObserver());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register bindings in the container.
|
* Register bindings in the container.
|
||||||
*/
|
*/
|
||||||
public function register()
|
public function register() {
|
||||||
{
|
|
||||||
$this->app->singleton('enforcer', function ($app) {
|
$this->app->singleton('enforcer', function ($app) {
|
||||||
return new EnforcerManager($app);
|
return new EnforcerManager($app);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue