wip RBAC
This commit is contained in:
parent
9dc58f9f92
commit
5d94c9d92f
@ -2,14 +2,14 @@
|
|||||||
|
|
||||||
namespace App\Models\Enums;
|
namespace App\Models\Enums;
|
||||||
|
|
||||||
enum UserRole: int
|
enum UserRole: string
|
||||||
{
|
{
|
||||||
case Guest = 0;
|
case Guest = 'guest';
|
||||||
case Patient = 1;
|
case Patient = 'patient';
|
||||||
case ReferringPhysician = 2;
|
case ReferringPhysician = 'referring_physician';
|
||||||
case Technician = 3;
|
case Technician = 'technician';
|
||||||
case Radiologist = 4;
|
case Radiologist = 'radiologist';
|
||||||
case Associate = 5;
|
case Associate = 'associate';
|
||||||
case System = 6;
|
case SystemAgent = 'system_agent';
|
||||||
case Admin = 99;
|
case Admin = 'admin';
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace Database\Factories;
|
namespace Database\Factories;
|
||||||
|
|
||||||
use App\Models\Enums\UserRole;
|
|
||||||
use App\Models\Team;
|
use App\Models\Team;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
@ -38,7 +37,6 @@ public function definition(): array
|
|||||||
'email_verified_at' => fake()->dateTime(),
|
'email_verified_at' => fake()->dateTime(),
|
||||||
'last_seen_at' => fake()->dateTime(),
|
'last_seen_at' => fake()->dateTime(),
|
||||||
'phone' => fake()->phoneNumber(),
|
'phone' => fake()->phoneNumber(),
|
||||||
'user_role' => static::$role ??= UserRole::Guest->value,
|
|
||||||
'password' => static::$password ??= Hash::make('password'),
|
'password' => static::$password ??= Hash::make('password'),
|
||||||
'two_factor_secret' => null,
|
'two_factor_secret' => null,
|
||||||
'two_factor_recovery_codes' => null,
|
'two_factor_recovery_codes' => null,
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Models\Enums\UserRole;
|
|
||||||
use App\Models\Facility;
|
use App\Models\Facility;
|
||||||
use App\Models\Institute;
|
use App\Models\Institute;
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
@ -25,7 +24,6 @@ public function up(): void
|
|||||||
$table->string('email')->nullable()->index();
|
$table->string('email')->nullable()->index();
|
||||||
$table->timestamp('email_verified_at')->nullable();
|
$table->timestamp('email_verified_at')->nullable();
|
||||||
$table->string('password');
|
$table->string('password');
|
||||||
$table->unsignedTinyInteger('user_role')->default(UserRole::Guest->value);
|
|
||||||
$table->foreignId('current_team_id')->nullable();
|
$table->foreignId('current_team_id')->nullable();
|
||||||
$table->string('profile_photo_path')->nullable();
|
$table->string('profile_photo_path')->nullable();
|
||||||
$table->foreignIdFor(Institute::class)->nullable()->index();
|
$table->foreignIdFor(Institute::class)->nullable()->index();
|
||||||
|
@ -12,10 +12,13 @@ class RoleSeeder extends Seeder
|
|||||||
{
|
{
|
||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
$adm = SpatieRole::create(['name' => UserRole::Admin->name]);
|
foreach (UserRole::cases() as $role) {
|
||||||
$rad = SpatieRole::create(['name' => UserRole::Radiologist->name]);
|
SpatieRole::create(['name' => $role->value]);
|
||||||
$tech = SpatieRole::create(['name' => UserRole::Technician->name]);
|
}
|
||||||
$guest = SpatieRole::create(['name' => UserRole::Guest->name]);
|
$adm = SpatieRole::findByName(UserRole::Admin->value);
|
||||||
|
$rad = SpatieRole::findByName(UserRole::Radiologist->value);
|
||||||
|
$tech = SpatieRole::findByName(UserRole::Technician->value);
|
||||||
|
$guest = SpatieRole::findByName(UserRole::Guest->value);
|
||||||
|
|
||||||
foreach (Permission::cases() as $perm) {
|
foreach (Permission::cases() as $perm) {
|
||||||
SpatiePermission::create(['name' => $perm->value]);
|
SpatiePermission::create(['name' => $perm->value]);
|
||||||
@ -23,6 +26,7 @@ public function run(): void
|
|||||||
|
|
||||||
$rad->givePermissionTo([
|
$rad->givePermissionTo([
|
||||||
Permission::ReportCreate,
|
Permission::ReportCreate,
|
||||||
|
Permission::ReportDownload,
|
||||||
Permission::StudyDownload,
|
Permission::StudyDownload,
|
||||||
Permission::StudyMetadataView,
|
Permission::StudyMetadataView,
|
||||||
Permission::StudyNotesCreate,
|
Permission::StudyNotesCreate,
|
||||||
@ -39,6 +43,16 @@ public function run(): void
|
|||||||
Permission::AttachmentUpload,
|
Permission::AttachmentUpload,
|
||||||
Permission::AttachmentDownload,
|
Permission::AttachmentDownload,
|
||||||
Permission::StudyArchive,
|
Permission::StudyArchive,
|
||||||
|
Permission::ReportDownload,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$adm->givePermissionTo(SpatiePermission::all());
|
||||||
|
|
||||||
|
$guest->givePermissionTo([
|
||||||
|
Permission::StudyMetadataView,
|
||||||
|
Permission::StudyNotesView,
|
||||||
|
Permission::StudyDownload,
|
||||||
|
Permission::ReportDownload,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,42 +13,49 @@ public function run(): void
|
|||||||
{
|
{
|
||||||
// User::factory(10)->create();
|
// User::factory(10)->create();
|
||||||
|
|
||||||
User::factory()->create([
|
$usr = User::factory()->create([
|
||||||
'first_name' => 'PACS Sync',
|
'first_name' => 'PACS Sync',
|
||||||
'display_name' => 'PACS Sync Agent',
|
'display_name' => 'PACS Sync Agent',
|
||||||
'username' => '$$_pacs_sync_$$',
|
'username' => '$$_pacs_sync_$$',
|
||||||
'password' => bcrypt(fake()->password(20)),
|
'password' => bcrypt(fake()->password(20)),
|
||||||
'user_role' => UserRole::System->value,
|
|
||||||
'is_active' => false,
|
'is_active' => false,
|
||||||
]);
|
]);
|
||||||
|
$usr->assignRole(UserRole::SystemAgent);
|
||||||
|
|
||||||
User::factory()->create([
|
$usr = User::factory()->create([
|
||||||
'first_name' => 'Administrator',
|
'first_name' => 'Administrator',
|
||||||
'display_name' => 'Administrator',
|
'display_name' => 'Administrator',
|
||||||
'username' => 'admin',
|
'username' => 'admin',
|
||||||
'email' => 'admin@example.com',
|
'email' => 'admin@example.com',
|
||||||
'email_verified_at' => now(),
|
'email_verified_at' => now(),
|
||||||
'phone' => '+8801733938582',
|
'phone' => '+8801733938582',
|
||||||
'user_role' => UserRole::Admin->value,
|
|
||||||
]);
|
]);
|
||||||
|
$usr->assignRole(UserRole::Admin);
|
||||||
|
|
||||||
$chevron = Institute::where('name', 'Chevron')->first();
|
$chevron = Institute::where('name', 'Chevron')->first();
|
||||||
$srini = Institute::where('name', 'Srinivasa')->first();
|
$srini = Institute::where('name', 'Srinivasa')->first();
|
||||||
|
|
||||||
User::factory(2)->create([
|
User::factory(2)->create([
|
||||||
'institute_id' => $chevron->id,
|
'institute_id' => $chevron->id,
|
||||||
'user_role' => UserRole::Technician->value,
|
])
|
||||||
]);
|
->each(function ($u) {
|
||||||
|
$u->assignRole(UserRole::Technician);
|
||||||
|
});
|
||||||
User::factory(2)->create([
|
User::factory(2)->create([
|
||||||
'institute_id' => $srini->id,
|
'institute_id' => $srini->id,
|
||||||
'user_role' => UserRole::Technician->value,
|
])
|
||||||
]);
|
->each(function ($u) {
|
||||||
|
$u->assignRole(UserRole::Technician);
|
||||||
|
});
|
||||||
|
|
||||||
User::factory(2)->create([
|
User::factory(4)->create()
|
||||||
'user_role' => UserRole::Radiologist->value,
|
->each(function ($u) {
|
||||||
]);
|
$u->assignRole(UserRole::Radiologist);
|
||||||
|
});
|
||||||
|
|
||||||
User::factory(4)->create();
|
User::factory(4)->create()
|
||||||
|
->each(function ($u) {
|
||||||
|
$u->assignRole(UserRole::Guest);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user