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 26 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
19 changes: 19 additions & 0 deletions app/Http/Controllers/Dashboard/PermissionController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Http\Controllers\Dashboard;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Permission;

class PermissionController extends Controller
{
//
public function getPermissions()
{

$permissions = Permission::all();

return response()->json($permissions);
}
}
85 changes: 85 additions & 0 deletions app/Http/Controllers/Dashboard/RolesController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?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;
use Redirect;

class RolesController extends Controller
{
public function index(): Response
{
/**
* Shows the role page
* @return Response
*/
return Inertia::render(
'AccessControl/Roles',
['roles' => []]
);
}
public function details($roleId): Response
chaitak-gorai marked this conversation as resolved.
Show resolved Hide resolved
{
/**
* Shows the role page
* @return Response
*/
$role = Role::with('permissions')->where('id', $roleId)->first();
$users = $role->users()->get();
$temp = [
'id' => $role->id,
'name' => $role->name,
'display_name' => $role->display_name,
'description' => $role->description,
'permissions' => $role->permissions,
'users' => $users,
];
return Inertia::render(
'AccessControl/RolesDetails',
['roleDetails' => $temp]
);
}
public function store(CreateRoleRequest $request)
{
$role = new Role();
$role->name = $request->name;
$role->display_name = $request->display_name;
$role->description = $request->description;
$role->save();
foreach ($request->permissions as $permission) {
$role->permissions()->attach([$permission['id']]);
}
$role->save();
if ($role->save()) {
return Inertia::location(route('dashboard.roles.index'));
} else {
return Redirect::back()->with(['error' => 'Something went wrong']);
}
}
public function getRoles()
{
$result = [];
$roles = Role::with('permissions')->get();
foreach ($roles as $role) {
$users = $role->users()->get();
$temp = [
'id' => $role->id,
'name' => $role->name,
'display_name' => $role->display_name,
'description' => $role->description,
'permissions' => $role->permissions,
'users' => $users,
];
array_push($result, $temp);
}

return response()->json($result, 200);
}
}
19 changes: 19 additions & 0 deletions app/Http/Controllers/Dashboard/User/SetupAccount.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Http\Controllers\Dashboard\User;

use App\Http\Controllers\Controller;
use App\Models\Facilities\Facility;
use Illuminate\Http\Request;
use Inertia\Inertia;

class SetupAccount extends Controller
{

public function index()
{
$facilities = Facility::pluck('name', 'id');

return Inertia::render('Users/AddUsers', ['facilities' => $facilities]);
}
}
97 changes: 84 additions & 13 deletions app/Http/Controllers/Dashboard/User/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,29 @@
namespace App\Http\Controllers\Dashboard\User;

use App\Http\Controllers\Controller;
use App\Mail\InvitationMail;
use App\Models\Facilities\Facility;
use App\Models\Invitation;
use App\Models\Role;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Inertia\Response;
use Inertia\Inertia;
use Mail;
use Redirect;
use Str;
use URL;

class UserController extends Controller
{
/**
* Display a listing of the resource.
*
* @return Response
*/

public function index()
{
//
/**
* Shows the role page
* @return Response
*/
}

/**
* Show the form for creating a new resource.
*
Expand All @@ -36,9 +44,7 @@ public function create()
*/
public function store(Request $request)
{
//
}

/**
* Display the specified resource.
*
Expand All @@ -50,15 +56,41 @@ public function show($id)
//
}


public function profile($userId): Response
{
/**
* Shows the user profile page
* @return Response
*/
$user = User::where('id', $userId)->first();
$invitation_details = Invitation::where('email', $user->email)->first();
$user->invitation_details = $invitation_details;

return Inertia::render('Users/UserProfile', ['userData' => $user]);
}

public function showEditPage($userId): Response
chaitak-gorai marked this conversation as resolved.
Show resolved Hide resolved
{
/**
* Shows the user edit page
* @return Response
*/
$user = User::where('id', $userId)->first();
$facilities = Facility::pluck('name', 'id');

return Inertia::render('Users/EditUser', ['userData' => $user, 'facilities' => $facilities]);
chaitak-gorai marked this conversation as resolved.
Show resolved Hide resolved
}


/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Response
*/
public function edit($id)
public function edit()
chaitak-gorai marked this conversation as resolved.
Show resolved Hide resolved
{
//
}

/**
Expand All @@ -68,9 +100,48 @@ public function edit($id)
* @param int $id
* @return Response
*/
public function update(Request $request, $id)
public function update(Request $request, $userId)
{
//


//
// Get the existing user data
$user = User::findOrFail($userId);

// Update user data
$user->username = $request->username;
$user->email = $request->email;
$user->first_name = $request->first_name;
$user->middle_name = $request->middle_name;
$user->last_name = $request->last_name;
$user->federal_tax_id = $request->tax_id;
$user->federal_drug_id = $request->dea_number;
$user->npi = $request->npi;
$user->suffix = $request->suffix;
$user->taxonomy = $request->taxonomy;
$user->info = $request->job_description;
$user->warehouse = $request->default_warehouse;
$user->facility = $request->default_facility;
$user->provider_type = $request->provider_type;
$user->license = $request->license_number;
$user->additional_details = $request->additional_details;

$user->save();
//update the roles if role is changed
if ($user->access_control != $request->role) {
$user->roles()->detach();
$user->permissions()->detach();
$user->access_control = $request->role;
$role = Role::where('name', '=', $request->role)->first();
$permissions = $role->permissions;
$user->attachRole($role);
foreach ($permissions as $permission) {
$user->attachPermission($permission);
}
}
$user->save();
return Inertia::location(route('dashboard.users.edit', ['userId' => $user->id]));
}

/**
Expand Down
124 changes: 124 additions & 0 deletions app/Http/Controllers/InvitationController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?php

namespace App\Http\Controllers;

use App\Invite;
use App\Models\Facilities\Facility;
use App\Models\Invitation;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Redirect;
use Inertia\Response;
use JamesDordoy\LaravelVueDatatable\Http\Resources\DataTableCollectionResource;
use Str;

class InvitationController extends Controller
{
public function showInvitations(): Response
{

$facilities = Facility::pluck('name', 'id');

return Inertia::render('Users/Invitations', ['facilities' => $facilities]);
}


//URL for datatable for invitations
public function getInvitations(Request $request)
{
$length = $request->input('length', 10);
$sortBy = $request->input('column');
$orderBy = $request->input('dir');
$facility = $request->input('facility');


$query = Invitation::with('user');

$query->orderBy($sortBy, $orderBy);

if ($facility != null) {
$query->where('facility', $facility);
}

$data = $query->paginate($length);

return new DataTableCollectionResource($data);
}

public function index($token): Response
{
/**
* Shows the role page
* @return Response
*/
$invite = Invitation::where('token', $token)->first();

//send a invalid token message if the invite is not found in the database.
if (!$invite) {
return Inertia::render('Users/AddPassword', ['status' => 'invalid']);
}

//masking the username part of the email.
$email = $invite->email;
[$username, $domain] = explode('@', $email);
$emailLength = strlen($email);
$usernameLength = strlen($username);
$maskedEmail = Str::mask($email, '*', - ($emailLength - $usernameLength / 2), $usernameLength / 2);

return Inertia::render('Users/AddPassword', ['status' => $invite->status, 'email' => $maskedEmail]);
}

public function sendInvite(Request $request)
{
$temporaryPassword = Str::random(10);
$userData = [
'username' => $request->username,
'password' => bcrypt($temporaryPassword),
'email' => $request->email,
'first_name' => $request->first_name,
'middle_name' => $request->middle_name,
'last_name' => $request->last_name,
'federal_tax_id' => $request->tax_id,
'federal_drug_id' => $request->dea_number,
'npi' => $request->npi,
'suffix' => $request->suffix,
'taxonomy' => $request->taxonomy,
'info' => $request->job_description,
'access_control' => $request->role,
'warehouse' => $request->default_warehouse,
'facility' => $request->default_facility,
'provider_type' => $request->provider_type,
'license' => $request->license_number,
'additional_details' => $request->additional_details,
];



Invite::send($userData, $request->email);
return Inertia::location(route('dashboard.users.invite'));
}

//single controller for both accept and reject based on reject parameter
public function acceptOrRejectInvite(Request $request)
{
$token = $request->token;

$reject = $request->reject;
if ($reject) {
$success = Invite::reject($token);
if ($success) {
return Inertia::location(route('login'));
} else {
return Redirect::back()->with(['error' => 'Something went wrong']);
}
} else {
$password = bcrypt($request->password);
$success = Invite::accept($token, $password);
if ($success) {
return Inertia::location(route('login'));
} else {
return Redirect::back()->with(['error' => 'Something went wrong']);
}
}
}
}
Loading