0
0
Fork 0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-05-06 17:20:07 +00:00

Started work towards adding role view permissions

Work halted as re-write required.
In reference to 
This commit is contained in:
Dan Brown 2016-04-09 12:40:07 +01:00
parent 1a7de4c2d6
commit 6e03078de3
5 changed files with 73 additions and 5 deletions

View file

@ -0,0 +1,54 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddViewPermissionsToRoles extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$currentRoles = \BookStack\Role::all();
// Create new view permissions
$entities = ['Book', 'Page', 'Chapter'];
$ops = ['View All', 'View Own'];
foreach ($entities as $entity) {
foreach ($ops as $op) {
$newPermission = new \BookStack\Permission();
$newPermission->name = strtolower($entity) . '-' . strtolower(str_replace(' ', '-', $op));
$newPermission->display_name = $op . ' ' . $entity . 's';
$newPermission->save();
foreach ($currentRoles as $role) {
$role->attachPermission($newPermission);
}
}
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
// Delete the new view permissions
$entities = ['Book', 'Page', 'Chapter'];
$ops = ['View All', 'View Own'];
foreach ($entities as $entity) {
foreach ($ops as $op) {
$permissionName = strtolower($entity) . '-' . strtolower(str_replace(' ', '-', $op));
$newPermission = \BookStack\Permission::where('name', '=', $permissionName)->first();
foreach ($newPermission->roles as $role) {
$role->detachPermission($newPermission);
}
$newPermission->delete();
}
}
}
}