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 1 commit
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
68 changes: 68 additions & 0 deletions app/Http/Controllers/Dashboard/RolesController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?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 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(Request $request)
{
// Validate the request input
$validator = Validator::make($request->all(), [
'name' => 'required|string',
'display_name' => 'required|string',
'description' => 'required|string',
]);

if ($validator->fails()) {
return response()->json($validator->errors(), 422);
muarachmann marked this conversation as resolved.
Show resolved Hide resolved
}

// 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);
}
}
171 changes: 171 additions & 0 deletions resources/app/pages/Roles.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
<template>
<div class="flex min-h-screen bg-white py-8 px-4">
<div class="w-1/2 mx-auto bg-white rounded shadow-md p-6">
<h2 class="text-2xl font-bold mb-4">Add Role</h2>
<form @submit.prevent="addRole">
<div class="mb-4">
<label class="block font-bold mb-2" for="name">Name</label>
<input
v-model="name"
type="text"
id="name"
class="w-full px-4 py-2 rounded ring-2 ring-orange-500 focus:ring-orange-500"
/>
</div>
<div class="mb-4">
<label class="block font-bold mb-2" for="name"
>Display Name</label
>
<input
v-model="display_name"
type="text"
id="display_name"
class="w-full px-4 py-2 rounded ring-2 ring-orange-500 focus:ring-orange-500"
/>
</div>
<div class="mb-4">
<label class="block font-bold mb-2" for="description"
>Description</label
>
<input
v-model="description"
id="description"
rows="4"
class="w-full px-4 py-2 rounded ring-2 ring-orange-500 focus:ring-orange-500"
/>
</div>
<div class="mb-4">
<label class="block font-bold mb-2" for="permissions"
>Permissions</label
>
<select
v-model="selectedPermissions"
multiple
id="permissions"
class="w-full px-4 py-2 rounded ring-2 ring-orange-500 focus:ring-orange-500"
>
<option
v-for="permission in permissions"
:key="permission.id"
:value="permission.id"
>
{{ permission.name }}
</option>
</select>
</div>
<button
type="submit"
class="bg-orange-500 hover:bg-orange-600 text-white font-bold py-2 px-4 rounded focus:outline-none focus:ring-2 focus:ring-orange-500"
>
Add Role
</button>
</form>
</div>

<div class="w-1/2 mx-auto bg-white rounded shadow-md p-6">
<h2 class="text-2xl font-bold mb-4">Existing Roles</h2>
<div class="grid grid-cols-2 gap-4">
<div
v-for="role in roles"
:key="role.id"
class="bg-white rounded-md p-4 shadow-lg"
>
<h3 class="text-lg font-bold">{{ role.display_name }}</h3>
<p class="text-gray-500">@{{ role.name }}</p>
<p class="text-gray-500">{{ role.description }}</p>
<div class="mt-2">
<p class="font-bold">Permissions:</p>
<span
v-for="permission in role.permissions"
:key="permission.id"
class="inline-block bg-orange-100 rounded-full px-3 py-1 mb-2 text-xs font-semibold mr-2"
>{{ permission.name }}</span
>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
import DashboardLayout from "../layouts/DashboardLayout";
export default {
name: "Roles",
layout: DashboardLayout,

data() {
return {
name: "",
display_name: "",
description: "",
permissions: [
{ id: 1, name: "Permission 1" },
{ id: 2, name: "Permission 2" },
{ id: 3, name: "Permission 3" },
],
selectedPermissions: [],
roles: [
{
id: 1,
name: "Admin",
description: "Can do everything",
permissions: [
"create_posts",
"edit_posts",
"delete_posts",
"create_roles",
],
},
{
id: 2,
name: "User",
description: "Can view and create",
permissions: ["create_posts", "view_posts"],
},
],
};
},
mounted() {
this.getRoles();
},
methods: {
getRoles() {
axios.get("/dashboard/allRoles").then((response) => {
this.roles = response.data;
});
},
addRole() {
axios
.post("/dashboard/roles", {
name: this.name,
muarachmann marked this conversation as resolved.
Show resolved Hide resolved
display_name: this.display_name,
description: this.description,
})
.then((response) => {
console.log(response);
this.roles.push(response.data);
this.name = "";
this.description = "";
this.permissions = [];
})
.catch((error) => {
console.log(error);
});
},

// deleteRole(id) {
// axios
// .delete(`/roles/${id}`)
// .then((response) => {
// this.roles = this.roles.filter((role) => role.id !== id);
// })
// .catch((error) => {
// console.log(error);
// });
// },
},
created() {
this.$on("submit", this.addRole);
},
};
</script>
7 changes: 6 additions & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Http\Controllers\Auth\ResetPasswordController;
use App\Http\Controllers\Dashboard\Calendar\CalendarController;
use App\Http\Controllers\Dashboard\DashboardController;
use App\Http\Controllers\Dashboard\RolesController;
use App\Http\Controllers\Dashboard\Facility\FacilityController;
use App\Http\Controllers\Dashboard\FlowBoardController;
use App\Http\Controllers\Dashboard\Patient\PatientAppointmentController;
Expand Down Expand Up @@ -109,7 +110,9 @@ function () {

// ======== Calendar routes ========
Route::get('calendar', [CalendarController::class, 'index'])->name('calendar');

Route::get('/roles', [RolesController::class, 'index']);
Route::post('/roles', [RolesController::class, 'store']);
Route::get('/allRoles', [RolesController::class, 'getRoles']);
muarachmann marked this conversation as resolved.
Show resolved Hide resolved
// ======== Users related routes ========
Route::resource('users', UserController::class)->names([
'index' => 'users.index',
Expand Down Expand Up @@ -214,3 +217,5 @@ function () {
});
});
});