From 5bedbba2a7b712d74741574f0f23f21606b25529 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Fri, 15 Dec 2017 12:36:13 -0600 Subject: [PATCH] use laratrust to replace entrust #78 --- app/Database/factories/AirportFactory.php | 1 - .../2017_06_08_0000_create_users_table.php | 66 ----- ...17_06_08_0001_roles_permissions_tables.php | 101 +++++++ app/Database/seeds/dev.yml | 4 + app/Http/Kernel.php | 6 +- .../Middleware/RedirectIfAuthenticated.php | 2 +- app/Models/Permission.php | 4 +- app/Models/Role.php | 4 +- app/Models/User.php | 6 +- app/Services/DatabaseService.php | 8 +- composer.json | 4 +- composer.lock | 273 ++++++++++-------- config/app.php | 2 - config/entrust.php | 92 ------ config/laratrust.php | 210 ++++++++++++++ .../Installer/Services/EnvironmentService.php | 6 +- resources/views/layouts/default/app.blade.php | 5 +- tests/data/base.yml | 2 + 18 files changed, 501 insertions(+), 295 deletions(-) create mode 100644 app/Database/migrations/2017_06_08_0001_roles_permissions_tables.php delete mode 100644 config/entrust.php create mode 100644 config/laratrust.php diff --git a/app/Database/factories/AirportFactory.php b/app/Database/factories/AirportFactory.php index 2fd72fa8..a5a55190 100644 --- a/app/Database/factories/AirportFactory.php +++ b/app/Database/factories/AirportFactory.php @@ -6,7 +6,6 @@ use Faker\Generator as Faker; * Add any number of airports. Don't really care if they're real or not */ $factory->define(App\Models\Airport::class, function (Faker $faker) { - return [ 'id' => strtoupper($faker->unique()->text(5)), 'icao' => function(array $apt) { return $apt['id']; }, diff --git a/app/Database/migrations/2017_06_08_0000_create_users_table.php b/app/Database/migrations/2017_06_08_0000_create_users_table.php index 330c8d29..bb16dc68 100755 --- a/app/Database/migrations/2017_06_08_0000_create_users_table.php +++ b/app/Database/migrations/2017_06_08_0000_create_users_table.php @@ -37,68 +37,6 @@ class CreateUsersTable extends Migration $table->index('email'); $table->index('api_key'); }); - - // Create table for storing roles - Schema::create('roles', function (Blueprint $table) { - $table->increments('id'); - $table->string('name')->unique(); - $table->string('display_name')->nullable(); - $table->string('description')->nullable(); - $table->timestamps(); - }); - - // Create table for associating roles to users (Many-to-Many) - Schema::create('role_user', function (Blueprint $table) { - $table->unsignedInteger('user_id'); - $table->unsignedInteger('role_id'); - - $table->foreign('user_id')->references('id')->on('users') - ->onUpdate('cascade')->onDelete('cascade'); - $table->foreign('role_id')->references('id')->on('roles') - ->onUpdate('cascade')->onDelete('cascade'); - - $table->primary(['user_id', 'role_id']); - $table->index(['role_id', 'user_id']); - }); - - // Create table for storing permissions - Schema::create('permissions', function (Blueprint $table) { - $table->increments('id'); - $table->string('name')->unique(); - $table->string('display_name')->nullable(); - $table->string('description')->nullable(); - $table->timestamps(); - }); - - // Create table for associating permissions to roles (Many-to-Many) - Schema::create('permission_role', function (Blueprint $table) { - $table->unsignedInteger('permission_id'); - $table->unsignedInteger('role_id'); - - $table->foreign('permission_id')->references('id')->on('permissions') - ->onUpdate('cascade')->onDelete('cascade'); - $table->foreign('role_id')->references('id')->on('roles') - ->onUpdate('cascade')->onDelete('cascade'); - - $table->primary(['permission_id', 'role_id']); - }); - - # create a default user/role - $roles = [ - [ - 'id' => 1, - 'name' => 'admin', - 'display_name' => 'Administrators', - ], - [ - 'id' => 2, - 'name' => 'user', - 'display_name' => 'Pilot' - ], - ]; - - - $this->addData('roles', $roles); } /** @@ -109,9 +47,5 @@ class CreateUsersTable extends Migration public function down() { Schema::dropIfExists('users'); - Schema::dropIfExists('permission_role'); - Schema::dropIfExists('permissions'); - Schema::dropIfExists('role_user'); - Schema::dropIfExists('roles'); } } diff --git a/app/Database/migrations/2017_06_08_0001_roles_permissions_tables.php b/app/Database/migrations/2017_06_08_0001_roles_permissions_tables.php new file mode 100644 index 00000000..a8dd6179 --- /dev/null +++ b/app/Database/migrations/2017_06_08_0001_roles_permissions_tables.php @@ -0,0 +1,101 @@ +increments('id'); + $table->string('name')->unique(); + $table->string('display_name')->nullable(); + $table->string('description')->nullable(); + $table->timestamps(); + }); + + // Create table for storing permissions + Schema::create('permissions', function (Blueprint $table) { + $table->increments('id'); + $table->string('name')->unique(); + $table->string('display_name')->nullable(); + $table->string('description')->nullable(); + $table->timestamps(); + }); + + // Create table for associating roles to users and teams (Many To Many Polymorphic) + Schema::create('role_user', function (Blueprint $table) { + $table->unsignedInteger('role_id'); + $table->unsignedInteger('user_id'); + $table->string('user_type'); + + $table->foreign('role_id')->references('id')->on('roles') + ->onUpdate('cascade')->onDelete('cascade'); + + $table->primary(['user_id', 'role_id', 'user_type']); + }); + + // Create table for associating permissions to users (Many To Many Polymorphic) + Schema::create('permission_user', function (Blueprint $table) { + $table->unsignedInteger('permission_id'); + $table->unsignedInteger('user_id'); + $table->string('user_type'); + + $table->foreign('permission_id')->references('id')->on('permissions') + ->onUpdate('cascade')->onDelete('cascade'); + + $table->primary(['user_id', 'permission_id', 'user_type']); + }); + + // Create table for associating permissions to roles (Many-to-Many) + Schema::create('permission_role', function (Blueprint $table) { + $table->unsignedInteger('permission_id'); + $table->unsignedInteger('role_id'); + + $table->foreign('permission_id')->references('id')->on('permissions') + ->onUpdate('cascade')->onDelete('cascade'); + $table->foreign('role_id')->references('id')->on('roles') + ->onUpdate('cascade')->onDelete('cascade'); + + $table->primary(['permission_id', 'role_id']); + }); + + # create a default user/role + $roles = [ + [ + 'id' => 1, + 'name' => 'admin', + 'display_name' => 'Administrators', + ], + [ + 'id' => 2, + 'name' => 'user', + 'display_name' => 'Pilot' + ], + ]; + + + $this->addData('roles', $roles); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('permission_user'); + Schema::dropIfExists('permission_role'); + Schema::dropIfExists('permissions'); + Schema::dropIfExists('role_user'); + Schema::dropIfExists('roles'); + } +} diff --git a/app/Database/seeds/dev.yml b/app/Database/seeds/dev.yml index 0dbb98dc..13de353a 100644 --- a/app/Database/seeds/dev.yml +++ b/app/Database/seeds/dev.yml @@ -55,12 +55,16 @@ users: role_user: - user_id: 1 role_id: 1 + user_type: App\Models\User - user_id: 1 role_id: 2 + user_type: App\Models\User - user_id: 2 role_id: 2 + user_type: App\Models\User - user_id: 3 role_id: 2 + user_type: App\Models\User # ranks ranks: diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 7c69f41d..d8061931 100755 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -54,8 +54,8 @@ class Kernel extends HttpKernel 'can' => \Illuminate\Auth\Middleware\Authorize::class, 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, - 'role' => \Zizaco\Entrust\Middleware\EntrustRole::class, - 'permission' => \Zizaco\Entrust\Middleware\EntrustPermission::class, - 'ability' => \Zizaco\Entrust\Middleware\EntrustAbility::class, + #'role' => \Laratrust\Middleware\LaratrustRole::class, + #'permission' => \Laratrust\Middleware\LaratrustPermission::class, + #'ability' => \Laratrust\Middleware\LaratrustAbility::class, ]; } diff --git a/app/Http/Middleware/RedirectIfAuthenticated.php b/app/Http/Middleware/RedirectIfAuthenticated.php index e4cec9c8..e27860e2 100755 --- a/app/Http/Middleware/RedirectIfAuthenticated.php +++ b/app/Http/Middleware/RedirectIfAuthenticated.php @@ -18,7 +18,7 @@ class RedirectIfAuthenticated public function handle($request, Closure $next, $guard = null) { if (Auth::guard($guard)->check()) { - return redirect('/home'); + return redirect('/'); } return $next($request); diff --git a/app/Models/Permission.php b/app/Models/Permission.php index d32d8f2c..b7f527b9 100644 --- a/app/Models/Permission.php +++ b/app/Models/Permission.php @@ -1,8 +1,8 @@ insert($row); - } catch(QueryException $e) { - Log::info($e->getMessage()); - } + #} catch(QueryException $e) { + # Log::info($e->getMessage()); + #} } } } diff --git a/composer.json b/composer.json index 4ea82855..2aec6200 100755 --- a/composer.json +++ b/composer.json @@ -1,4 +1,4 @@ - { +{ "name": "phpvms/phpvms", "version": "7.0.0-dev", "description": "phpVMS - Virtual Airline Administration", @@ -23,7 +23,6 @@ "doctrine/dbal": "v2.5.12", "doctrine/inflector": "v1.1.0", "doctrine/instantiator": "v1.0.5", - "zizaco/entrust": "5.2.x-dev", "prettus/l5-repository": "2.6.28", "spatie/laravel-pjax": "1.3.1", "symfony/inflector": "v3.4.0", @@ -45,6 +44,7 @@ "sebastiaanluca/laravel-helpers": "1.0.2", "jackiedo/timezonelist": "5.x", "tivie/php-os-detector": "1.1.0", + "santigarcor/laratrust": "5.0.3", "nabeel/vacentral": "dev-master" }, "require-dev": { diff --git a/composer.lock b/composer.lock index 50deb70b..cfa8394b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "f657a54ce87b561f6f413f836cbd20a3", + "content-hash": "a34f3d409e7a3e41c650c2c201b3e2e7", "packages": [ { "name": "composer/semver", @@ -427,7 +427,7 @@ "Doctrine\\DBAL\\": "lib/" } }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -750,7 +750,7 @@ "Egulias\\EmailValidator\\": "EmailValidator" } }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -796,7 +796,7 @@ "Parsedown": "" } }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -856,7 +856,7 @@ "GuzzleHttp\\": "src/" } }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -914,7 +914,7 @@ "src/functions_include.php" ] }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -969,7 +969,7 @@ "src/functions_include.php" ] }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -1031,7 +1031,7 @@ "Hashids\\": "src/" } }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -1138,7 +1138,7 @@ "InfyOm\\AdminLTETemplates\\": "src/" } }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -1199,7 +1199,7 @@ "src/helpers.php" ] }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -1249,7 +1249,7 @@ "Jackiedo\\Timezonelist\\": "src/Jackiedo/Timezonelist" } }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -1326,6 +1326,51 @@ ], "time": "2016-12-07T09:37:55+00:00" }, + { + "name": "kkszymanowski/traitor", + "version": "0.2.4", + "source": { + "type": "git", + "url": "https://github.com/KKSzymanowski/Traitor.git", + "reference": "05462468d0592545448f1a2877d045f5048abea1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/KKSzymanowski/Traitor/zipball/05462468d0592545448f1a2877d045f5048abea1", + "reference": "05462468d0592545448f1a2877d045f5048abea1", + "shasum": "" + }, + "require": { + "nikic/php-parser": "^1.0|^2.0|^3.0", + "php": ">=5.4" + }, + "require-dev": { + "phpunit/phpunit": "~4.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "Traitor\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Kuba Szymanowski", + "email": "kuba.szymanowski@inf24.pl" + } + ], + "description": "Add a trait use statement to existing PHP class", + "keywords": [ + "add", + "php", + "trait" + ], + "time": "2017-08-28T11:34:42+00:00" + }, { "name": "laracasts/flash", "version": "3.0.2", @@ -1495,7 +1540,7 @@ "Illuminate\\": "src/Illuminate/" } }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -2024,7 +2069,7 @@ "Cron\\": "src/Cron/" } }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -2073,7 +2118,7 @@ "src/DeepCopy/deep_copy.php" ] }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -2117,7 +2162,7 @@ "VaCentral\\": "src/" } }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -2211,7 +2256,7 @@ "PhpParser\\": "lib/PhpParser" } }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "BSD-3-Clause" ], @@ -2644,7 +2689,7 @@ ] } }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -2797,7 +2842,7 @@ "Prophecy\\": "src/" } }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -2915,7 +2960,7 @@ "src/" ] }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "BSD-3-Clause" ], @@ -3056,7 +3101,7 @@ "src/" ] }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "BSD-3-Clause" ], @@ -3137,7 +3182,7 @@ "src/" ] }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "BSD-3-Clause" ], @@ -3260,7 +3305,7 @@ "Prettus\\Repository\\": "src/Prettus/Repository/" } }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -3685,6 +3730,75 @@ ], "time": "2017-03-25T12:08:31+00:00" }, + { + "name": "santigarcor/laratrust", + "version": "5.0.3", + "source": { + "type": "git", + "url": "https://github.com/santigarcor/laratrust.git", + "reference": "dcded937608c4b8e356968597903925a61fa06c5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/santigarcor/laratrust/zipball/dcded937608c4b8e356968597903925a61fa06c5", + "reference": "dcded937608c4b8e356968597903925a61fa06c5", + "shasum": "" + }, + "require": { + "illuminate/auth": "~5.2", + "illuminate/cache": "~5.2", + "illuminate/console": "~5.2", + "illuminate/database": "^5.2.32", + "illuminate/support": "~5.2", + "kkszymanowski/traitor": "^0.2.0", + "php": ">=5.5.9" + }, + "require-dev": { + "mockery/mockery": ">=0.9.9", + "orchestra/testbench": "~3.2", + "phpunit/phpunit": ">=4.1" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Laratrust\\LaratrustServiceProvider" + ], + "aliases": { + "Laratrust": "Laratrust\\LaratrustFacade" + } + } + }, + "autoload": { + "psr-4": { + "Laratrust\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Santiago Garcia", + "homepage": "http://santigarcor.me" + } + ], + "description": "This package provides a flexible way to add Role-based Permissions to Laravel", + "keywords": [ + "Teams", + "acl", + "authorization", + "laratrust", + "laravel", + "multiusers", + "permissions", + "php", + "rbac", + "roles" + ], + "time": "2017-12-02T21:56:51+00:00" + }, { "name": "scriptfusion/phpunit-immediate-exception-printer", "version": "1.3.0", @@ -3863,7 +3977,7 @@ "src/" ] }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "BSD-3-Clause" ], @@ -4438,7 +4552,7 @@ "src/helpers.php" ] }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -4621,7 +4735,7 @@ "/Tests/" ] }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -4730,7 +4844,7 @@ "/Tests/" ] }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -4898,7 +5012,7 @@ "/Tests/" ] }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -4952,7 +5066,7 @@ "/Tests/" ] }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -5040,7 +5154,7 @@ "/Tests/" ] }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -5241,7 +5355,7 @@ "bootstrap.php" ] }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -5298,7 +5412,7 @@ "bootstrap.php" ] }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -5357,7 +5471,7 @@ "Resources/stubs" ] }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -5409,7 +5523,7 @@ "Symfony\\Polyfill\\Util\\": "" } }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -5464,7 +5578,7 @@ "/Tests/" ] }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -5521,7 +5635,7 @@ "/Tests/" ] }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -5604,7 +5718,7 @@ "/Tests/" ] }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -5688,7 +5802,7 @@ "/Tests/" ] }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -5756,7 +5870,7 @@ "/Tests/" ] }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -5821,7 +5935,7 @@ "/Tests/" ] }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -6014,7 +6128,7 @@ "Tivie\\OS\\": "src/" } }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "APACHE 2.0" ], @@ -6235,7 +6349,7 @@ "Webpatser\\Uuid": "src/" } }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -6364,7 +6478,7 @@ "src/helper.php" ] }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -6421,7 +6535,7 @@ "Zend\\Diactoros\\": "src/" } }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "BSD-2-Clause" ], @@ -6433,74 +6547,6 @@ "psr-7" ], "time": "2017-10-12T15:24:51+00:00" - }, - { - "name": "zizaco/entrust", - "version": "5.2.x-dev", - "source": { - "type": "git", - "url": "https://github.com/Zizaco/entrust.git", - "reference": "3623cc052937d9e62543402b50f24065720d44b9" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/Zizaco/entrust/zipball/3623cc052937d9e62543402b50f24065720d44b9", - "reference": "3623cc052937d9e62543402b50f24065720d44b9", - "shasum": "" - }, - "require": { - "illuminate/cache": "~5.0", - "illuminate/console": "~5.0", - "illuminate/support": "~5.0", - "php": ">=5.5.0" - }, - "require-dev": { - "illuminate/database": "~5.0", - "mockery/mockery": "dev-master", - "phpunit/phpunit": "~4.1", - "sami/sami": "dev-master" - }, - "type": "library", - "autoload": { - "classmap": [ - "src/commands" - ], - "psr-4": { - "Zizaco\\Entrust\\": "src/Entrust/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Andrew Elkins", - "homepage": "http://andrewelkins.com" - }, - { - "name": "Zizaco Zizuini", - "email": "zizaco@gmail.com" - }, - { - "name": "Ben Batschelet", - "homepage": "http://github.com/bbatsche" - }, - { - "name": "Michele Angioni", - "email": "michele.angioni@gmail.com" - } - ], - "description": "This package provides a flexible way to add Role-based Permissions to Laravel", - "keywords": [ - "acl", - "auth", - "illuminate", - "laravel", - "permission", - "roles" - ], - "time": "2016-12-29T06:25:06+00:00" } ], "packages-dev": [ @@ -6715,7 +6761,7 @@ "Whoops\\": "src/Whoops/" } }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -7107,7 +7153,7 @@ "/Tests/" ] }, - "notification-url": "http://packagist.org/downloads/", + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -7131,7 +7177,6 @@ "stability-flags": { "infyomlabs/laravel-generator": 20, "infyomlabs/adminlte-templates": 20, - "zizaco/entrust": 20, "makinacorpus/php-bloom": 20, "nabeel/vacentral": 20 }, diff --git a/config/app.php b/config/app.php index 19a57ac8..8ba5a6a4 100755 --- a/config/app.php +++ b/config/app.php @@ -57,7 +57,6 @@ return [ Prettus\Repository\Providers\RepositoryServiceProvider::class, InfyOm\Generator\InfyOmGeneratorServiceProvider::class, InfyOm\AdminLTETemplates\AdminLTETemplatesServiceProvider::class, - Zizaco\Entrust\EntrustServiceProvider::class, Spatie\Fractal\FractalServiceProvider::class, SebastiaanLuca\Helpers\Methods\GlobalHelpersServiceProvider::class, SebastiaanLuca\Helpers\Collections\CollectionMacrosServiceProvider::class, @@ -86,7 +85,6 @@ return [ 'Crypt' => Illuminate\Support\Facades\Crypt::class, 'DB' => Illuminate\Support\Facades\DB::class, 'Eloquent' => Illuminate\Database\Eloquent\Model::class, - 'Entrust' => Zizaco\Entrust\EntrustFacade::class, 'Event' => Illuminate\Support\Facades\Event::class, 'File' => Illuminate\Support\Facades\File::class, 'Flash' => Laracasts\Flash\Flash::class, diff --git a/config/entrust.php b/config/entrust.php deleted file mode 100644 index 55635637..00000000 --- a/config/entrust.php +++ /dev/null @@ -1,92 +0,0 @@ - 'App\Models\Role', - - /* - |-------------------------------------------------------------------------- - | Entrust Roles Table - |-------------------------------------------------------------------------- - | - | This is the roles table used by Entrust to save roles to the database. - | - */ - 'roles_table' => 'roles', - - /* - |-------------------------------------------------------------------------- - | Entrust Permission Model - |-------------------------------------------------------------------------- - | - | This is the Permission model used by Entrust to create correct relations. - | Update the permission if it is in a different namespace. - | - */ - 'permission' => 'App\Models\Permission', - - /* - |-------------------------------------------------------------------------- - | Entrust Permissions Table - |-------------------------------------------------------------------------- - | - | This is the permissions table used by Entrust to save permissions to the - | database. - | - */ - 'permissions_table' => 'permissions', - - /* - |-------------------------------------------------------------------------- - | Entrust permission_role Table - |-------------------------------------------------------------------------- - | - | This is the permission_role table used by Entrust to save relationship - | between permissions and roles to the database. - | - */ - 'permission_role_table' => 'permission_role', - - /* - |-------------------------------------------------------------------------- - | Entrust role_user Table - |-------------------------------------------------------------------------- - | - | This is the role_user table used by Entrust to save assigned roles to the - | database. - | - */ - 'role_user_table' => 'role_user', - - /* - |-------------------------------------------------------------------------- - | User Foreign key on Entrust's role_user Table (Pivot) - |-------------------------------------------------------------------------- - */ - 'user_foreign_key' => 'user_id', - - /* - |-------------------------------------------------------------------------- - | Role Foreign key on Entrust's role_user Table (Pivot) - |-------------------------------------------------------------------------- - */ - 'role_foreign_key' => 'role_id', - -]; diff --git a/config/laratrust.php b/config/laratrust.php new file mode 100644 index 00000000..c4151f11 --- /dev/null +++ b/config/laratrust.php @@ -0,0 +1,210 @@ + false, + + /* + |-------------------------------------------------------------------------- + | Use cache in the package + |-------------------------------------------------------------------------- + | + | Defines if Laratrust will use Laravel's Cache to cache the roles and permissions. + | + */ + 'use_cache' => true, + + /* + |-------------------------------------------------------------------------- + | Use teams feature in the package + |-------------------------------------------------------------------------- + | + | Defines if Laratrust will use the teams feature. + | Please check the docs to see what you need to do in case you have the package already configured. + | + */ + 'use_teams' => false, + + /* + |-------------------------------------------------------------------------- + | Strict check for roles/permissions inside teams + |-------------------------------------------------------------------------- + | + | Determines if a strict check should be done when checking if a role or permission + | is attached inside a team. + | If it's false, when checking a role/permission without specifying the team, + | it will check only if the user has attached that role/permission ignoring the team. + | + */ + 'teams_strict_check' => false, + + /* + |-------------------------------------------------------------------------- + | Laratrust User Models + |-------------------------------------------------------------------------- + | + | This is the array that contains the information of the user models. + | This information is used in the add-trait command, and for the roles and + | permissions relationships with the possible user models. + | + | The key in the array is the name of the relationship inside the roles and permissions. + | + */ + 'user_models' => [ + 'users' => 'App\Models\User', + ], + + /* + |-------------------------------------------------------------------------- + | Laratrust Models + |-------------------------------------------------------------------------- + | + | These are the models used by Laratrust to define the roles, permissions and teams. + | If you want the Laratrust models to be in a different namespace or + | to have a different name, you can do it here. + | + */ + 'models' => [ + /** + * Role model + */ + 'role' => 'App\Models\Role', + + /** + * Permission model + */ + 'permission' => 'App\Models\Permission', + + /** + * Team model + */ + 'team' => 'App\Team', + + ], + + /* + |-------------------------------------------------------------------------- + | Laratrust Tables + |-------------------------------------------------------------------------- + | + | These are the tables used by Laratrust to store all the authorization data. + | + */ + 'tables' => [ + /** + * Roles table. + */ + 'roles' => 'roles', + + /** + * Permissions table. + */ + 'permissions' => 'permissions', + + /** + * Teams table. + */ + 'teams' => 'teams', + + /** + * Role - User intermediate table. + */ + 'role_user' => 'role_user', + + /** + * Permission - User intermediate table. + */ + 'permission_user' => 'permission_user', + + /** + * Permission - Role intermediate table. + */ + 'permission_role' => 'permission_role', + + ], + + /* + |-------------------------------------------------------------------------- + | Laratrust Foreign Keys + |-------------------------------------------------------------------------- + | + | These are the foreign keys used by laratrust in the intermediate tables. + | + */ + 'foreign_keys' => [ + /** + * User foreign key on Laratrust's role_user and permission_user tables. + */ + 'user' => 'user_id', + + /** + * Role foreign key on Laratrust's role_user and permission_role tables. + */ + 'role' => 'role_id', + + /** + * Role foreign key on Laratrust's permission_user and permission_role tables. + */ + 'permission' => 'permission_id', + + /** + * Role foreign key on Laratrust's role_user and permission_user tables. + */ + 'team' => 'team_id', + + ], + + /* + |-------------------------------------------------------------------------- + | Laratrust Middleware + |-------------------------------------------------------------------------- + | + | This configuration helps to customize the Laratrust middleware behavior. + | + */ + 'middleware' => [ + /** + * Define if the laratrust middleware are registered automatically in the service provider + */ + 'register' => true, + + /** + * Method to be called in the middleware return case. + * Available: abort|redirect + */ + 'handling' => 'abort', + + /** + * Parameter passed to the middleware_handling method + */ + 'params' => '403', + + ], + + /* + |-------------------------------------------------------------------------- + | Laratrust Magic 'can' Method + |-------------------------------------------------------------------------- + | + | Supported cases for the magic can method (Refer to the docs). + | Available: camel_case|snake_case|kebab_case + | + */ + 'magic_can_method_case' => 'kebab_case', +]; diff --git a/modules/Installer/Services/EnvironmentService.php b/modules/Installer/Services/EnvironmentService.php index 0f0817a6..d0a06fa5 100644 --- a/modules/Installer/Services/EnvironmentService.php +++ b/modules/Installer/Services/EnvironmentService.php @@ -51,7 +51,11 @@ class EnvironmentService if(\extension_loaded('apc')) { $opts['CACHE_DRIVER'] = 'apc'; } else { - $opts['CACHE_DRIVER'] = 'array'; + if($opts['APP_ENV'] === 'dev') { + $opts['CACHE_DRIVER'] = 'array'; + } else { + $opts['CACHE_DRIVER'] = 'file'; + } } return $opts; diff --git a/resources/views/layouts/default/app.blade.php b/resources/views/layouts/default/app.blade.php index 8930ee1e..8181e186 100644 --- a/resources/views/layouts/default/app.blade.php +++ b/resources/views/layouts/default/app.blade.php @@ -95,14 +95,15 @@

Profile

- @if(Entrust::hasRole('admin')) + + @role('admin') - @endif + @endrole {{-- Show the module links for being logged out --}} @foreach($moduleSvc->getFrontendLinks($logged_in=true) as &$link) diff --git a/tests/data/base.yml b/tests/data/base.yml index 8d0dd17d..98aad8ae 100644 --- a/tests/data/base.yml +++ b/tests/data/base.yml @@ -24,8 +24,10 @@ users: role_user: - user_id: 1 role_id: 1 + user_type: App\Models\User - user_id: 1 role_id: 2 + user_type: App\Models\User ranks: - id: 1