Merge roles and user_roles tables for new permission system

This commit is contained in:
DariusIII
2018-06-27 10:02:44 +02:00
parent eab2df3ad8
commit 8618e5e896
6 changed files with 114 additions and 52 deletions
+1
View File
@@ -1,4 +1,5 @@
2018-06-27 DariusIII
* Chg: Merge roles and user_roles tables for new permission system
* Chg: Update Movie processing handling
2018-06-26 DariusIII
* Chg: Add HasRole trait to User model
+88
View File
@@ -0,0 +1,88 @@
<?php
return [
'models' => [
/*
* When using the "HasRoles" trait from this package, we need to know which
* Eloquent model should be used to retrieve your permissions. Of course, it
* is often just the "Permission" model but you may use whatever you like.
*
* The model you want to use as a Permission model needs to implement the
* `Spatie\Permission\Contracts\Permission` contract.
*/
'permission' => Spatie\Permission\Models\Permission::class,
/*
* When using the "HasRoles" trait from this package, we need to know which
* Eloquent model should be used to retrieve your roles. Of course, it
* is often just the "Role" model but you may use whatever you like.
*
* The model you want to use as a Role model needs to implement the
* `Spatie\Permission\Contracts\Role` contract.
*/
'role' => Spatie\Permission\Models\Role::class,
],
'table_names' => [
/*
* When using the "HasRoles" trait from this package, we need to know which
* table should be used to retrieve your roles. We have chosen a basic
* default value but you may easily change it to any table you like.
*/
'roles' => 'roles',
/*
* When using the "HasRoles" trait from this package, we need to know which
* table should be used to retrieve your permissions. We have chosen a basic
* default value but you may easily change it to any table you like.
*/
'permissions' => 'permissions',
/*
* When using the "HasRoles" trait from this package, we need to know which
* table should be used to retrieve your models permissions. We have chosen a
* basic default value but you may easily change it to any table you like.
*/
'model_has_permissions' => 'model_has_permissions',
/*
* When using the "HasRoles" trait from this package, we need to know which
* table should be used to retrieve your models roles. We have chosen a
* basic default value but you may easily change it to any table you like.
*/
'model_has_roles' => 'model_has_roles',
/*
* When using the "HasRoles" trait from this package, we need to know which
* table should be used to retrieve your roles permissions. We have chosen a
* basic default value but you may easily change it to any table you like.
*/
'role_has_permissions' => 'role_has_permissions',
],
/*
* By default all permissions will be cached for 24 hours unless a permission or
* role is updated. Then the cache will be flushed immediately.
*/
'cache_expiration_time' => 60 * 24,
/*
* When set to true, the required permission/role names are added to the exception
* message. This could be considered an information leak in some contexts, so
* the default setting is false here for optimum safety.
*/
'display_permission_in_exception' => false,
];
@@ -2,7 +2,6 @@
return [
0 => [
'id' => 1,
'name' => 'User',
'apirequests' => 10,
'downloadrequests' => 10,
@@ -14,7 +13,6 @@ return [
'addyears' => 0,
],
1 => [
'id' => 2,
'name' => 'Admin',
'apirequests' => 1000,
'downloadrequests' => 1000,
@@ -26,7 +24,6 @@ return [
'addyears' => 0,
],
2 => [
'id' => 3,
'name' => 'Disabled',
'apirequests' => 0,
'downloadrequests' => 0,
@@ -38,7 +35,6 @@ return [
'addyears' => 0,
],
3 => [
'id' => 4,
'name' => 'Moderator',
'apirequests' => 1000,
'downloadrequests' => 1000,
@@ -50,7 +46,6 @@ return [
'addyears' => 0,
],
4 => [
'id' => 5,
'name' => 'Friend',
'apirequests' => 100,
'downloadrequests' => 100,
@@ -23,11 +23,9 @@ class CreateUsersTable extends Migration {
$table->string('lastname')->nullable();
$table->string('email');
$table->string('password');
$table->integer('user_roles_id')->default(1)->index('ix_user_roles')->comment('FK to user_roles.id');
$table->string('host', 40)->nullable();
$table->integer('grabs')->default(0);
$table->string('api_token', 64);
$table->timestamps();
$table->string('resetguid', 50)->nullable();
$table->dateTime('lastlogin')->nullable();
$table->dateTime('apiaccess')->nullable();
@@ -59,6 +57,7 @@ class CreateUsersTable extends Migration {
$table->boolean('verified')->default(false);
$table->string('verification_token')->nullable();
$table->rememberToken();
$table->timestamps();
});
}
@@ -16,6 +16,9 @@ class CreatePermissionTables extends Migration
$tableNames = config('permission.table_names');
Schema::create($tableNames['permissions'], function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->charset = 'utf8';
$table->collation = 'utf8_unicode_ci';
$table->increments('id');
$table->string('name');
$table->string('guard_name');
@@ -23,13 +26,28 @@ class CreatePermissionTables extends Migration
});
Schema::create($tableNames['roles'], function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->charset = 'utf8';
$table->collation = 'utf8_unicode_ci';
$table->increments('id');
$table->string('name');
$table->string('guard_name');
$table->integer('apirequests')->unsigned();
$table->integer('rate_limit')->default(60);
$table->integer('downloadrequests')->unsigned();
$table->integer('defaultinvites')->unsigned();
$table->boolean('isdefault')->default(0);
$table->boolean('canpreview')->default(0);
$table->boolean('hideads')->default(0);
$table->integer('donation')->default(0);
$table->integer('addyears')->default(0);
$table->timestamps();
});
Schema::create($tableNames['model_has_permissions'], function (Blueprint $table) use ($tableNames) {
$table->engine = 'InnoDB';
$table->charset = 'utf8';
$table->collation = 'utf8_unicode_ci';
$table->unsignedInteger('permission_id');
$table->morphs('model');
@@ -42,6 +60,9 @@ class CreatePermissionTables extends Migration
});
Schema::create($tableNames['model_has_roles'], function (Blueprint $table) use ($tableNames) {
$table->engine = 'InnoDB';
$table->charset = 'utf8';
$table->collation = 'utf8_unicode_ci';
$table->unsignedInteger('role_id');
$table->morphs('model');
@@ -54,6 +75,9 @@ class CreatePermissionTables extends Migration
});
Schema::create($tableNames['role_has_permissions'], function (Blueprint $table) use ($tableNames) {
$table->engine = 'InnoDB';
$table->charset = 'utf8';
$table->collation = 'utf8_unicode_ci';
$table->unsignedInteger('permission_id');
$table->unsignedInteger('role_id');
@@ -1,45 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateUserRolesTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('user_roles', function(Blueprint $table)
{
$table->engine = 'InnoDB';
$table->charset = 'utf8';
$table->collation = 'utf8_unicode_ci';
$table->integer('id', true);
$table->string('name', 32);
$table->integer('apirequests')->unsigned();
$table->integer('rate_limit')->default(60);
$table->integer('downloadrequests')->unsigned();
$table->integer('defaultinvites')->unsigned();
$table->boolean('isdefault')->default(0);
$table->boolean('canpreview')->default(0);
$table->boolean('hideads')->default(0);
$table->integer('donation')->default(0);
$table->integer('addyears')->default(0);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('user_roles');
}
}