-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Conflicts: app/models/User.php composer.json
- Loading branch information
Showing
14 changed files
with
257 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
app/database/migrations/2014_04_03_015654_entrust_setup_tables.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
|
||
class EntrustSetupTables extends Migration { | ||
|
||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::drop('role_user'); | ||
Schema::drop('roles'); | ||
|
||
|
||
// Creates the roles table | ||
Schema::create('roles', function($table) | ||
{ | ||
$table->increments('id')->unsigned(); | ||
$table->string('name')->unique(); | ||
$table->timestamps(); | ||
}); | ||
|
||
// Creates the assigned_roles (Many-to-Many relation) table | ||
Schema::create('assigned_roles', function($table) | ||
{ | ||
$table->increments('id')->unsigned(); | ||
$table->integer('user_id')->unsigned(); | ||
$table->integer('role_id')->unsigned(); | ||
$table->foreign('user_id')->references('id')->on('users'); // assumes a users table | ||
$table->foreign('role_id')->references('id')->on('roles'); | ||
}); | ||
|
||
// Creates the permissions table | ||
Schema::create('permissions', function($table) | ||
{ | ||
$table->increments('id')->unsigned(); | ||
$table->string('name'); | ||
$table->string('display_name'); | ||
$table->timestamps(); | ||
}); | ||
|
||
// Creates the permission_role (Many-to-Many relation) table | ||
Schema::create('permission_role', function($table) | ||
{ | ||
$table->increments('id')->unsigned(); | ||
$table->integer('permission_id')->unsigned(); | ||
$table->integer('role_id')->unsigned(); | ||
$table->foreign('permission_id')->references('id')->on('permissions'); // assumes a users table | ||
$table->foreign('role_id')->references('id')->on('roles'); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::table('assigned_roles', function(Blueprint $table) { | ||
$table->dropForeign('assigned_roles_user_id_foreign'); | ||
$table->dropForeign('assigned_roles_role_id_foreign'); | ||
}); | ||
|
||
Schema::table('permission_role', function(Blueprint $table) { | ||
$table->dropForeign('permission_role_permission_id_foreign'); | ||
$table->dropForeign('permission_role_role_id_foreign'); | ||
}); | ||
|
||
Schema::drop('assigned_roles'); | ||
Schema::drop('permission_role'); | ||
Schema::drop('roles'); | ||
Schema::drop('permissions'); | ||
|
||
Schema::create('roles', function($table){ | ||
$table->increments('id'); | ||
$table->string('label'); | ||
$table->string('permissions'); | ||
$table->timestamps(); | ||
}); | ||
|
||
Schema::create('role_user', function($table){ | ||
$table->integer('role_id')->unsigned(); | ||
$table->integer('user_id')->unsigned(); | ||
$table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade'); | ||
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); | ||
}); | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
app/database/migrations/2014_04_03_064948_drop_user_level_column.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
class DropUserLevelColumn extends Migration { | ||
|
||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::table('users', function($table) { | ||
$table->dropColumn('user_level'); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
throw new Exception("Cannot roll back this migration"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Seeder; | ||
|
||
class RbacSeeder extends Seeder | ||
{ | ||
private $adminPermissions = array( | ||
'ManageDocuments' => array( | ||
'name' => 'admin_manage_documents', | ||
'display_name' => 'Manage Documents', | ||
), | ||
'ManageSettings' => array( | ||
'name' => 'admin_manage_settings', | ||
'display_name' => "Manage Settings" | ||
), | ||
'VerifyUsers' => array( | ||
'name' => "admin_verify_users", | ||
'display_name' => "Verify Users" | ||
) | ||
); | ||
|
||
public function run() | ||
{ | ||
$admin = new Role(); | ||
$admin->name = 'Admin'; | ||
$admin->save(); | ||
|
||
$permIds = array(); | ||
foreach($this->adminPermissions as $permClass => $data) { | ||
$perm = new Permission(); | ||
|
||
foreach($data as $key => $val) { | ||
$perm->$key = $val; | ||
} | ||
|
||
$perm->save(); | ||
|
||
$permIds[] = $perm->id; | ||
} | ||
|
||
$admin->perms()->sync($permIds); | ||
|
||
$user = User::where('email', '=', '[email protected]')->first(); | ||
$user->attachRole($admin); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Seeder; | ||
|
||
class UsersTableSeeder extends Seeder | ||
{ | ||
public function run() | ||
{ | ||
DB::table('users')->insert(array( | ||
'email' => '[email protected]', | ||
'password' => '$2y$10$uIX./LUQwWBW3Orqd.E7LOY8KdCHHkIM9dGmZe95lFlf0OrH8YzOK', | ||
'fname' => 'John', | ||
'lname' => 'Coggeshall', | ||
'user_level' => 1, | ||
'token' => '', | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
use Zizaco\Entrust\EntrustPermission; | ||
|
||
class Permission extends EntrustPermission {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
use Zizaco\Entrust\EntrustRole; | ||
|
||
class Role extends EntrustRole {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.