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:
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Organization;
|
||||
use App\Models\Shortcut;
|
||||
use Livewire\Component;
|
||||
|
||||
new class extends Component
|
||||
{
|
||||
public Organization $organization;
|
||||
public ?Shortcut $shortcut = null;
|
||||
public bool $global = false;
|
||||
|
||||
public string $label = '';
|
||||
public string $url = '';
|
||||
public string $icon = '';
|
||||
|
||||
public function mount(Organization $organization, ?Shortcut $shortcut = null, bool $global = false): void
|
||||
{
|
||||
$this->organization = $organization;
|
||||
|
||||
if ($shortcut?->exists) {
|
||||
abort_unless($shortcut->organization_id === $organization->id || $shortcut->isGlobal(), 404);
|
||||
|
||||
if ($shortcut->isGlobal()) {
|
||||
abort_unless(auth()->user()->hasRole('Administrateur'), 403);
|
||||
}
|
||||
|
||||
$this->shortcut = $shortcut;
|
||||
$this->global = $shortcut->isGlobal();
|
||||
$this->label = $shortcut->label;
|
||||
$this->url = $shortcut->url;
|
||||
$this->icon = $shortcut->icon ?? '';
|
||||
} else {
|
||||
abort_if($global && ! auth()->user()->hasRole('Administrateur'), 403);
|
||||
$this->global = $global;
|
||||
}
|
||||
}
|
||||
|
||||
public function save(): void
|
||||
{
|
||||
$validated = $this->validate([
|
||||
'label' => 'required|string|max:255',
|
||||
'url' => 'required|url|max:2048',
|
||||
'icon' => 'nullable|string|max:10',
|
||||
]);
|
||||
|
||||
if ($this->shortcut?->exists) {
|
||||
$this->shortcut->update($validated);
|
||||
session()->flash('status', "Raccourci « {$this->shortcut->label} » mis à jour.");
|
||||
} else {
|
||||
Shortcut::create([
|
||||
...$validated,
|
||||
'organization_id' => $this->global ? null : $this->organization->id,
|
||||
'created_by' => auth()->id(),
|
||||
]);
|
||||
session()->flash('status', "Raccourci « {$this->label} » créé.");
|
||||
}
|
||||
|
||||
$this->redirectRoute('organizations.shortcuts.index', $this->organization, navigate: true);
|
||||
}
|
||||
};
|
||||
?>
|
||||
|
||||
<div class="max-w-lg">
|
||||
<p class="text-sm text-slate-500">{{ $organization->name }}</p>
|
||||
<h1 class="mb-6 text-2xl font-semibold text-slate-900">
|
||||
{{ $shortcut?->exists ? 'Modifier le raccourci' : 'Nouveau raccourci' }}
|
||||
</h1>
|
||||
|
||||
@if ($global)
|
||||
<p class="mb-4 rounded border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-700">
|
||||
Ce raccourci sera visible depuis toutes les organisations.
|
||||
</p>
|
||||
@endif
|
||||
|
||||
<form wire:submit="save" class="space-y-4 rounded border border-slate-200 bg-white p-6">
|
||||
<div class="grid grid-cols-4 gap-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-slate-700">Icône</label>
|
||||
<input type="text" wire:model="icon" placeholder="🔗" maxlength="10"
|
||||
class="mt-1 w-full rounded border-slate-300 text-center text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
||||
</div>
|
||||
<div class="col-span-3">
|
||||
<label class="block text-sm font-medium text-slate-700">Libellé</label>
|
||||
<input type="text" wire:model="label" placeholder="ex. Portail client"
|
||||
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
||||
@error('label') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-slate-700">URL</label>
|
||||
<input type="url" wire:model="url" placeholder="https://exemple.com"
|
||||
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
||||
@error('url') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
|
||||
</div>
|
||||
|
||||
<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('organizations.shortcuts.index', $organization) }}" class="text-sm text-slate-500 hover:text-slate-900">Annuler</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Organization;
|
||||
use App\Models\Shortcut;
|
||||
use Livewire\Component;
|
||||
|
||||
new class extends Component
|
||||
{
|
||||
public Organization $organization;
|
||||
|
||||
public function delete(int $shortcutId): void
|
||||
{
|
||||
$shortcut = Shortcut::findOrFail($shortcutId);
|
||||
|
||||
abort_unless($shortcut->organization_id === $this->organization->id || $shortcut->isGlobal(), 404);
|
||||
|
||||
if ($shortcut->isGlobal()) {
|
||||
abort_unless(auth()->user()->hasRole('Administrateur'), 403);
|
||||
}
|
||||
|
||||
$shortcut->delete();
|
||||
|
||||
session()->flash('status', "Raccourci « {$shortcut->label} » supprimé.");
|
||||
}
|
||||
|
||||
public function with(): array
|
||||
{
|
||||
return [
|
||||
'globalShortcuts' => Shortcut::whereNull('organization_id')->orderBy('label')->get(),
|
||||
'orgShortcuts' => $this->organization->shortcuts()->orderBy('label')->get(),
|
||||
];
|
||||
}
|
||||
};
|
||||
?>
|
||||
|
||||
<div>
|
||||
<div class="mb-6 flex items-center justify-between">
|
||||
<div>
|
||||
<p class="text-sm text-slate-500">{{ $organization->name }}</p>
|
||||
<h1 class="text-2xl font-semibold text-slate-900">Raccourcis</h1>
|
||||
</div>
|
||||
<div class="flex gap-2">
|
||||
@role('Administrateur')
|
||||
<a href="{{ route('organizations.shortcuts.create', [$organization, 'global' => true]) }}"
|
||||
class="rounded border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50">
|
||||
+ Raccourci global
|
||||
</a>
|
||||
@endrole
|
||||
<a href="{{ route('organizations.shortcuts.create', $organization) }}"
|
||||
class="rounded bg-slate-900 px-4 py-2 text-sm font-medium text-white hover:bg-slate-700">
|
||||
+ Raccourci de l'organisation
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid grid-cols-1 gap-6 lg:grid-cols-2">
|
||||
<div>
|
||||
<h2 class="mb-3 text-sm font-semibold uppercase tracking-wide text-slate-500">Globaux (toutes organisations)</h2>
|
||||
<div class="overflow-hidden rounded border border-slate-200 bg-white">
|
||||
<ul class="divide-y divide-slate-100">
|
||||
@forelse ($globalShortcuts as $shortcut)
|
||||
<li class="flex items-center justify-between gap-3 px-4 py-3 text-sm">
|
||||
<a href="{{ $shortcut->url }}" target="_blank" rel="noopener" class="flex min-w-0 items-center gap-2 text-slate-900 hover:underline">
|
||||
<span>{{ $shortcut->icon ?: '🔗' }}</span>
|
||||
<span class="truncate">{{ $shortcut->label }}</span>
|
||||
</a>
|
||||
@role('Administrateur')
|
||||
<div class="flex shrink-0 items-center gap-3 text-xs">
|
||||
<a href="{{ route('organizations.shortcuts.edit', [$organization, $shortcut]) }}" class="text-slate-500 hover:text-slate-900">Modifier</a>
|
||||
<button type="button" wire:click="delete({{ $shortcut->id }})"
|
||||
wire:confirm="Supprimer ce raccourci global ? Il disparaîtra pour toutes les organisations."
|
||||
class="text-red-500 hover:text-red-700">
|
||||
Supprimer
|
||||
</button>
|
||||
</div>
|
||||
@endrole
|
||||
</li>
|
||||
@empty
|
||||
<li class="px-4 py-6 text-center text-sm text-slate-400">Aucun raccourci global.</li>
|
||||
@endforelse
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h2 class="mb-3 text-sm font-semibold uppercase tracking-wide text-slate-500">Propres à {{ $organization->name }}</h2>
|
||||
<div class="overflow-hidden rounded border border-slate-200 bg-white">
|
||||
<ul class="divide-y divide-slate-100">
|
||||
@forelse ($orgShortcuts as $shortcut)
|
||||
<li class="flex items-center justify-between gap-3 px-4 py-3 text-sm">
|
||||
<a href="{{ $shortcut->url }}" target="_blank" rel="noopener" class="flex min-w-0 items-center gap-2 text-slate-900 hover:underline">
|
||||
<span>{{ $shortcut->icon ?: '🔗' }}</span>
|
||||
<span class="truncate">{{ $shortcut->label }}</span>
|
||||
</a>
|
||||
<div class="flex shrink-0 items-center gap-3 text-xs">
|
||||
<a href="{{ route('organizations.shortcuts.edit', [$organization, $shortcut]) }}" class="text-slate-500 hover:text-slate-900">Modifier</a>
|
||||
<button type="button" wire:click="delete({{ $shortcut->id }})"
|
||||
wire:confirm="Supprimer ce raccourci ?"
|
||||
class="text-red-500 hover:text-red-700">
|
||||
Supprimer
|
||||
</button>
|
||||
</div>
|
||||
</li>
|
||||
@empty
|
||||
<li class="px-4 py-6 text-center text-sm text-slate-400">Aucun raccourci pour cette organisation.</li>
|
||||
@endforelse
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user