New user groups and memberships

This commit is contained in:
James Cole
2021-08-28 15:47:33 +02:00
parent a14c9438ad
commit 10787aada8
12 changed files with 483 additions and 8 deletions

View File

@@ -0,0 +1,74 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
/**
* Class UserGroups
*/
class UserGroups extends Migration
{
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('group_memberships');
Schema::dropIfExists('user_roles');
Schema::dropIfExists('user_groups');
}
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
/*
* user is a member of a user_group through a user_group_role
* may have multiple roles in a group
*/
Schema::create(
'user_groups', static function (Blueprint $table) {
$table->bigIncrements('id');
$table->timestamps();
$table->softDeletes();
$table->string('title', 255);
$table->unique('title');
}
);
Schema::create(
'user_roles', static function (Blueprint $table) {
$table->bigIncrements('id');
$table->timestamps();
$table->softDeletes();
$table->string('title', 255);
$table->unique('title');
}
);
Schema::create(
'group_memberships',
static function (Blueprint $table) {
$table->bigIncrements('id');
$table->timestamps();
$table->softDeletes();
$table->integer('user_id', false, true);
$table->bigInteger('user_group_id', false, true);
$table->bigInteger('user_role_id', false, true);
$table->foreign('user_id')->references('id')->on('users')->onUpdate('cascade')->onDelete('cascade');
$table->foreign('user_group_id')->references('id')->on('user_groups')->onUpdate('cascade')->onDelete('cascade');
$table->foreign('user_role_id')->references('id')->on('user_roles')->onUpdate('cascade')->onDelete('cascade');
$table->unique(['user_id', 'user_group_id', 'user_role_id']);
}
);
}
}

View File

@@ -40,5 +40,6 @@ class DatabaseSeeder extends Seeder
$this->call(PermissionSeeder::class);
$this->call(LinkTypeSeeder::class);
$this->call(ConfigSeeder::class);
$this->call(UserRoleSeeder::class);
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace Database\Seeders;
use FireflyIII\Models\UserRole;
use Illuminate\Database\Seeder;
use PDOEXception;
/**
* Class UserRoleSeeder
*/
class UserRoleSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$roles = [
UserRole::READ_ONLY,
UserRole::CHANGE_TRANSACTIONS,
UserRole::CHANGE_RULES,
UserRole::CHANGE_PIGGY_BANKS,
UserRole::CHANGE_REPETITIONS,
UserRole::VIEW_REPORTS,
UserRole::FULL,
];
/** @var string $role */
foreach ($roles as $role) {
try {
UserRole::create(['title' => $role]);
} catch (PDOException $e) {
// @ignoreException
}
}
}
}