Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GSOC-23: Roles and User Modules #43

Open
wants to merge 43 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
6f27b3b
Roles interface with add role
chaitak-gorai Jun 9, 2023
6bc448a
🐛 Minor fixes: used ziggy
chaitak-gorai Jun 16, 2023
e4281e4
Added Laratrust Seeder for Roles
chaitak-gorai Jun 16, 2023
a819002
Minor updates
chaitak-gorai Jun 20, 2023
51ec886
Role UI update and Permission Data fetched in form
chaitak-gorai Jun 24, 2023
f2c8e85
Seeder Temporary bug fix & Scrollable Dropdown UI
chaitak-gorai Jun 25, 2023
4fb9808
🐛 Seeder updated & Bug solved
chaitak-gorai Jun 27, 2023
1e7fcb4
Seeder updated with sub modules
chaitak-gorai Jul 1, 2023
499cc6e
Customized Role Creation
chaitak-gorai Jul 1, 2023
66d9cf3
Users in Roles UI
chaitak-gorai Jul 1, 2023
9124937
Roles Details Page
chaitak-gorai Jul 1, 2023
a8cf553
Minor updates
chaitak-gorai Jul 2, 2023
c4c3f83
Add User Form UI
chaitak-gorai Jul 8, 2023
1b24983
Add User Form UI
chaitak-gorai Jul 8, 2023
5ddf478
➕ Add User via Invitation
chaitak-gorai Jul 21, 2023
4621bfa
Added a default value for token expiry
chaitak-gorai Jul 21, 2023
3e3a4dd
User Invitation Updated
chaitak-gorai Jul 26, 2023
037543c
Table Updates
chaitak-gorai Jul 26, 2023
97f0a33
Minor Updates
chaitak-gorai Aug 1, 2023
7e18c00
Minor updates on reviews
chaitak-gorai Aug 2, 2023
d796678
Invitations List UI
chaitak-gorai Aug 4, 2023
c24064e
Updates with Pagination.
chaitak-gorai Aug 8, 2023
811dd08
Proper Folder Structure Update
chaitak-gorai Aug 9, 2023
c8420ae
User Profile Page
chaitak-gorai Aug 13, 2023
9b4261f
Edit Profile Functionality
chaitak-gorai Aug 14, 2023
c6033fd
Minor update
chaitak-gorai Aug 14, 2023
d4de977
Routes Update, Clean file names
chaitak-gorai Aug 15, 2023
a75e3de
Removed redundant file
chaitak-gorai Aug 15, 2023
1e66f61
multiselect component for permissions select
chaitak-gorai Aug 23, 2023
066983c
Revert last changes and used MultiSelect
chaitak-gorai Aug 23, 2023
e02194a
fixed head for mobile devices
chaitak-gorai Apr 1, 2023
3ecdb06
Added icon template for svg icons
chaitak-gorai Apr 2, 2023
1eb7661
✨ Drawer Navigation Menu
chaitak-gorai Apr 18, 2023
5679a23
Fixed chevron icon color
chaitak-gorai Apr 21, 2023
a4b7c1a
🐛 fixed the backdrop bug
chaitak-gorai Apr 21, 2023
e877ac6
added all nav menu
chaitak-gorai May 26, 2023
2a621a6
Added L2 submenus
chaitak-gorai Jun 2, 2023
047b2dc
Added L2 submenus for small devices
chaitak-gorai Jun 2, 2023
15cbf9f
Merge branch 'develop' into roles
chaitak-gorai Aug 26, 2023
5ace6ba
access controlled routes
chaitak-gorai Aug 26, 2023
378fe5b
Merge branch 'roles' of https://github.com/chaitak-gorai/lh-ehr-larav…
chaitak-gorai Aug 26, 2023
4374361
Users datatable
chaitak-gorai Aug 26, 2023
2b6b772
Validations for Add User
chaitak-gorai Sep 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions app/Http/Controllers/Dashboard/RolesController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace App\Http\Controllers\Dashboard;

use App\Models\Role;
use App\Models\Permission;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use App\Http\Controllers\Controller;
use App\Http\Requests\CreateRoleRequest;
use Inertia\Inertia;
use Inertia\Response;
class RolesController extends Controller
{
public function index(): Response
{
/**
* Shows the role page
* @return Response
*/

return Inertia::render('Roles',
[
'roles' => []
]
);
}
public function store(CreateRoleRequest $request)
{

// Create a new Role object and save it to the database
$role = new Role();
$role->name = $request->name;
$role->display_name = $request->display_name;
$role->description = $request->description;
$role->save();

// Return a success response with the new role object
return response()->json($role, 201);
}
public function getRoles()
{
// Get all roles from the database
// $roles = Role::all();
$roles = Role::with('permissions')->get();
// Get the permissions associated with each role


// Embed the permissions into the roles
chaitak-gorai marked this conversation as resolved.
Show resolved Hide resolved

// foreach ($roles as $role) {
// $role->permissions = $role->permissions;
// }


// Return all roles as a JSON response
return response()->json($roles);
}
}
32 changes: 32 additions & 0 deletions app/Http/Requests/CreateRoleRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class CreateRoleRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array<string, mixed>
*/
public function rules()
{
return [
'name' => 'required|string',
'display_name' => 'required|string',
'description' => 'required|string',
];
}
}
141 changes: 141 additions & 0 deletions config/laratrust_seeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<?php

return [
/**
* Control if the seeder should create a user per role while seeding the data.
*/
'create_users' => false,

/**
* Control if all the laratrust tables should be truncated before running the seeder.
*/
'truncate_tables' => true,

'roles_structure' => [
'superadministrator' => [
'calendar' => 'c,r,u,d',
'flow-board' => 'c,r,u,d',
'patient' => 'c,r,u,d',
'fees' => 'c,r,u,d',
'inventory' => 'c,r,u,d',
'procedures' => 'c,r,u,d',
'administration' => 'c,r,u,d',
'reports' => 'c,r,u,d',
'misc' => 'c,r,u,d',
'popups' => 'c,r,u,d',
'qa-measures' => 'c,r,u,d',
'help' => 'c,r,u,d',
],
'administrators' => [
'calendar' => 'c,r,u,d',
'flow-board' => 'c,r,u,d',
'patient' => 'c,r,u,d',
'fees' => 'c,r,u,d',
'inventory' => 'c,r,u,d',
'procedures' => 'c,r,u,d',
'administration' => 'c,r',
'reports' => 'c,r,u,d',
'misc' => 'c,r,u,d',
'popups' => 'c,r,u,d',
'qa-measures' => 'c,r,u,d',
'help' => 'r',
],
'lh-user' => [
chaitak-gorai marked this conversation as resolved.
Show resolved Hide resolved
'calendar' => 'r',
'patient' => 'r',
'fees' => 'r',
'inventory' => 'r',
'procedures' => 'r',
'administration' => 'r',
'reports' => 'r',
'misc' => 'r',
'popups' => 'r',
'qa-measures' => 'r',
'help' => 'r',
],
'accounting' => [
'Calendar' => 'r',
'patient' => 'r',
'fees' => 'c,r,u,d',
'inventory' => 'r',
'procedures' => 'r',
'administration' => 'r,u',
'reports' => 'c,r,u,d',
'misc' => 'r,u',
'popups' => 'r,u',
'qa-measures' => 'r,u',
'help' => 'r',
],
'clinicians' => [
'calendar' => 'c,r,u,d',
'patient' => 'c,r,u,d',
'fees' => 'c,r,u,d',
'inventory' => 'r,u',
'procedures' => 'r,u',
'administration' => 'r,u',
'reports' => 'r,u',
'misc' => 'r,u',
'popups' => 'r,u',
'qa-measures' => 'r,u',
'help' => 'r',
],
'emergency_login' => [
'calendar' => 'r',
'patient' => 'c,r,u,d',
'fees' => 'r',
'inventory' => 'r',
'procedures' => 'r',
'administration' => 'r',
'reports' => 'r',
'misc' => 'r',
'popups' => 'r',
'qa-measures' => 'r',
'help' => 'r',
],
'front_office' => [
'calendar' => 'r,u',
'patient' => 'r,u',
'fees' => 'r,u',
'inventory' => 'r',
'procedures' => 'r',
'administration' => 'r',
'reports' => 'r',
'misc' => 'r',
'popups' => 'r',
'qa-measures' => 'r',
'help' => 'r',
],
'physicians' => [
'calendar' => 'c,r,u,d',
'patient' => 'c,r,u,d',
'fees' => 'r,u',
'inventory' => 'r',
'procedures' => 'c,r,u,d',
'administration' => 'c,r',
'reports' => 'c,r,u,d',
'misc' => 'c,r,u,d',
'popups' => 'c,r,u,d',
'qa-measures' => 'c,r,u,d',
'help' => 'r',
],
'super_student' => [
'calendar' => 'r,u',
'patient' => 'r,u',
'fees' => 'r',
'inventory' => 'r',
'procedures' => 'r,u',
'administration' => 'r,u',
'reports' => 'r,u',
'misc' => 'r,u',
'popups' => 'r,u',
'qa-measures' => 'r,u',
'help' => 'r',
],
],
'permissions_map' => [
'c' => 'create',
'r' => 'read',
'u' => 'update',
'd' => 'delete'
]
];
3 changes: 3 additions & 0 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function truncateAndSeedData()
DB::table($name)->truncate();
}
Schema::enableForeignKeyConstraints();

$this->seedData();
$this->complete();
}
Expand All @@ -58,8 +59,10 @@ public function seedData()
if (count($continents) < 1) {
Artisan::call('world:init');
}

$this->call(CurrencySeeder::class);
$this->call(UserTableSeeder::class);
$this->call(LaratrustSeeder::class);
$this->call(AddressTableSeeder::class);
$this->call(ContactTableSeeder::class);
$this->call(FacilityTableSeeder::class);
Expand Down
103 changes: 103 additions & 0 deletions database/seeders/LaratrustSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php

namespace Database\Seeders;

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Config;

class LaratrustSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$this->truncateLaratrustTables();

$config = Config::get('laratrust_seeder.roles_structure');

if ($config === null) {
$this->command->error("The configuration has not been published. Did you run `php artisan vendor:publish --tag=\"laratrust-seeder\"`");
$this->command->line('');
return false;
}

$mapPermission = collect(config('laratrust_seeder.permissions_map'));

foreach ($config as $key => $modules) {

// Create a new role
$role = \App\Models\Role::firstOrCreate([
'name' => $key,
'display_name' => ucwords(str_replace('_', ' ', $key)),
'description' => ucwords(str_replace('_', ' ', $key))
]);
$permissions = [];

$this->command->info('Creating Role '. strtoupper($key));

// Reading role permission modules
foreach ($modules as $module => $value) {

foreach (explode(',', $value) as $p => $perm) {

$permissionValue = $mapPermission->get($perm);

$permissions[] = \App\Models\Permission::firstOrCreate([
'name' => $module . '-' . $permissionValue,
'display_name' => ucfirst($permissionValue) . ' ' . ucfirst($module),
'description' => ucfirst($permissionValue) . ' ' . ucfirst($module),
])->id;

$this->command->info('Creating Permission to '.$permissionValue.' for '. $module);
}
}

// Attach all permissions to the role
$role->permissions()->sync($permissions);

if (Config::get('laratrust_seeder.create_users')) {
$this->command->info("Creating '{$key}' user");
// Create default user for each role
$user = \App\Models\User::create([
'name' => ucwords(str_replace('_', ' ', $key)),
'email' => $key.'@app.com',
'password' => bcrypt('password')
]);
$user->attachRole($role);
}

}
}

/**
* Truncates all the laratrust tables and the users table
*
* @return void
*/
public function truncateLaratrustTables()
{
$this->command->info('Truncating User, Role and Permission tables');
Schema::disableForeignKeyConstraints();

DB::table('permission_role')->truncate();
DB::table('permission_user')->truncate();
DB::table('role_user')->truncate();

if (Config::get('laratrust_seeder.truncate_tables')) {
DB::table('roles')->truncate();
DB::table('permissions')->truncate();

if (Config::get('laratrust_seeder.create_users')) {
$usersTable = (new \App\Models\User)->getTable();
DB::table($usersTable)->truncate();
}
}

Schema::enableForeignKeyConstraints();
}
}
Loading