Add base things for roles.
This commit is contained in:
parent
8d90699f40
commit
e120d26cbf
7 changed files with 146 additions and 3 deletions
|
@ -51,7 +51,6 @@ class CreateSessionsTable extends Migration
|
||||||
public function down()
|
public function down()
|
||||||
{
|
{
|
||||||
$schema = Database::connection()->getSchemaBuilder();
|
$schema = Database::connection()->getSchemaBuilder();
|
||||||
$schema->drop('sessions');
|
|
||||||
|
|
||||||
$schema->table('users', function (Blueprint $table) {
|
$schema->table('users', function (Blueprint $table) {
|
||||||
$table->integer('user_registered')
|
$table->integer('user_registered')
|
||||||
|
@ -61,5 +60,7 @@ class CreateSessionsTable extends Migration
|
||||||
$table->dropSoftDeletes();
|
$table->dropSoftDeletes();
|
||||||
$table->dropTimestamps();
|
$table->dropTimestamps();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$schema->drop('sessions');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
90
database/2018_02_11_135554_create_roles_tables.php
Normal file
90
database/2018_02_11_135554_create_roles_tables.php
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
<?php
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Misuzu\Database;
|
||||||
|
|
||||||
|
// phpcs:disable
|
||||||
|
class CreateRolesTables extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @SuppressWarnings(PHPMD)
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
$schema = Database::connection()->getSchemaBuilder();
|
||||||
|
$schema->create('roles', function (Blueprint $table) {
|
||||||
|
$table->increments('role_id');
|
||||||
|
|
||||||
|
$table->integer('role_hierarchy')
|
||||||
|
->default(1);
|
||||||
|
|
||||||
|
$table->string('role_name', 255);
|
||||||
|
|
||||||
|
$table->string('role_title', 64)
|
||||||
|
->nullable();
|
||||||
|
|
||||||
|
$table->text('role_description')
|
||||||
|
->nullable();
|
||||||
|
|
||||||
|
$table->boolean('role_secret')
|
||||||
|
->default(false);
|
||||||
|
|
||||||
|
$table->integer('role_colour')
|
||||||
|
->nullable()
|
||||||
|
->default(null);
|
||||||
|
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
|
||||||
|
$schema->create('user_roles', function (Blueprint $table) {
|
||||||
|
$table->integer('user_id')
|
||||||
|
->unsigned();
|
||||||
|
|
||||||
|
$table->integer('role_id')
|
||||||
|
->unsigned();
|
||||||
|
|
||||||
|
$table->primary(['user_id', 'role_id']);
|
||||||
|
|
||||||
|
$table->foreign('user_id')
|
||||||
|
->references('user_id')
|
||||||
|
->on('users')
|
||||||
|
->onUpdate('cascade')
|
||||||
|
->onDelete('cascade');
|
||||||
|
|
||||||
|
$table->foreign('role_id')
|
||||||
|
->references('role_id')
|
||||||
|
->on('roles')
|
||||||
|
->onUpdate('cascade')
|
||||||
|
->onDelete('cascade');
|
||||||
|
});
|
||||||
|
|
||||||
|
$schema->table('users', function (Blueprint $table) {
|
||||||
|
$table->integer('display_role')
|
||||||
|
->unsigned()
|
||||||
|
->nullable()
|
||||||
|
->default(null);
|
||||||
|
|
||||||
|
$table->foreign('display_role')
|
||||||
|
->references('role_id')
|
||||||
|
->on('roles')
|
||||||
|
->onUpdate('cascade')
|
||||||
|
->onDelete('set null');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @SuppressWarnings(PHPMD)
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
$schema = Database::connection()->getSchemaBuilder();
|
||||||
|
|
||||||
|
$schema->table('users', function (Blueprint $table) {
|
||||||
|
$table->dropForeign(['display_role']);
|
||||||
|
$table->dropColumn('display_role');
|
||||||
|
});
|
||||||
|
|
||||||
|
$schema->drop('user_roles');
|
||||||
|
$schema->drop('roles');
|
||||||
|
}
|
||||||
|
}
|
|
@ -86,9 +86,9 @@ class Colour
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __construct(int $raw)
|
public function __construct(?int $raw)
|
||||||
{
|
{
|
||||||
$this->rawValue = $raw;
|
$this->rawValue = $raw ?? self::INHERIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function fromRGB(int $red, int $green, int $blue): Colour
|
public static function fromRGB(int $red, int $green, int $blue): Colour
|
||||||
|
|
14
src/Users/Role.php
Normal file
14
src/Users/Role.php
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
<?php
|
||||||
|
namespace Misuzu\Users;
|
||||||
|
|
||||||
|
use Misuzu\Model;
|
||||||
|
|
||||||
|
class Role extends Model
|
||||||
|
{
|
||||||
|
protected $primaryKey = 'role_id';
|
||||||
|
|
||||||
|
public function users()
|
||||||
|
{
|
||||||
|
return $this->hasMany(UserRole::class, 'role_id');
|
||||||
|
}
|
||||||
|
}
|
|
@ -72,4 +72,9 @@ class User extends Model
|
||||||
{
|
{
|
||||||
return $this->hasMany(Session::class, 'user_id');
|
return $this->hasMany(Session::class, 'user_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function roles()
|
||||||
|
{
|
||||||
|
return $this->hasMany(UserRole::class, 'user_id');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
21
src/Users/UserRole.php
Normal file
21
src/Users/UserRole.php
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
<?php
|
||||||
|
namespace Misuzu\Users;
|
||||||
|
|
||||||
|
use Misuzu\Model;
|
||||||
|
|
||||||
|
class UserRole extends Model
|
||||||
|
{
|
||||||
|
protected $primaryKey = null;
|
||||||
|
public $incrementing = false;
|
||||||
|
public $timestamps = false;
|
||||||
|
|
||||||
|
public function user()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class, 'user_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function role()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Role::class, 'role_id');
|
||||||
|
}
|
||||||
|
}
|
|
@ -33,6 +33,18 @@ class ColourTest extends TestCase
|
||||||
$this->assertEquals($colour->hex, '000000');
|
$this->assertEquals($colour->hex, '000000');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testNull()
|
||||||
|
{
|
||||||
|
$colour = new Colour(null);
|
||||||
|
|
||||||
|
$this->assertTrue($colour->inherit);
|
||||||
|
$this->assertEquals($colour->raw, 0x40000000);
|
||||||
|
$this->assertEquals($colour->red, 0);
|
||||||
|
$this->assertEquals($colour->green, 0);
|
||||||
|
$this->assertEquals($colour->blue, 0);
|
||||||
|
$this->assertEquals($colour->hex, '000000');
|
||||||
|
}
|
||||||
|
|
||||||
public function testFromRaw()
|
public function testFromRaw()
|
||||||
{
|
{
|
||||||
$colour = new Colour(static::RAW_HEX6);
|
$colour = new Colour(static::RAW_HEX6);
|
||||||
|
|
Loading…
Add table
Reference in a new issue