Initial commit: CABM-IT (ItGlue-style MSP documentation platform)

Laravel 13 + Livewire/Volt app for managing client organizations,
documents, passwords, flexible assets, virtual machines, contacts,
domains, todos, shortcuts, and role-based user administration.
This commit is contained in:
jeremy bayse
2026-08-16 13:28:12 +02:00
commit 8f22dca9c8
209 changed files with 23324 additions and 0 deletions
@@ -0,0 +1,159 @@
<?php
use App\Models\Organization;
use App\Models\User;
use Illuminate\Support\Facades\Hash;
use Illuminate\Validation\Rule;
use Illuminate\Validation\Rules\Password;
use Livewire\Component;
use Spatie\Permission\Models\Role;
new class extends Component
{
public ?User $user = null;
public string $name = '';
public string $email = '';
public string $password = '';
public string $password_confirmation = '';
public string $role = '';
public bool $is_msp_staff = false;
/** @var array<int, int> */
public array $organization_ids = [];
public function mount(?User $user = null): void
{
if ($user?->exists) {
$this->user = $user;
$this->name = $user->name;
$this->email = $user->email;
$this->role = $user->getRoleNames()->first() ?? '';
$this->is_msp_staff = (bool) $user->is_msp_staff;
$this->organization_ids = $user->organizations->pluck('id')->all();
}
}
public function save(): void
{
$validated = $this->validate([
'name' => 'required|string|max:255',
'email' => ['required', 'email', 'max:255', Rule::unique('users', 'email')->ignore($this->user?->id)],
'password' => [$this->user?->exists ? 'nullable' : 'required', 'string', Password::default(), 'confirmed'],
'role' => 'required|exists:roles,name',
'is_msp_staff' => 'boolean',
'organization_ids' => 'array',
'organization_ids.*' => 'exists:organizations,id',
]);
$attributes = [
'name' => $validated['name'],
'email' => $validated['email'],
'is_msp_staff' => $validated['is_msp_staff'],
];
if (! empty($validated['password'])) {
$attributes['password'] = Hash::make($validated['password']);
}
if ($this->user?->exists) {
$this->user->update($attributes);
} else {
$this->user = User::create($attributes);
}
$this->user->syncRoles([$this->role]);
$this->user->organizations()->sync($this->organization_ids);
session()->flash('status', "Utilisateur « {$this->user->name} » enregistré.");
$this->redirectRoute('users.index', navigate: true);
}
public function with(): array
{
return [
'roles' => Role::orderBy('name')->get(),
'organizations' => Organization::orderBy('name')->get(),
];
}
};
?>
<div class="max-w-2xl">
<p class="text-sm text-slate-500">Gestion des utilisateurs</p>
<h1 class="mb-6 text-2xl font-semibold text-slate-900">
{{ $user?->exists ? 'Modifier l\'utilisateur' : 'Nouvel utilisateur' }}
</h1>
<form wire:submit="save" class="space-y-4 rounded border border-slate-200 bg-white p-6">
<div class="grid grid-cols-2 gap-4">
<div>
<label class="block text-sm font-medium text-slate-700">Nom</label>
<input type="text" wire:model="name"
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
@error('name') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
</div>
<div>
<label class="block text-sm font-medium text-slate-700">Email</label>
<input type="email" wire:model="email"
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
@error('email') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
</div>
</div>
<div class="grid grid-cols-2 gap-4">
<div>
<label class="block text-sm font-medium text-slate-700">Mot de passe {{ $user?->exists ? '(laisser vide pour ne pas changer)' : '' }}</label>
<input type="password" wire:model="password" autocomplete="new-password"
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
@error('password') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
</div>
<div>
<label class="block text-sm font-medium text-slate-700">Confirmation</label>
<input type="password" wire:model="password_confirmation" autocomplete="new-password"
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
</div>
</div>
<div>
<label class="block text-sm font-medium text-slate-700">Rôle</label>
<select wire:model="role"
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
<option value="">—</option>
@foreach ($roles as $roleOption)
<option value="{{ $roleOption->name }}">{{ $roleOption->name }}</option>
@endforeach
</select>
@error('role') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
</div>
<label class="flex items-center gap-2 text-sm text-slate-700">
<input type="checkbox" wire:model.live="is_msp_staff" class="rounded border-slate-300">
Membre de l'équipe MSP (accès à toutes les organisations)
</label>
@unless ($is_msp_staff)
<div>
<label class="block text-sm font-medium text-slate-700">Organisations accessibles</label>
<div class="mt-2 max-h-48 space-y-1 overflow-y-auto rounded border border-slate-200 p-3">
@forelse ($organizations as $organization)
<label class="flex items-center gap-2 text-sm text-slate-700">
<input type="checkbox" wire:model="organization_ids" value="{{ $organization->id }}" class="rounded border-slate-300">
{{ $organization->name }}
</label>
@empty
<p class="text-sm text-slate-400">Aucune organisation.</p>
@endforelse
</div>
</div>
@endunless
<div class="flex items-center gap-3 pt-2">
<button type="submit"
class="rounded bg-slate-900 px-4 py-2 text-sm font-medium text-white hover:bg-slate-700">
Enregistrer
</button>
<a href="{{ route('users.index') }}" class="text-sm text-slate-500 hover:text-slate-900">Annuler</a>
</div>
</form>
</div>
@@ -0,0 +1,111 @@
<?php
use App\Models\User;
use Livewire\Attributes\Url;
use Livewire\Component;
use Livewire\WithPagination;
new class extends Component
{
use WithPagination;
#[Url]
public string $search = '';
public function delete(int $userId): void
{
if ($userId === auth()->id()) {
session()->flash('error', 'Vous ne pouvez pas supprimer votre propre compte.');
return;
}
$user = User::findOrFail($userId);
$user->delete();
session()->flash('status', "Utilisateur « {$user->name} » supprimé.");
}
public function with(): array
{
return [
'users' => User::query()
->when($this->search, fn ($query) => $query->where(function ($q) {
$q->where('name', 'like', "%{$this->search}%")
->orWhere('email', 'like', "%{$this->search}%");
}))
->orderBy('name')
->paginate(15),
];
}
};
?>
<div>
<div class="mb-6 flex items-center justify-between">
<h1 class="text-2xl font-semibold text-slate-900">Utilisateurs</h1>
<a href="{{ route('users.create') }}"
class="rounded bg-slate-900 px-4 py-2 text-sm font-medium text-white hover:bg-slate-700">
+ Nouvel utilisateur
</a>
</div>
@if (session('error'))
<div class="mb-4 rounded border border-red-200 bg-red-50 px-4 py-2 text-sm text-red-700">
{{ session('error') }}
</div>
@endif
<input type="text" wire:model.live.debounce.300ms="search" placeholder="Filtrer par nom ou email..."
class="mb-4 w-full max-w-sm rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
<div class="overflow-x-auto rounded border border-slate-200 bg-white">
<table class="min-w-full divide-y divide-slate-200 text-sm">
<thead class="bg-slate-50 text-left text-xs uppercase tracking-wide text-slate-500">
<tr>
<th class="px-4 py-3">Nom</th>
<th class="px-4 py-3">Email</th>
<th class="px-4 py-3">Rôle</th>
<th class="px-4 py-3">Organisations</th>
<th class="px-4 py-3"></th>
</tr>
</thead>
<tbody class="divide-y divide-slate-100">
@forelse ($users as $user)
<tr wire:key="user-{{ $user->id }}">
<td class="px-4 py-3">
<a href="{{ route('users.edit', $user) }}" class="font-medium text-slate-900 hover:underline">
{{ $user->name }}
</a>
@if ($user->id === auth()->id())
<span class="ml-2 rounded-full bg-slate-100 px-2 py-0.5 text-xs font-medium text-slate-600">Vous</span>
@endif
</td>
<td class="px-4 py-3 text-slate-600">{{ $user->email }}</td>
<td class="px-4 py-3 text-slate-600">{{ $user->getRoleNames()->implode(', ') ?: '—' }}</td>
<td class="px-4 py-3 text-slate-600">{{ $user->is_msp_staff ? 'Toutes (staff)' : $user->organizations->count() }}</td>
<td class="px-4 py-3 text-right whitespace-nowrap">
<a href="{{ route('users.edit', $user) }}" class="text-slate-500 hover:text-slate-900">Modifier</a>
@unless ($user->id === auth()->id())
<button type="button"
wire:click="delete({{ $user->id }})"
wire:confirm="Supprimer cet utilisateur ? Cette action est irréversible."
class="ml-3 text-red-500 hover:text-red-700">
Supprimer
</button>
@endunless
</td>
</tr>
@empty
<tr>
<td colspan="5" class="px-4 py-6 text-center text-slate-400">Aucun utilisateur pour le moment.</td>
</tr>
@endforelse
</tbody>
</table>
</div>
<div class="mt-4">
{{ $users->links() }}
</div>
</div>