- Added main application entry point (app.jsx) and bootstrap file for React setup. - Created Wiki index page (Index.jsx) for documentation and file management. - Implemented utility functions for formatting and status handling in utils.js. - Set up Blade template (app.blade.php) for Inertia.js integration. - Defined API routes for metrics and terminal access in api.php. - Established console commands for scheduled tasks in console.php. - Created web routes for various application features including authentication, hypervisors, containers, cloud accounts, security, backups, and wiki management in web.php. - Developed setup scripts for Windows (setup.ps1) and Linux (setup.sh) environments. - Configured Tailwind CSS for styling with custom themes and animations in tailwind.config.js. - Set up Vite for asset bundling and development server in vite.config.js.
59 lines
1.8 KiB
PHP
59 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Acl;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
use Inertia\Inertia;
|
|
use Spatie\Permission\Models\Permission;
|
|
use Spatie\Permission\Models\Role;
|
|
|
|
class RoleController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
return Inertia::render('Acl/Index', [
|
|
'users' => \App\Models\User::with('roles')->paginate(30),
|
|
'roles' => Role::withCount('permissions', 'users')->get(),
|
|
]);
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
return Inertia::render('Acl/RoleCreate', ['permissions' => Permission::all()->groupBy(fn($p) => explode('.', $p->name)[0])]);
|
|
}
|
|
|
|
public function store(Request $request)
|
|
{
|
|
$validated = $request->validate(['name' => 'required|string|unique:roles', 'permissions' => 'array']);
|
|
$role = Role::create(['name' => $validated['name']]);
|
|
if ($validated['permissions'] ?? false) {
|
|
$role->syncPermissions($validated['permissions']);
|
|
}
|
|
return redirect()->route('acl.index')->with('success', 'Role created.');
|
|
}
|
|
|
|
public function edit(Role $role)
|
|
{
|
|
return Inertia::render('Acl/RoleEdit', [
|
|
'role' => $role->load('permissions'),
|
|
'permissions' => Permission::all()->groupBy(fn($p) => explode('.', $p->name)[0]),
|
|
]);
|
|
}
|
|
|
|
public function update(Request $request, Role $role)
|
|
{
|
|
$role->syncPermissions($request->input('permissions', []));
|
|
return back()->with('success', 'Role updated.');
|
|
}
|
|
|
|
public function destroy(Role $role)
|
|
{
|
|
if (in_array($role->name, ['super-admin', 'admin'])) {
|
|
return back()->with('error', 'Cannot delete system roles.');
|
|
}
|
|
$role->delete();
|
|
return back()->with('success', 'Role deleted.');
|
|
}
|
|
}
|