Skip to content

Commit 1883034

Browse files
authored
Merge pull request #1 from osindex/master
🐛 update casbin version
2 parents 6f06165 + 46674ff commit 1883034

File tree

4 files changed

+80
-6
lines changed

4 files changed

+80
-6
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"license": "Apache-2.0",
1212
"require": {
1313
"laravel/framework": "~5.1",
14-
"casbin/casbin": ">=0.1.0"
14+
"casbin/casbin": ">=0.2.1"
1515
},
1616
"require-dev": {
1717
"phpunit/phpunit": "~5.7|~6.0|~7.0|~8.0",

src/Commands/GroupAdd.php

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace Lauthz\Commands;
4+
5+
use Illuminate\Console\Command;
6+
use Lauthz\Facades\Enforcer;
7+
8+
/**
9+
* PolicyAdd class.
10+
*/
11+
class GroupAdd extends Command
12+
{
13+
/**
14+
* The name and signature of the console command.
15+
*
16+
* @var string
17+
*/
18+
protected $signature = 'group:add
19+
{policy : the rule separated by commas}';
20+
21+
/**
22+
* The console command description.
23+
*
24+
* @var string
25+
*/
26+
protected $description = 'Adds a role inheritance rule to the current policy.';
27+
28+
/**
29+
* Execute the console command.
30+
*
31+
* @return mixed
32+
*/
33+
public function handle()
34+
{
35+
$params = explode(',', $this->argument('policy'));
36+
array_walk($params, function (&$value) {
37+
$value = trim($value);
38+
});
39+
$ret = Enforcer::addGroupingPolicy(...$params);
40+
if ($ret) {
41+
$this->info('Grouping `' . implode(', ', $params) . '` created');
42+
} else {
43+
$this->error('Grouping `' . implode(', ', $params) . '` creation failed');
44+
}
45+
46+
return $ret ? 0 : 1;
47+
}
48+
}

src/LauthzServiceProvider.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace Lauthz;
44

5+
use Illuminate\Support\ServiceProvider;
56
use Lauthz\Models\Rule;
67
use Lauthz\Observers\RuleObserver;
7-
use Illuminate\Support\ServiceProvider;
88

99
class LauthzServiceProvider extends ServiceProvider
1010
{
@@ -14,17 +14,18 @@ class LauthzServiceProvider extends ServiceProvider
1414
public function boot()
1515
{
1616
if ($this->app->runningInConsole()) {
17-
$this->publishes([__DIR__.'/../database/migrations' => database_path('migrations')], 'laravel-lauthz-migrations');
18-
$this->publishes([__DIR__.'/../config/lauthz-rbac-model.conf' => config_path('lauthz-rbac-model.conf')], 'laravel-lauthz-config');
19-
$this->publishes([__DIR__.'/../config/lauthz.php' => config_path('lauthz.php')], 'laravel-lauthz-config');
17+
$this->publishes([__DIR__ . '/../database/migrations' => database_path('migrations')], 'laravel-lauthz-migrations');
18+
$this->publishes([__DIR__ . '/../config/lauthz-rbac-model.conf' => config_path('lauthz-rbac-model.conf')], 'laravel-lauthz-config');
19+
$this->publishes([__DIR__ . '/../config/lauthz.php' => config_path('lauthz.php')], 'laravel-lauthz-config');
2020

2121
$this->commands([
22+
Commands\GroupAdd::class,
2223
Commands\PolicyAdd::class,
2324
Commands\RoleAssign::class,
2425
]);
2526
}
2627

27-
$this->mergeConfigFrom(__DIR__.'/../config/lauthz.php', 'lauthz');
28+
$this->mergeConfigFrom(__DIR__ . '/../config/lauthz.php', 'lauthz');
2829

2930
$this->bootObserver();
3031
}

tests/Commands/GroupAddTest.php

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Lauthz\Tests\Commands;
4+
5+
use Illuminate\Foundation\Testing\DatabaseMigrations;
6+
use Illuminate\Support\Facades\Artisan;
7+
use Lauthz\Facades\Enforcer;
8+
use Lauthz\Tests\TestCase;
9+
10+
class GroupAddTest extends TestCase
11+
{
12+
use DatabaseMigrations;
13+
14+
public function testHandle()
15+
{
16+
$this->assertFalse(Enforcer::hasGroupingPolicy('eve', 'writer', 'domain'));
17+
18+
$exitCode = Artisan::call('group:add', ['policy' => 'eve, writer, domain']);
19+
$this->assertTrue(0 === $exitCode);
20+
$this->assertTrue(Enforcer::hasGroupingPolicy('eve', 'writer', 'domain'));
21+
22+
$exitCode = Artisan::call('group:add', ['policy' => 'eve, writer, domain']);
23+
$this->assertFalse(0 === $exitCode);
24+
}
25+
}

0 commit comments

Comments
 (0)