Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
uyab committed Jan 6, 2016
1 parent 1b2f2b3 commit 184648b
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,17 @@ public function boot(Gate $gate)
{

$this->registerMigrations();
$this->registerSeeds();
$this->registerConfigurations();

$this->registerAcl($gate);

if (!$this->skipAcl()) {
$this->registerAcl($gate);
}

$this->registerCommands();
}

protected function registerAcl($gate)
{
$table_permissions_name = app('Laravolt\Acl\Models\Permission')->getTable();

if (! Schema::hasTable($table_permissions_name)) {
return false;
}

$gate->before(function ($user) {
$isAdmin = call_user_func(config('acl.is_admin'), $user);
if ($isAdmin) {
Expand All @@ -71,14 +65,26 @@ protected function registerAcl($gate)
});

$permissions = Permission::all();

foreach ($permissions as $permission) {
$gate->define($permission->name, function (HasRoleAndPermission $user) use ($permission) {
return $user->hasPermission($permission);
});
}
}

protected function skipAcl()
{
$table_permissions_name = app('Laravolt\Acl\Models\Permission')->getTable();
if (!Schema::hasTable($table_permissions_name)) {
return true;
}

if ($this->app->runningInConsole()) {
return true;
}

return false;
}
/**
* Register the package migrations
*
Expand All @@ -92,18 +98,6 @@ protected function registerMigrations()
], 'migrations');
}

/**
* Register the package database seeds
*
* @return void
*/
protected function registerSeeds()
{
$this->publishes([
$this->packagePath('database/seeds') => database_path('/seeds')
], 'seeds');
}

/**
* Register the package configurations
*
Expand Down

0 comments on commit 184648b

Please sign in to comment.