BUB-17 Aggiunto gruppi e ACL per laravel
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreatePermissionsTable extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
$permissionsTable = config('acl.tables.permissions', 'permissions');
|
||||
Schema::create($permissionsTable, function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('name');
|
||||
$table->string('guard_name');
|
||||
$table->text('description')->nullable();
|
||||
$table->softDeletes();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['name', 'guard_name']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
$tables = config('acl.tables');
|
||||
Schema::dropIfExists($tables['permissions']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateGroupsTable extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
$groupsTable = config('acl.tables.groups', 'groups');
|
||||
$teams = config('acl.teams');
|
||||
$columnNames = config('acl.column_names');
|
||||
|
||||
Schema::create($groupsTable, function (Blueprint $table) use ($teams, $columnNames) {
|
||||
$table->bigIncrements('id');
|
||||
|
||||
if ($teams || config("acl.testing")) {
|
||||
$table->unsignedBigInteger($columnNames['team_foreign_key'])->nullable();
|
||||
$table->index($columnNames['team_foreign_key'], 'groups_team_foreign_key_index');
|
||||
}
|
||||
|
||||
$table->string('name');
|
||||
$table->string('guard_name');
|
||||
$table->text('description')->nullable();
|
||||
$table->softDeletes();
|
||||
$table->timestamps();
|
||||
|
||||
if ($teams || config('acl.testing')) {
|
||||
$table->unique([$columnNames['team_foreign_key'], 'name', 'guard_name']);
|
||||
} else {
|
||||
$table->unique(['name', 'guard_name']);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
$groupsTable = config('acl.tables.groups', 'groups');
|
||||
Schema::dropIfExists($groupsTable);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Junges\ACL\AclRegistrar;
|
||||
|
||||
class CreateModelHasPermissionsTable extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
$columnNames = config('acl.column_names');
|
||||
|
||||
$modelHasPermissions = config('acl.tables.model_has_permissions', 'model_has_permissions');
|
||||
$permissionsTable = config('acl.tables.permissions', 'permissions');
|
||||
$teams = config('acl.teams');
|
||||
|
||||
Schema::create($modelHasPermissions, function (Blueprint $table) use ($permissionsTable, $columnNames, $teams) {
|
||||
$table->unsignedBigInteger(AclRegistrar::$pivotPermission);
|
||||
$table->string('model_type');
|
||||
$table->unsignedBigInteger($columnNames['model_morph_key']);
|
||||
$table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_permissions_id_model_type_index');
|
||||
|
||||
$table->foreign(AclRegistrar::$pivotPermission)
|
||||
->references('id')
|
||||
->on($permissionsTable)
|
||||
->cascadeOnDelete();
|
||||
|
||||
if ($teams) {
|
||||
$table->unsignedBigInteger($columnNames['team_foreign_key']);
|
||||
$table->index($columnNames['team_foreign_key'], 'model_has_permissions_team_foreign_key_index');
|
||||
|
||||
$table->primary([$columnNames['team_foreign_key'], AclRegistrar::$pivotPermission, $columnNames['model_morph_key'], 'model_type'],
|
||||
'model_has_permissions_permission_model_type_primary');
|
||||
} else {
|
||||
$table->primary([AclRegistrar::$pivotPermission, $columnNames['model_morph_key'], 'model_type'],
|
||||
'model_has_permissions_permission_model_type_primary');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
$modelHasPermissionTable = config('acl.tables.model_has_permissions', 'model_has_permissions');
|
||||
Schema::dropIfExists($modelHasPermissionTable);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Junges\ACL\AclRegistrar;
|
||||
|
||||
class CreateModelHasGroupsTable extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
$columnNames = config('acl.column_names');
|
||||
$modelHasGroups = config('acl.tables.model_has_groups', 'model_has_groups');
|
||||
$groupsTable = config('acl.tables.groups', 'groups');
|
||||
$teams = config('acl.teams');
|
||||
|
||||
Schema::create($modelHasGroups, function (Blueprint $table) use ($groupsTable, $columnNames, $teams) {
|
||||
$table->unsignedBigInteger(AclRegistrar::$pivotGroup);
|
||||
|
||||
$table->string('model_type');
|
||||
$table->unsignedBigInteger($columnNames['model_morph_key']);
|
||||
$table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_groups_model_id_model_type_index');
|
||||
|
||||
$table->foreign(AclRegistrar::$pivotGroup)
|
||||
->references('id')
|
||||
->on($groupsTable)
|
||||
->cascadeOnDelete();
|
||||
|
||||
if ($teams) {
|
||||
$table->unsignedBigInteger($columnNames['team_foreign_key']);
|
||||
$table->index($columnNames['team_foreign_key'], 'model_has_groups_team_foreign_key_index');
|
||||
|
||||
$table->primary([$columnNames['team_foreign_key'], AclRegistrar::$pivotGroup, $columnNames['model_morph_key'], 'model_type'],
|
||||
'model_has_groups_group_model_type_primary');
|
||||
} else {
|
||||
$table->primary([AclRegistrar::$pivotGroup, $columnNames['model_morph_key'], 'model_type'],
|
||||
'model_has_groups_group_model_type_primary');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
$modelHasGroupsTable = config('acl.tables.model_has_groups', 'model_has_groups');
|
||||
Schema::dropIfExists($modelHasGroupsTable);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Junges\ACL\AclRegistrar;
|
||||
|
||||
class CreateGroupHasPermissionsTable extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
$groupHasPermissionTable = config('acl.tables.group_has_permissions', 'group_has_permissions');
|
||||
$groupsTable = config('acl.tables.groups', 'groups');
|
||||
$permissionsTable = config('acl.tables.permissions', 'permissions');
|
||||
|
||||
Schema::create($groupHasPermissionTable, function (Blueprint $table) use ($groupsTable, $permissionsTable) {
|
||||
$table->unsignedBigInteger(AclRegistrar::$pivotPermission);
|
||||
$table->unsignedBigInteger(AclRegistrar::$pivotGroup);
|
||||
|
||||
$table->foreign(AclRegistrar::$pivotPermission)
|
||||
->references('id')
|
||||
->on($permissionsTable)
|
||||
->cascadeOnDelete();
|
||||
|
||||
$table->foreign(AclRegistrar::$pivotGroup)
|
||||
->references('id')
|
||||
->on($groupsTable)
|
||||
->cascadeOnDelete();
|
||||
|
||||
$table->primary([AclRegistrar::$pivotPermission, AclRegistrar::$pivotGroup], 'group_has_permission_permission_id_group_id_primary');
|
||||
});
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
$groupHasPermissionsTable = config('acl.tables.group_has_permissions', 'group_has_permissions');
|
||||
|
||||
Schema::dropIfExists($groupHasPermissionsTable);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user