Ajoute fiche d'identité informatique, catalogue prestataires et schémas draw.io
- Fiche d'identité par organisation (technicien référent, FAI, IP publiques, prestataires liés) accessible depuis un nouveau menu. - Nouveau module Prestataires dédié (catalogue léger réutilisable entre communes, avec journal de suivi des échanges) plutôt que de détourner les organisations de type "Fournisseur". - Nouveau menu Infrastructure par organisation avec schémas réseau/fonctionnel édités via draw.io embarqué (URL configurable, cf. réglages admin). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
74c0b01a2e
commit
3c87ced1e4
@@ -35,6 +35,11 @@ class Document extends Model implements Linkable
|
|||||||
return $this->type === 'upload';
|
return $this->type === 'upload';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isDiagram(): bool
|
||||||
|
{
|
||||||
|
return $this->type === 'diagram';
|
||||||
|
}
|
||||||
|
|
||||||
public function renderedMarkdown(): string
|
public function renderedMarkdown(): string
|
||||||
{
|
{
|
||||||
return (new CommonMarkConverter())->convert($this->content ?? '')->getContent();
|
return (new CommonMarkConverter())->convert($this->content ?? '')->getContent();
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use Illuminate\Database\Eloquent\Model;
|
|||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
#[Fillable(['name', 'slug', 'org_type', 'status', 'description', 'allowed_ip_ranges', 'logo_path', 'glpi_entity_id'])]
|
#[Fillable(['name', 'slug', 'org_type', 'status', 'description', 'allowed_ip_ranges', 'logo_path', 'glpi_entity_id', 'technician_user_id', 'isp_name', 'public_ips'])]
|
||||||
class Organization extends Model
|
class Organization extends Model
|
||||||
{
|
{
|
||||||
use SoftDeletes;
|
use SoftDeletes;
|
||||||
@@ -17,6 +17,7 @@ class Organization extends Model
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'allowed_ip_ranges' => 'array',
|
'allowed_ip_ranges' => 'array',
|
||||||
|
'public_ips' => 'array',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,4 +87,16 @@ class Organization extends Model
|
|||||||
{
|
{
|
||||||
return $this->hasMany(Shortcut::class);
|
return $this->hasMany(Shortcut::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function technician()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class, 'technician_user_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function providers()
|
||||||
|
{
|
||||||
|
return $this->belongsToMany(Provider::class, 'organization_provider')
|
||||||
|
->withPivot('id', 'label')
|
||||||
|
->withTimestamps();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||||
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
|
#[Fillable(['name', 'logo_path', 'phone', 'email', 'website', 'notes'])]
|
||||||
|
class Provider extends Model
|
||||||
|
{
|
||||||
|
use SoftDeletes;
|
||||||
|
|
||||||
|
protected function logoUrl(): Attribute
|
||||||
|
{
|
||||||
|
return Attribute::get(
|
||||||
|
fn () => $this->logo_path ? Storage::disk('public')->url($this->logo_path) : asset('images/default-organization-logo.svg')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function organizations()
|
||||||
|
{
|
||||||
|
return $this->belongsToMany(Organization::class, 'organization_provider')
|
||||||
|
->withPivot('id', 'label')
|
||||||
|
->withTimestamps();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function logEntries()
|
||||||
|
{
|
||||||
|
return $this->hasMany(ProviderLogEntry::class)->orderByDesc('created_at');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class ProviderLogEntry extends Model
|
||||||
|
{
|
||||||
|
const UPDATED_AT = null;
|
||||||
|
|
||||||
|
const CATEGORIES = [
|
||||||
|
'contact' => 'Échange (mail / appel)',
|
||||||
|
'observation' => 'Observation',
|
||||||
|
'incident' => 'Incident',
|
||||||
|
'info' => 'Information générale',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $guarded = [];
|
||||||
|
|
||||||
|
public function provider()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Provider::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function creator()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(User::class, 'created_by');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function categoryLabel(): string
|
||||||
|
{
|
||||||
|
return self::CATEGORIES[$this->category] ?? $this->category;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -36,6 +36,9 @@ class SettingsRegistry
|
|||||||
'ONLYOFFICE_CALLBACK_BASE_URL' => ['config' => 'onlyoffice.callback_base_url', 'label' => 'URL de rappel (callback)'],
|
'ONLYOFFICE_CALLBACK_BASE_URL' => ['config' => 'onlyoffice.callback_base_url', 'label' => 'URL de rappel (callback)'],
|
||||||
'ONLYOFFICE_JWT_SECRET' => ['config' => 'onlyoffice.jwt_secret', 'label' => 'Secret JWT'],
|
'ONLYOFFICE_JWT_SECRET' => ['config' => 'onlyoffice.jwt_secret', 'label' => 'Secret JWT'],
|
||||||
],
|
],
|
||||||
|
'Draw.io' => [
|
||||||
|
'DRAWIO_URL' => ['config' => 'drawio.url', 'label' => "URL de l'éditeur draw.io"],
|
||||||
|
],
|
||||||
'GLPI' => [
|
'GLPI' => [
|
||||||
'GLPI_API_URL' => ['config' => 'glpi.api_url', 'label' => "URL de l'API"],
|
'GLPI_API_URL' => ['config' => 'glpi.api_url', 'label' => "URL de l'API"],
|
||||||
'GLPI_APP_TOKEN' => ['config' => 'glpi.app_token', 'label' => 'Jeton application'],
|
'GLPI_APP_TOKEN' => ['config' => 'glpi.app_token', 'label' => 'Jeton application'],
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
// Base URL of the draw.io / diagrams.net editor to embed (embed mode).
|
||||||
|
// Defaults to the public diagrams.net service; point this to a self-hosted
|
||||||
|
// instance (e.g. the official jgraph/drawio Docker image) to keep diagram
|
||||||
|
// editing fully in-house.
|
||||||
|
'url' => env('DRAWIO_URL', 'https://embed.diagrams.net'),
|
||||||
|
];
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('organizations', function (Blueprint $table) {
|
||||||
|
$table->foreignId('technician_user_id')->nullable()->after('glpi_entity_id')->constrained('users')->nullOnDelete();
|
||||||
|
$table->string('isp_name')->nullable()->after('technician_user_id');
|
||||||
|
$table->json('public_ips')->nullable()->after('isp_name');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('organizations', function (Blueprint $table) {
|
||||||
|
$table->dropConstrainedForeignId('technician_user_id');
|
||||||
|
$table->dropColumn(['isp_name', 'public_ips']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('providers', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('name');
|
||||||
|
$table->string('logo_path')->nullable();
|
||||||
|
$table->string('phone')->nullable();
|
||||||
|
$table->string('email')->nullable();
|
||||||
|
$table->string('website')->nullable();
|
||||||
|
$table->text('notes')->nullable();
|
||||||
|
$table->timestamps();
|
||||||
|
$table->softDeletes();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('providers');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('organization_provider', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('organization_id')->constrained()->cascadeOnDelete();
|
||||||
|
$table->foreignId('provider_id')->constrained()->cascadeOnDelete();
|
||||||
|
$table->string('label')->nullable();
|
||||||
|
$table->timestamps();
|
||||||
|
|
||||||
|
$table->unique(['organization_id', 'provider_id', 'label'], 'organization_provider_unique');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('organization_provider');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('provider_log_entries', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('provider_id')->constrained()->cascadeOnDelete();
|
||||||
|
$table->string('category');
|
||||||
|
$table->text('note');
|
||||||
|
$table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
|
||||||
|
$table->timestamp('created_at')->useCurrent();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('provider_log_entries');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,130 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Document;
|
||||||
|
use App\Models\Organization;
|
||||||
|
use Livewire\Component;
|
||||||
|
|
||||||
|
new class extends Component
|
||||||
|
{
|
||||||
|
public Organization $organization;
|
||||||
|
public Document $document;
|
||||||
|
public string $backRoute = 'organizations.documents.index';
|
||||||
|
|
||||||
|
public bool $renaming = false;
|
||||||
|
public string $name = '';
|
||||||
|
|
||||||
|
public function mount(Organization $organization, Document $document, string $backRoute = 'organizations.documents.index'): void
|
||||||
|
{
|
||||||
|
abort_unless($document->isDiagram(), 404);
|
||||||
|
|
||||||
|
$this->organization = $organization;
|
||||||
|
$this->document = $document;
|
||||||
|
$this->backRoute = $backRoute;
|
||||||
|
$this->name = $document->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rename(): void
|
||||||
|
{
|
||||||
|
$validated = $this->validate(['name' => 'required|string|max:255']);
|
||||||
|
|
||||||
|
$this->document->update($validated);
|
||||||
|
$this->renaming = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function saveDiagram(string $xml): void
|
||||||
|
{
|
||||||
|
$contentChanged = $this->document->content !== $xml;
|
||||||
|
|
||||||
|
$this->document->update(['content' => $xml]);
|
||||||
|
|
||||||
|
if ($contentChanged) {
|
||||||
|
$this->document->increment('current_version');
|
||||||
|
$this->document->versions()->create([
|
||||||
|
'version' => $this->document->current_version,
|
||||||
|
'content' => $xml,
|
||||||
|
'created_by' => auth()->id(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<p class="text-sm text-slate-500">{{ $organization->name }}</p>
|
||||||
|
<div class="mb-4 flex items-center justify-between">
|
||||||
|
@if ($renaming)
|
||||||
|
<form wire:submit="rename" class="flex items-center gap-2">
|
||||||
|
<input type="text" wire:model="name" autofocus
|
||||||
|
class="rounded border-slate-300 text-2xl font-semibold shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
||||||
|
<button type="submit" class="cursor-pointer rounded bg-slate-900 px-3 py-1.5 text-sm text-white hover:bg-slate-700">Enregistrer</button>
|
||||||
|
<button type="button" wire:click="$set('renaming', false)" class="cursor-pointer text-sm text-slate-500 hover:text-slate-900">Annuler</button>
|
||||||
|
@error('name') <p class="text-sm text-red-600">{{ $message }}</p> @enderror
|
||||||
|
</form>
|
||||||
|
@else
|
||||||
|
<button type="button" wire:click="$set('renaming', true)" class="group flex cursor-pointer items-center gap-2">
|
||||||
|
<h1 class="text-2xl font-semibold text-slate-900">{{ $document->name }}</h1>
|
||||||
|
<span class="text-sm text-slate-400 opacity-0 group-hover:opacity-100">Renommer</span>
|
||||||
|
</button>
|
||||||
|
@endif
|
||||||
|
<a href="{{ route($backRoute, $organization) }}" class="text-sm text-slate-500 hover:text-slate-900">Retour</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
wire:ignore
|
||||||
|
x-data="drawioEditor(@js($document->content ?? ''), @js(config('drawio.url')))"
|
||||||
|
x-init="init()"
|
||||||
|
class="w-full"
|
||||||
|
style="height: 78vh;"
|
||||||
|
>
|
||||||
|
<iframe x-ref="iframe" src="{{ config('drawio.url') }}?embed=1&proto=json&spin=1&noSaveBtn=0&saveAndExit=0&noExitBtn=1"
|
||||||
|
class="h-full w-full rounded border border-slate-200 bg-white"></iframe>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p class="mt-2 text-xs text-slate-500" x-data="{ status: '' }" x-on:diagram-status.window="status = $event.detail" x-text="status"></p>
|
||||||
|
|
||||||
|
<div class="mt-8 max-w-5xl">
|
||||||
|
<x-documents.version-history :document="$document" />
|
||||||
|
|
||||||
|
<div class="mt-8">
|
||||||
|
<livewire:related-items.panel :organization="$organization" :item="$document" :key="'related-'.$document->id" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@once
|
||||||
|
<script>
|
||||||
|
function drawioEditor(initialXml, baseUrl) {
|
||||||
|
return {
|
||||||
|
origin: null,
|
||||||
|
init() {
|
||||||
|
this.origin = new URL(baseUrl, window.location.href).origin;
|
||||||
|
window.addEventListener('message', (evt) => this.handleMessage(evt));
|
||||||
|
},
|
||||||
|
handleMessage(evt) {
|
||||||
|
if (evt.origin !== this.origin) return;
|
||||||
|
|
||||||
|
let msg;
|
||||||
|
try {
|
||||||
|
msg = JSON.parse(evt.data);
|
||||||
|
} catch (e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (msg.event === 'init') {
|
||||||
|
this.post({ action: 'load', xml: initialXml, autosave: 0 });
|
||||||
|
} else if (msg.event === 'save') {
|
||||||
|
this.$wire.saveDiagram(msg.xml).then(() => {
|
||||||
|
window.dispatchEvent(new CustomEvent('diagram-status', { detail: 'Enregistré à ' + new Date().toLocaleTimeString() }));
|
||||||
|
this.post({ action: 'status', message: 'Enregistré', modified: false });
|
||||||
|
});
|
||||||
|
} else if (msg.event === 'exit') {
|
||||||
|
this.post({ action: 'status', message: '', modified: false });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
post(payload) {
|
||||||
|
this.$refs.iframe.contentWindow.postMessage(JSON.stringify(payload), this.origin);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
@endonce
|
||||||
@@ -0,0 +1,135 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Document;
|
||||||
|
use App\Models\Organization;
|
||||||
|
use Livewire\Component;
|
||||||
|
|
||||||
|
new class extends Component
|
||||||
|
{
|
||||||
|
public Organization $organization;
|
||||||
|
|
||||||
|
public string $newDiagramName = '';
|
||||||
|
public bool $showNewDiagram = false;
|
||||||
|
|
||||||
|
public function createDiagram(): void
|
||||||
|
{
|
||||||
|
$this->validate(['newDiagramName' => 'required|string|max:255']);
|
||||||
|
|
||||||
|
$emptyDiagram = <<<'XML'
|
||||||
|
<mxfile host="app.diagrams.net">
|
||||||
|
<diagram name="Page-1">
|
||||||
|
<mxGraphModel dx="800" dy="600" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0">
|
||||||
|
<root>
|
||||||
|
<mxCell id="0" />
|
||||||
|
<mxCell id="1" parent="0" />
|
||||||
|
</root>
|
||||||
|
</mxGraphModel>
|
||||||
|
</diagram>
|
||||||
|
</mxfile>
|
||||||
|
XML;
|
||||||
|
|
||||||
|
$document = $this->organization->documents()->create([
|
||||||
|
'name' => $this->newDiagramName,
|
||||||
|
'type' => 'diagram',
|
||||||
|
'content' => $emptyDiagram,
|
||||||
|
'current_version' => 1,
|
||||||
|
'created_by' => auth()->id(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$document->versions()->create([
|
||||||
|
'version' => 1,
|
||||||
|
'content' => $emptyDiagram,
|
||||||
|
'created_by' => auth()->id(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->redirectRoute('organizations.infrastructure.edit', [$this->organization, $document], navigate: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete(int $documentId): void
|
||||||
|
{
|
||||||
|
$document = $this->organization->documents()->where('type', 'diagram')->findOrFail($documentId);
|
||||||
|
$document->delete();
|
||||||
|
|
||||||
|
session()->flash('status', "Schéma « {$document->name} » supprimé.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function with(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'diagrams' => $this->organization->documents()
|
||||||
|
->where('type', 'diagram')
|
||||||
|
->with('creator')
|
||||||
|
->orderBy('name')
|
||||||
|
->get(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<div class="mb-6 flex items-center justify-between">
|
||||||
|
<h1 class="text-2xl font-semibold text-slate-900">Infrastructure</h1>
|
||||||
|
<button type="button" wire:click="$toggle('showNewDiagram')"
|
||||||
|
class="cursor-pointer rounded bg-slate-900 px-4 py-2 text-sm font-medium text-white hover:bg-slate-700">
|
||||||
|
+ Nouveau schéma
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@if (session('status'))
|
||||||
|
<div class="mb-4 rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-sm text-emerald-700">
|
||||||
|
{{ session('status') }}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
@if ($showNewDiagram)
|
||||||
|
<form wire:submit="createDiagram" class="mb-4 flex items-start gap-2 rounded border border-slate-200 bg-white p-3">
|
||||||
|
<div class="flex-1">
|
||||||
|
<input type="text" wire:model="newDiagramName" placeholder="Ex: Schéma réseau - Mairie, Schéma fonctionnel - SI RH"
|
||||||
|
class="w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
||||||
|
@error('newDiagramName') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="cursor-pointer rounded bg-slate-900 px-3 py-1.5 text-sm text-white hover:bg-slate-700">
|
||||||
|
Créer
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
<div class="overflow-hidden 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">Créé par</th>
|
||||||
|
<th class="px-4 py-3">Mis à jour</th>
|
||||||
|
<th class="px-4 py-3"></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody class="divide-y divide-slate-100">
|
||||||
|
@forelse ($diagrams as $diagram)
|
||||||
|
<tr wire:key="diagram-{{ $diagram->id }}">
|
||||||
|
<td class="px-4 py-3">
|
||||||
|
<a href="{{ route('organizations.infrastructure.edit', [$organization, $diagram]) }}" class="font-medium text-slate-900 hover:underline">
|
||||||
|
🗺️ {{ $diagram->name }}
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
<td class="px-4 py-3 text-slate-600">{{ $diagram->creator?->name ?? '—' }}</td>
|
||||||
|
<td class="px-4 py-3 text-slate-600">{{ $diagram->updated_at->diffForHumans() }}</td>
|
||||||
|
<td class="px-4 py-3 text-right">
|
||||||
|
<a href="{{ route('organizations.infrastructure.edit', [$organization, $diagram]) }}" class="text-slate-500 hover:text-slate-900">Ouvrir</a>
|
||||||
|
<button type="button"
|
||||||
|
wire:click="delete({{ $diagram->id }})"
|
||||||
|
wire:confirm="Supprimer ce schéma ? Cette action est irréversible."
|
||||||
|
class="ml-3 cursor-pointer text-red-500 hover:text-red-700">
|
||||||
|
Supprimer
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
@empty
|
||||||
|
<tr>
|
||||||
|
<td colspan="4" class="px-4 py-6 text-center text-slate-400">Aucun schéma pour le moment.</td>
|
||||||
|
</tr>
|
||||||
|
@endforelse
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -19,6 +19,10 @@
|
|||||||
class="block rounded px-3 py-2 hover:bg-slate-800 {{ request()->routeIs('organizations.*') ? 'bg-slate-800 text-white' : '' }}">
|
class="block rounded px-3 py-2 hover:bg-slate-800 {{ request()->routeIs('organizations.*') ? 'bg-slate-800 text-white' : '' }}">
|
||||||
Organisations
|
Organisations
|
||||||
</a>
|
</a>
|
||||||
|
<a href="{{ route('providers.index') }}"
|
||||||
|
class="block rounded px-3 py-2 hover:bg-slate-800 {{ request()->routeIs('providers.*') ? 'bg-slate-800 text-white' : '' }}">
|
||||||
|
Prestataires
|
||||||
|
</a>
|
||||||
|
|
||||||
@if ($currentOrganization)
|
@if ($currentOrganization)
|
||||||
@php
|
@php
|
||||||
@@ -38,6 +42,10 @@
|
|||||||
class="block rounded px-3 py-2 hover:bg-slate-800 {{ request()->routeIs('organizations.dashboard') ? 'bg-slate-800 text-white' : '' }}">
|
class="block rounded px-3 py-2 hover:bg-slate-800 {{ request()->routeIs('organizations.dashboard') ? 'bg-slate-800 text-white' : '' }}">
|
||||||
Tableau de bord
|
Tableau de bord
|
||||||
</a>
|
</a>
|
||||||
|
<a href="{{ route('organizations.identity-card', $currentOrganization) }}"
|
||||||
|
class="block rounded px-3 py-2 hover:bg-slate-800 {{ request()->routeIs('organizations.identity-card') ? 'bg-slate-800 text-white' : '' }}">
|
||||||
|
Fiche d'identité
|
||||||
|
</a>
|
||||||
<a href="{{ route('organizations.todos.index', $currentOrganization) }}"
|
<a href="{{ route('organizations.todos.index', $currentOrganization) }}"
|
||||||
class="block rounded px-3 py-2 hover:bg-slate-800 {{ request()->routeIs('organizations.todos.*') ? 'bg-slate-800 text-white' : '' }}">
|
class="block rounded px-3 py-2 hover:bg-slate-800 {{ request()->routeIs('organizations.todos.*') ? 'bg-slate-800 text-white' : '' }}">
|
||||||
ToDo
|
ToDo
|
||||||
@@ -62,6 +70,10 @@
|
|||||||
class="block rounded px-3 py-2 hover:bg-slate-800 {{ request()->routeIs('organizations.documents.*') ? 'bg-slate-800 text-white' : '' }}">
|
class="block rounded px-3 py-2 hover:bg-slate-800 {{ request()->routeIs('organizations.documents.*') ? 'bg-slate-800 text-white' : '' }}">
|
||||||
Documents
|
Documents
|
||||||
</a>
|
</a>
|
||||||
|
<a href="{{ route('organizations.infrastructure.index', $currentOrganization) }}"
|
||||||
|
class="block rounded px-3 py-2 hover:bg-slate-800 {{ request()->routeIs('organizations.infrastructure.*') ? 'bg-slate-800 text-white' : '' }}">
|
||||||
|
Infrastructure
|
||||||
|
</a>
|
||||||
<a href="{{ route('organizations.virtual-machines.index', $currentOrganization) }}"
|
<a href="{{ route('organizations.virtual-machines.index', $currentOrganization) }}"
|
||||||
class="block rounded px-3 py-2 hover:bg-slate-800 {{ request()->routeIs('organizations.virtual-machines.*') ? 'bg-slate-800 text-white' : '' }}">
|
class="block rounded px-3 py-2 hover:bg-slate-800 {{ request()->routeIs('organizations.virtual-machines.*') ? 'bg-slate-800 text-white' : '' }}">
|
||||||
Machines virtuelles
|
Machines virtuelles
|
||||||
|
|||||||
@@ -0,0 +1,198 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Organization;
|
||||||
|
use App\Models\Provider;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Livewire\Component;
|
||||||
|
|
||||||
|
new class extends Component
|
||||||
|
{
|
||||||
|
public Organization $organization;
|
||||||
|
|
||||||
|
public ?int $technicianUserId = null;
|
||||||
|
public string $ispName = '';
|
||||||
|
public string $publicIpsText = '';
|
||||||
|
|
||||||
|
public ?int $newProviderId = null;
|
||||||
|
public string $newProviderLabel = '';
|
||||||
|
|
||||||
|
public function mount(Organization $organization): void
|
||||||
|
{
|
||||||
|
$this->organization = $organization;
|
||||||
|
$this->technicianUserId = $organization->technician_user_id;
|
||||||
|
$this->ispName = $organization->isp_name ?? '';
|
||||||
|
$this->publicIpsText = implode("\n", $organization->public_ips ?? []);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save(): void
|
||||||
|
{
|
||||||
|
$validated = $this->validate([
|
||||||
|
'technicianUserId' => 'nullable|exists:users,id',
|
||||||
|
'ispName' => 'nullable|string|max:255',
|
||||||
|
'publicIpsText' => 'nullable|string',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$ips = collect(preg_split('/[\s,]+/', (string) $validated['publicIpsText'], -1, PREG_SPLIT_NO_EMPTY))
|
||||||
|
->unique()
|
||||||
|
->values();
|
||||||
|
|
||||||
|
if ($ips->contains(fn ($ip) => filter_var($ip, FILTER_VALIDATE_IP) === false)) {
|
||||||
|
$this->addError('publicIpsText', 'Une ou plusieurs adresses IP sont invalides.');
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->organization->update([
|
||||||
|
'technician_user_id' => $validated['technicianUserId'],
|
||||||
|
'isp_name' => $validated['ispName'] !== '' ? $validated['ispName'] : null,
|
||||||
|
'public_ips' => $ips->all(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
session()->flash('status', "Fiche d'identité mise à jour.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addProvider(): void
|
||||||
|
{
|
||||||
|
$validated = $this->validate([
|
||||||
|
'newProviderId' => 'required|exists:providers,id',
|
||||||
|
'newProviderLabel' => 'nullable|string|max:255',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$label = $validated['newProviderLabel'] ?: null;
|
||||||
|
|
||||||
|
$alreadyLinked = $this->organization->providers()
|
||||||
|
->wherePivot('provider_id', $validated['newProviderId'])
|
||||||
|
->wherePivot('label', '=', $label)
|
||||||
|
->exists();
|
||||||
|
|
||||||
|
if ($alreadyLinked) {
|
||||||
|
$this->addError('newProviderId', 'Ce prestataire est déjà lié avec ce libellé.');
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->organization->providers()->attach($validated['newProviderId'], ['label' => $label]);
|
||||||
|
|
||||||
|
$this->reset(['newProviderId', 'newProviderLabel']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeProvider(int $pivotId): void
|
||||||
|
{
|
||||||
|
DB::table('organization_provider')
|
||||||
|
->where('id', $pivotId)
|
||||||
|
->where('organization_id', $this->organization->id)
|
||||||
|
->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function with(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'technicians' => User::role(['Administrateur', 'Technicien'])->orderBy('name')->get(),
|
||||||
|
'availableProviders' => Provider::orderBy('name')->get(),
|
||||||
|
'providers' => $this->organization->providers()->orderBy('name')->get(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="max-w-3xl">
|
||||||
|
<p class="text-sm text-slate-500">{{ $organization->name }}</p>
|
||||||
|
<h1 class="mb-6 text-2xl font-semibold text-slate-900">Fiche d'identité informatique</h1>
|
||||||
|
|
||||||
|
@if (session('status'))
|
||||||
|
<div class="mb-4 rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-sm text-emerald-700">
|
||||||
|
{{ session('status') }}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
<form wire:submit="save" class="space-y-4 rounded border border-slate-200 bg-white p-6">
|
||||||
|
<div>
|
||||||
|
<label class="block text-sm font-medium text-slate-700">Technicien gestionnaire</label>
|
||||||
|
<select wire:model="technicianUserId"
|
||||||
|
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 ($technicians as $technician)
|
||||||
|
<option value="{{ $technician->id }}">{{ $technician->name }}</option>
|
||||||
|
@endforeach
|
||||||
|
</select>
|
||||||
|
@error('technicianUserId') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label class="block text-sm font-medium text-slate-700">Fournisseur d'accès internet</label>
|
||||||
|
<input type="text" wire:model="ispName" placeholder="Orange, Free Pro, Telindus..."
|
||||||
|
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
||||||
|
@error('ispName') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label class="block text-sm font-medium text-slate-700">IP(s) publiques</label>
|
||||||
|
<textarea wire:model="publicIpsText" rows="3" placeholder="Une adresse IP par ligne"
|
||||||
|
class="mt-1 w-full rounded border-slate-300 font-mono text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500"></textarea>
|
||||||
|
@error('publicIpsText') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="pt-2">
|
||||||
|
<button type="submit"
|
||||||
|
class="cursor-pointer rounded bg-slate-900 px-4 py-2 text-sm font-medium text-white hover:bg-slate-700">
|
||||||
|
Enregistrer
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<div class="mt-8 rounded border border-slate-200 bg-white p-6">
|
||||||
|
<h2 class="mb-3 text-sm font-semibold uppercase tracking-wide text-slate-500">Prestataires</h2>
|
||||||
|
|
||||||
|
<ul class="mb-4 divide-y divide-slate-100">
|
||||||
|
@forelse ($providers as $provider)
|
||||||
|
<li wire:key="provider-{{ $provider->pivot->id }}" class="flex items-center gap-3 py-2 text-sm">
|
||||||
|
<img src="{{ $provider->logo_url }}" alt="Logo {{ $provider->name }}"
|
||||||
|
class="h-6 w-6 shrink-0 rounded border border-slate-200 bg-white object-contain p-0.5">
|
||||||
|
<div class="flex-1">
|
||||||
|
<a href="{{ route('providers.edit', $provider) }}" class="font-medium text-slate-900 hover:underline">
|
||||||
|
{{ $provider->name }}
|
||||||
|
</a>
|
||||||
|
@if ($provider->pivot->label)
|
||||||
|
<span class="text-xs text-slate-500">· {{ $provider->pivot->label }}</span>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
<button type="button" wire:click="removeProvider({{ $provider->pivot->id }})"
|
||||||
|
wire:confirm="Retirer ce prestataire ?"
|
||||||
|
class="cursor-pointer shrink-0 text-xs text-red-500 hover:text-red-700">
|
||||||
|
Retirer
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
@empty
|
||||||
|
<li class="py-2 text-sm text-slate-400">Aucun prestataire lié.</li>
|
||||||
|
@endforelse
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<form wire:submit="addProvider" class="flex flex-wrap items-start gap-2 rounded border border-slate-100 bg-slate-50 p-3">
|
||||||
|
<div class="flex-1">
|
||||||
|
<select wire:model="newProviderId"
|
||||||
|
class="w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
||||||
|
<option value="">Sélectionner un prestataire...</option>
|
||||||
|
@foreach ($availableProviders as $availableProvider)
|
||||||
|
<option value="{{ $availableProvider->id }}">{{ $availableProvider->name }}</option>
|
||||||
|
@endforeach
|
||||||
|
</select>
|
||||||
|
@error('newProviderId') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
|
||||||
|
</div>
|
||||||
|
<div class="flex-1">
|
||||||
|
<input type="text" wire:model="newProviderLabel" placeholder="Libellé (ex: Téléphonie, Maintenance copieurs)"
|
||||||
|
class="w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="cursor-pointer rounded bg-slate-900 px-3 py-1.5 text-sm text-white hover:bg-slate-700">
|
||||||
|
Ajouter
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
@if ($availableProviders->isEmpty())
|
||||||
|
<p class="mt-3 text-xs text-slate-500">
|
||||||
|
Aucun prestataire n'existe encore.
|
||||||
|
<a href="{{ route('providers.create') }}" class="underline hover:text-slate-900">En créer un</a>.
|
||||||
|
</p>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,217 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Provider;
|
||||||
|
use App\Models\ProviderLogEntry;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Livewire\Component;
|
||||||
|
use Livewire\WithFileUploads;
|
||||||
|
|
||||||
|
new class extends Component
|
||||||
|
{
|
||||||
|
use WithFileUploads;
|
||||||
|
|
||||||
|
public ?Provider $provider = null;
|
||||||
|
|
||||||
|
public string $name = '';
|
||||||
|
public string $phone = '';
|
||||||
|
public string $email = '';
|
||||||
|
public string $website = '';
|
||||||
|
public string $notes = '';
|
||||||
|
|
||||||
|
public $logo = null;
|
||||||
|
|
||||||
|
public string $newLogCategory = 'contact';
|
||||||
|
public string $newLogNote = '';
|
||||||
|
|
||||||
|
public function mount(?Provider $provider = null): void
|
||||||
|
{
|
||||||
|
if ($provider?->exists) {
|
||||||
|
$this->provider = $provider;
|
||||||
|
$this->name = $provider->name;
|
||||||
|
$this->phone = $provider->phone ?? '';
|
||||||
|
$this->email = $provider->email ?? '';
|
||||||
|
$this->website = $provider->website ?? '';
|
||||||
|
$this->notes = $provider->notes ?? '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save(): void
|
||||||
|
{
|
||||||
|
$validated = $this->validate([
|
||||||
|
'name' => 'required|string|max:255',
|
||||||
|
'phone' => 'nullable|string|max:50',
|
||||||
|
'email' => 'nullable|email|max:255',
|
||||||
|
'website' => 'nullable|string|max:255',
|
||||||
|
'notes' => 'nullable|string',
|
||||||
|
'logo' => 'nullable|image|max:2048',
|
||||||
|
]);
|
||||||
|
|
||||||
|
unset($validated['logo']);
|
||||||
|
|
||||||
|
foreach (['phone', 'email', 'website', 'notes'] as $field) {
|
||||||
|
$validated[$field] = $validated[$field] !== '' ? $validated[$field] : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->provider?->exists) {
|
||||||
|
$this->provider->update($validated);
|
||||||
|
} else {
|
||||||
|
$this->provider = Provider::create($validated);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->logo) {
|
||||||
|
if ($this->provider->logo_path) {
|
||||||
|
Storage::disk('public')->delete($this->provider->logo_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
$path = $this->logo->store("providers/{$this->provider->id}", 'public');
|
||||||
|
$this->provider->update(['logo_path' => $path]);
|
||||||
|
}
|
||||||
|
|
||||||
|
session()->flash('status', "Prestataire « {$this->provider->name} » enregistré.");
|
||||||
|
|
||||||
|
$this->redirectRoute('providers.index', navigate: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addLogEntry(): void
|
||||||
|
{
|
||||||
|
$this->validate([
|
||||||
|
'newLogCategory' => 'required|in:'.implode(',', array_keys(ProviderLogEntry::CATEGORIES)),
|
||||||
|
'newLogNote' => 'required|string',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->provider->logEntries()->create([
|
||||||
|
'category' => $this->newLogCategory,
|
||||||
|
'note' => $this->newLogNote,
|
||||||
|
'created_by' => auth()->id(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->newLogNote = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function deleteLogEntry(int $entryId): void
|
||||||
|
{
|
||||||
|
$this->provider->logEntries()->findOrFail($entryId)->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function with(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'logEntries' => $this->provider?->exists ? $this->provider->logEntries()->with('creator')->limit(30)->get() : collect(),
|
||||||
|
'categories' => ProviderLogEntry::CATEGORIES,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="max-w-2xl">
|
||||||
|
<h1 class="mb-6 text-2xl font-semibold text-slate-900">
|
||||||
|
{{ $provider?->exists ? 'Modifier le prestataire' : 'Nouveau prestataire' }}
|
||||||
|
</h1>
|
||||||
|
|
||||||
|
@if (session('status'))
|
||||||
|
<div class="mb-4 rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-sm text-emerald-700">
|
||||||
|
{{ session('status') }}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
<form wire:submit="save" class="space-y-4 rounded border border-slate-200 bg-white p-6">
|
||||||
|
<div>
|
||||||
|
<label class="block text-sm font-medium text-slate-700">Logo</label>
|
||||||
|
<div class="mt-1 flex items-center gap-4">
|
||||||
|
<img src="{{ $logo ? $logo->temporaryUrl() : ($provider?->logo_url ?? asset('images/default-organization-logo.svg')) }}"
|
||||||
|
class="h-16 w-16 rounded border border-slate-200 object-contain p-1" alt="Logo">
|
||||||
|
<input type="file" wire:model="logo" accept="image/*"
|
||||||
|
class="block text-sm text-slate-600 file:mr-3 file:rounded file:border-0 file:bg-slate-100 file:px-3 file:py-1.5 file:text-sm file:font-medium file:text-slate-700 hover:file:bg-slate-200">
|
||||||
|
</div>
|
||||||
|
@error('logo') <p class="mt-1 text-sm text-red-600">{{ $message }}</p> @enderror
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<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 class="grid grid-cols-2 gap-4">
|
||||||
|
<div>
|
||||||
|
<label class="block text-sm font-medium text-slate-700">Téléphone</label>
|
||||||
|
<input type="text" wire:model="phone"
|
||||||
|
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
||||||
|
</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>
|
||||||
|
<label class="block text-sm font-medium text-slate-700">Site web</label>
|
||||||
|
<input type="text" wire:model="website" placeholder="https://..."
|
||||||
|
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label class="block text-sm font-medium text-slate-700">Notes</label>
|
||||||
|
<textarea wire:model="notes" rows="3"
|
||||||
|
class="mt-1 w-full rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500"></textarea>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex items-center gap-3 pt-2">
|
||||||
|
<button type="submit"
|
||||||
|
class="cursor-pointer rounded bg-slate-900 px-4 py-2 text-sm font-medium text-white hover:bg-slate-700">
|
||||||
|
Enregistrer
|
||||||
|
</button>
|
||||||
|
<a href="{{ route('providers.index') }}" class="text-sm text-slate-500 hover:text-slate-900">Annuler</a>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
@if ($provider?->exists)
|
||||||
|
<div class="mt-8 rounded border border-slate-200 bg-white p-6">
|
||||||
|
<h2 class="mb-3 text-sm font-semibold uppercase tracking-wide text-slate-500">Journal de suivi</h2>
|
||||||
|
|
||||||
|
<form wire:submit="addLogEntry" class="mb-4 space-y-2 rounded border border-slate-100 bg-slate-50 p-3">
|
||||||
|
<div class="flex items-start gap-2">
|
||||||
|
<select wire:model="newLogCategory" class="rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500">
|
||||||
|
@foreach ($categories as $value => $label)
|
||||||
|
<option value="{{ $value }}">{{ $label }}</option>
|
||||||
|
@endforeach
|
||||||
|
</select>
|
||||||
|
<textarea wire:model="newLogNote" rows="2" placeholder="Ex: mail envoyé le 21/08 pour demander des précisions..."
|
||||||
|
class="flex-1 rounded border-slate-300 text-sm shadow-sm focus:border-slate-500 focus:ring-slate-500"></textarea>
|
||||||
|
<button type="submit" class="cursor-pointer rounded bg-slate-900 px-3 py-1.5 text-sm text-white hover:bg-slate-700">Ajouter</button>
|
||||||
|
</div>
|
||||||
|
@error('newLogNote') <p class="text-sm text-red-600">{{ $message }}</p> @enderror
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<div class="space-y-3">
|
||||||
|
@forelse ($logEntries as $entry)
|
||||||
|
<div wire:key="log-{{ $entry->id }}" class="flex items-start justify-between gap-4 border-b border-slate-100 pb-3 last:border-0 last:pb-0">
|
||||||
|
<div>
|
||||||
|
<span class="mb-1 inline-block rounded-full px-2 py-0.5 text-xs font-medium
|
||||||
|
{{ match($entry->category) {
|
||||||
|
'contact' => 'bg-blue-100 text-blue-700',
|
||||||
|
'observation' => 'bg-slate-100 text-slate-600',
|
||||||
|
'incident' => 'bg-red-100 text-red-700',
|
||||||
|
default => 'bg-slate-100 text-slate-600',
|
||||||
|
} }}">
|
||||||
|
{{ $entry->categoryLabel() }}
|
||||||
|
</span>
|
||||||
|
<p class="whitespace-pre-line text-sm text-slate-900">{{ $entry->note }}</p>
|
||||||
|
<p class="mt-1 text-xs text-slate-500">{{ $entry->creator?->name ?? 'système' }} · {{ $entry->created_at->diffForHumans() }}</p>
|
||||||
|
</div>
|
||||||
|
<button type="button" wire:click="deleteLogEntry({{ $entry->id }})"
|
||||||
|
wire:confirm="Supprimer cette entrée ?"
|
||||||
|
class="cursor-pointer shrink-0 text-xs text-red-500 hover:text-red-700">
|
||||||
|
Supprimer
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
@empty
|
||||||
|
<p class="text-sm text-slate-400">Aucune entrée dans le journal pour le moment.</p>
|
||||||
|
@endforelse
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Provider;
|
||||||
|
use Livewire\Attributes\Url;
|
||||||
|
use Livewire\Component;
|
||||||
|
use Livewire\WithPagination;
|
||||||
|
|
||||||
|
new class extends Component
|
||||||
|
{
|
||||||
|
use WithPagination;
|
||||||
|
|
||||||
|
#[Url]
|
||||||
|
public string $search = '';
|
||||||
|
|
||||||
|
public function delete(int $providerId): void
|
||||||
|
{
|
||||||
|
$provider = Provider::findOrFail($providerId);
|
||||||
|
$provider->delete();
|
||||||
|
|
||||||
|
session()->flash('status', "Prestataire « {$provider->name} » supprimé.");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function with(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'providers' => Provider::query()
|
||||||
|
->when($this->search, fn ($query) => $query->where('name', '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">Prestataires</h1>
|
||||||
|
<a href="{{ route('providers.create') }}"
|
||||||
|
class="rounded bg-slate-900 px-4 py-2 text-sm font-medium text-white hover:bg-slate-700">
|
||||||
|
+ Nouveau prestataire
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@if (session('status'))
|
||||||
|
<div class="mb-4 rounded border border-emerald-200 bg-emerald-50 px-3 py-2 text-sm text-emerald-700">
|
||||||
|
{{ session('status') }}
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
<input type="text" wire:model.live.debounce.300ms="search" placeholder="Filtrer par nom..."
|
||||||
|
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-hidden 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"></th>
|
||||||
|
<th class="px-4 py-3">Nom</th>
|
||||||
|
<th class="px-4 py-3">Téléphone</th>
|
||||||
|
<th class="px-4 py-3">Email</th>
|
||||||
|
<th class="px-4 py-3"></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody class="divide-y divide-slate-100">
|
||||||
|
@forelse ($providers as $provider)
|
||||||
|
<tr wire:key="provider-{{ $provider->id }}">
|
||||||
|
<td class="px-4 py-3">
|
||||||
|
<img src="{{ $provider->logo_url }}" alt="Logo {{ $provider->name }}"
|
||||||
|
class="h-8 w-8 rounded border border-slate-200 bg-white object-contain p-0.5">
|
||||||
|
</td>
|
||||||
|
<td class="px-4 py-3">
|
||||||
|
<a href="{{ route('providers.edit', $provider) }}" class="font-medium text-slate-900 hover:underline">
|
||||||
|
{{ $provider->name }}
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
<td class="px-4 py-3 text-slate-600">{{ $provider->phone ?? '—' }}</td>
|
||||||
|
<td class="px-4 py-3 text-slate-600">{{ $provider->email ?? '—' }}</td>
|
||||||
|
<td class="px-4 py-3 text-right">
|
||||||
|
<a href="{{ route('providers.edit', $provider) }}" class="text-slate-500 hover:text-slate-900">Modifier</a>
|
||||||
|
<button type="button"
|
||||||
|
wire:click="delete({{ $provider->id }})"
|
||||||
|
wire:confirm="Supprimer ce prestataire ? Cette action est irréversible."
|
||||||
|
class="ml-3 cursor-pointer text-red-500 hover:text-red-700">
|
||||||
|
Supprimer
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
@empty
|
||||||
|
<tr>
|
||||||
|
<td colspan="5" class="px-4 py-6 text-center text-slate-400">Aucun prestataire pour le moment.</td>
|
||||||
|
</tr>
|
||||||
|
@endforelse
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mt-4">
|
||||||
|
{{ $providers->links() }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -5,6 +5,8 @@
|
|||||||
<livewire:documents.markdown-editor :organization="$organization" :document="$document" />
|
<livewire:documents.markdown-editor :organization="$organization" :document="$document" />
|
||||||
@elseif ($document->isUpload())
|
@elseif ($document->isUpload())
|
||||||
<livewire:documents.upload-viewer :organization="$organization" :document="$document" />
|
<livewire:documents.upload-viewer :organization="$organization" :document="$document" />
|
||||||
|
@elseif ($document->isDiagram())
|
||||||
|
<livewire:documents.diagram-editor :organization="$organization" :document="$document" />
|
||||||
@else
|
@else
|
||||||
<livewire:documents.form :organization="$organization" :document="$document" />
|
<livewire:documents.form :organization="$organization" :document="$document" />
|
||||||
@endif
|
@endif
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<x-layouts.app :title="$document->name">
|
||||||
|
<livewire:documents.diagram-editor :organization="$organization" :document="$document" back-route="organizations.infrastructure.index" />
|
||||||
|
</x-layouts.app>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<x-layouts.app title="Infrastructure">
|
||||||
|
<livewire:infrastructure.index :organization="$organization" />
|
||||||
|
</x-layouts.app>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<x-layouts.app title="Fiche d'identité informatique">
|
||||||
|
<livewire:organizations.identity-card :organization="$organization" />
|
||||||
|
</x-layouts.app>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<x-layouts.app title="Nouveau prestataire">
|
||||||
|
<livewire:providers.form />
|
||||||
|
</x-layouts.app>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<x-layouts.app :title="$provider->name">
|
||||||
|
<livewire:providers.form :provider="$provider" />
|
||||||
|
</x-layouts.app>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
<x-layouts.app title="Prestataires">
|
||||||
|
<livewire:providers.index />
|
||||||
|
</x-layouts.app>
|
||||||
@@ -8,6 +8,7 @@ use App\Models\FlexibleAssetType;
|
|||||||
use App\Models\Location;
|
use App\Models\Location;
|
||||||
use App\Models\Organization;
|
use App\Models\Organization;
|
||||||
use App\Models\Password;
|
use App\Models\Password;
|
||||||
|
use App\Models\Provider;
|
||||||
use App\Models\Shortcut;
|
use App\Models\Shortcut;
|
||||||
use App\Models\Todo;
|
use App\Models\Todo;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
@@ -23,7 +24,14 @@ Route::middleware(['auth'])->group(function () {
|
|||||||
Route::get('/organizations', fn () => view('organizations.index'))->name('organizations.index');
|
Route::get('/organizations', fn () => view('organizations.index'))->name('organizations.index');
|
||||||
Route::get('/organizations/create', fn () => view('organizations.create'))->name('organizations.create');
|
Route::get('/organizations/create', fn () => view('organizations.create'))->name('organizations.create');
|
||||||
Route::get('/organizations/{organization}/edit', fn (Organization $organization) => view('organizations.edit', ['organization' => $organization]))->name('organizations.edit');
|
Route::get('/organizations/{organization}/edit', fn (Organization $organization) => view('organizations.edit', ['organization' => $organization]))->name('organizations.edit');
|
||||||
|
|
||||||
|
Route::prefix('/providers')->name('providers.')->group(function () {
|
||||||
|
Route::get('/', fn () => view('providers.index'))->name('index');
|
||||||
|
Route::get('/create', fn () => view('providers.create'))->name('create');
|
||||||
|
Route::get('/{provider}/edit', fn (Provider $provider) => view('providers.edit', ['provider' => $provider]))->name('edit');
|
||||||
|
});
|
||||||
Route::get('/organizations/{organization}/dashboard', fn (Organization $organization) => view('organizations.dashboard', ['organization' => $organization]))->name('organizations.dashboard');
|
Route::get('/organizations/{organization}/dashboard', fn (Organization $organization) => view('organizations.dashboard', ['organization' => $organization]))->name('organizations.dashboard');
|
||||||
|
Route::get('/organizations/{organization}/identity-card', fn (Organization $organization) => view('organizations.identity-card', ['organization' => $organization]))->name('organizations.identity-card');
|
||||||
|
|
||||||
Route::prefix('/organizations/{organization}/passwords')->name('organizations.passwords.')->group(function () {
|
Route::prefix('/organizations/{organization}/passwords')->name('organizations.passwords.')->group(function () {
|
||||||
Route::get('/', fn (Organization $organization) => view('passwords.index', ['organization' => $organization]))->name('index');
|
Route::get('/', fn (Organization $organization) => view('passwords.index', ['organization' => $organization]))->name('index');
|
||||||
@@ -74,6 +82,14 @@ Route::middleware(['auth'])->group(function () {
|
|||||||
Route::get('/{document}/download', DocumentDownloadController::class)->name('download');
|
Route::get('/{document}/download', DocumentDownloadController::class)->name('download');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Route::prefix('/organizations/{organization}/infrastructure')->name('organizations.infrastructure.')->group(function () {
|
||||||
|
Route::get('/', fn (Organization $organization) => view('infrastructure.index', ['organization' => $organization]))->name('index');
|
||||||
|
Route::get('/{document}/edit', fn (Organization $organization, Document $document) => view('infrastructure.edit', [
|
||||||
|
'organization' => $organization,
|
||||||
|
'document' => $document,
|
||||||
|
]))->name('edit');
|
||||||
|
});
|
||||||
|
|
||||||
Route::prefix('/organizations/{organization}/virtual-machines')->name('organizations.virtual-machines.')->group(function () {
|
Route::prefix('/organizations/{organization}/virtual-machines')->name('organizations.virtual-machines.')->group(function () {
|
||||||
Route::get('/', fn (Organization $organization) => view('virtual-machines.index', ['organization' => $organization]))->name('index');
|
Route::get('/', fn (Organization $organization) => view('virtual-machines.index', ['organization' => $organization]))->name('index');
|
||||||
Route::get('/create', fn (Organization $organization) => view('virtual-machines.create', ['organization' => $organization]))->name('create');
|
Route::get('/create', fn (Organization $organization) => view('virtual-machines.create', ['organization' => $organization]))->name('create');
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use App\Models\Organization;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Livewire\Livewire;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class InfrastructureTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
public function test_infrastructure_index_page_renders_for_an_authenticated_user(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$org = Organization::create(['name' => 'Test Commune', 'slug' => 'test-commune', 'org_type' => 'client']);
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->get(route('organizations.infrastructure.index', $org));
|
||||||
|
|
||||||
|
$response->assertOk();
|
||||||
|
$response->assertSee('Infrastructure');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_can_create_a_diagram_and_it_opens_in_the_editor(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$org = Organization::create(['name' => 'Test Commune', 'slug' => 'test-commune', 'org_type' => 'client']);
|
||||||
|
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
Livewire::test('infrastructure.index', ['organization' => $org])
|
||||||
|
->set('newDiagramName', 'Schéma réseau - Mairie')
|
||||||
|
->call('createDiagram')
|
||||||
|
->assertHasNoErrors();
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('documents', [
|
||||||
|
'organization_id' => $org->id,
|
||||||
|
'name' => 'Schéma réseau - Mairie',
|
||||||
|
'type' => 'diagram',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$document = $org->documents()->where('type', 'diagram')->firstOrFail();
|
||||||
|
|
||||||
|
$response = $this->get(route('organizations.infrastructure.edit', [$org, $document]));
|
||||||
|
$response->assertOk();
|
||||||
|
$response->assertSee('Schéma réseau - Mairie');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_saving_a_diagram_creates_a_new_version_only_when_content_changed(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$org = Organization::create(['name' => 'Test Commune', 'slug' => 'test-commune', 'org_type' => 'client']);
|
||||||
|
|
||||||
|
$document = $org->documents()->create([
|
||||||
|
'name' => 'Schéma test',
|
||||||
|
'type' => 'diagram',
|
||||||
|
'content' => '<mxfile>old</mxfile>',
|
||||||
|
'current_version' => 1,
|
||||||
|
'created_by' => $user->id,
|
||||||
|
]);
|
||||||
|
$document->versions()->create(['version' => 1, 'content' => '<mxfile>old</mxfile>', 'created_by' => $user->id]);
|
||||||
|
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
Livewire::test('documents.diagram-editor', ['organization' => $org, 'document' => $document])
|
||||||
|
->call('saveDiagram', '<mxfile>new</mxfile>');
|
||||||
|
|
||||||
|
$document->refresh();
|
||||||
|
$this->assertSame('<mxfile>new</mxfile>', $document->content);
|
||||||
|
$this->assertSame(2, $document->current_version);
|
||||||
|
$this->assertCount(2, $document->versions);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,157 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use App\Models\Organization;
|
||||||
|
use App\Models\Provider;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Livewire\Livewire;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class OrganizationIdentityCardTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
public function test_identity_card_page_renders_for_an_authenticated_user(): void
|
||||||
|
{
|
||||||
|
$this->seed(\Database\Seeders\RolesAndPermissionsSeeder::class);
|
||||||
|
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$org = Organization::create(['name' => 'Test Commune', 'slug' => 'test-commune', 'org_type' => 'client']);
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->get(route('organizations.identity-card', $org));
|
||||||
|
|
||||||
|
$response->assertOk();
|
||||||
|
$response->assertSee("Fiche d'identité informatique");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_can_save_identity_fields_and_link_a_provider(): void
|
||||||
|
{
|
||||||
|
$this->seed(\Database\Seeders\RolesAndPermissionsSeeder::class);
|
||||||
|
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$technician = User::factory()->create();
|
||||||
|
$technician->assignRole('Technicien');
|
||||||
|
|
||||||
|
$org = Organization::create(['name' => 'Test Commune', 'slug' => 'test-commune', 'org_type' => 'client']);
|
||||||
|
$provider = Provider::create(['name' => 'Orange Pro']);
|
||||||
|
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
Livewire::test('organizations.identity-card', ['organization' => $org])
|
||||||
|
->set('technicianUserId', $technician->id)
|
||||||
|
->set('ispName', 'Orange Pro')
|
||||||
|
->set('publicIpsText', "203.0.113.10\n203.0.113.11")
|
||||||
|
->call('save')
|
||||||
|
->assertHasNoErrors();
|
||||||
|
|
||||||
|
$org->refresh();
|
||||||
|
$this->assertSame($technician->id, $org->technician_user_id);
|
||||||
|
$this->assertSame('Orange Pro', $org->isp_name);
|
||||||
|
$this->assertSame(['203.0.113.10', '203.0.113.11'], $org->public_ips);
|
||||||
|
|
||||||
|
Livewire::test('organizations.identity-card', ['organization' => $org])
|
||||||
|
->set('newProviderId', $provider->id)
|
||||||
|
->set('newProviderLabel', 'Téléphonie')
|
||||||
|
->call('addProvider')
|
||||||
|
->assertHasNoErrors();
|
||||||
|
|
||||||
|
$this->assertCount(1, $org->providers()->get());
|
||||||
|
|
||||||
|
$pivotId = $org->providers()->first()->pivot->id;
|
||||||
|
|
||||||
|
Livewire::test('organizations.identity-card', ['organization' => $org])
|
||||||
|
->call('removeProvider', $pivotId);
|
||||||
|
|
||||||
|
$this->assertCount(0, $org->providers()->get());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_clearing_the_technician_select_nulls_it_out(): void
|
||||||
|
{
|
||||||
|
$this->seed(\Database\Seeders\RolesAndPermissionsSeeder::class);
|
||||||
|
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$technician = User::factory()->create();
|
||||||
|
$technician->assignRole('Technicien');
|
||||||
|
|
||||||
|
$org = Organization::create([
|
||||||
|
'name' => 'Test Commune',
|
||||||
|
'slug' => 'test-commune',
|
||||||
|
'org_type' => 'client',
|
||||||
|
'technician_user_id' => $technician->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
Livewire::test('organizations.identity-card', ['organization' => $org])
|
||||||
|
->assertSet('technicianUserId', $technician->id)
|
||||||
|
->set('technicianUserId', '')
|
||||||
|
->call('save')
|
||||||
|
->assertHasNoErrors();
|
||||||
|
|
||||||
|
$this->assertNull($org->refresh()->technician_user_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_duplicate_provider_link_with_same_label_is_rejected(): void
|
||||||
|
{
|
||||||
|
$this->seed(\Database\Seeders\RolesAndPermissionsSeeder::class);
|
||||||
|
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$org = Organization::create(['name' => 'Test Commune', 'slug' => 'test-commune', 'org_type' => 'client']);
|
||||||
|
$provider = Provider::create(['name' => 'Orange Pro']);
|
||||||
|
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$org->providers()->attach($provider->id, ['label' => 'Téléphonie']);
|
||||||
|
|
||||||
|
Livewire::test('organizations.identity-card', ['organization' => $org])
|
||||||
|
->set('newProviderId', $provider->id)
|
||||||
|
->set('newProviderLabel', 'Téléphonie')
|
||||||
|
->call('addProvider')
|
||||||
|
->assertHasErrors('newProviderId');
|
||||||
|
|
||||||
|
$this->assertCount(1, $org->providers()->get());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_duplicate_provider_link_without_a_label_is_rejected(): void
|
||||||
|
{
|
||||||
|
$this->seed(\Database\Seeders\RolesAndPermissionsSeeder::class);
|
||||||
|
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$org = Organization::create(['name' => 'Test Commune', 'slug' => 'test-commune', 'org_type' => 'client']);
|
||||||
|
$provider = Provider::create(['name' => 'Orange Pro']);
|
||||||
|
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
$org->providers()->attach($provider->id, ['label' => null]);
|
||||||
|
|
||||||
|
Livewire::test('organizations.identity-card', ['organization' => $org])
|
||||||
|
->set('newProviderId', $provider->id)
|
||||||
|
->set('newProviderLabel', '')
|
||||||
|
->call('addProvider')
|
||||||
|
->assertHasErrors('newProviderId');
|
||||||
|
|
||||||
|
$this->assertCount(1, $org->providers()->get());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_removing_a_provider_link_is_scoped_to_its_own_organization(): void
|
||||||
|
{
|
||||||
|
$this->seed(\Database\Seeders\RolesAndPermissionsSeeder::class);
|
||||||
|
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$orgA = Organization::create(['name' => 'Commune A', 'slug' => 'commune-a', 'org_type' => 'client']);
|
||||||
|
$orgB = Organization::create(['name' => 'Commune B', 'slug' => 'commune-b', 'org_type' => 'client']);
|
||||||
|
$provider = Provider::create(['name' => 'Orange Pro']);
|
||||||
|
|
||||||
|
$orgA->providers()->attach($provider->id, ['label' => null]);
|
||||||
|
$pivotIdA = $orgA->providers()->first()->pivot->id;
|
||||||
|
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
Livewire::test('organizations.identity-card', ['organization' => $orgB])
|
||||||
|
->call('removeProvider', $pivotIdA);
|
||||||
|
|
||||||
|
$this->assertCount(1, $orgA->providers()->get());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use App\Models\Provider;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Livewire\Livewire;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class ProviderTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
public function test_provider_index_page_renders_for_an_authenticated_user(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->get(route('providers.index'));
|
||||||
|
|
||||||
|
$response->assertOk();
|
||||||
|
$response->assertSee('Prestataires');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_can_create_a_provider(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
Livewire::test('providers.form')
|
||||||
|
->set('name', 'Orange Pro')
|
||||||
|
->set('phone', '09 70 00 00 00')
|
||||||
|
->set('email', 'contact@orange-pro.fr')
|
||||||
|
->call('save')
|
||||||
|
->assertHasNoErrors();
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('providers', ['name' => 'Orange Pro', 'email' => 'contact@orange-pro.fr']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_blank_optional_fields_are_stored_as_null_not_empty_strings(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
Livewire::test('providers.form')
|
||||||
|
->set('name', 'Minimal Provider')
|
||||||
|
->call('save')
|
||||||
|
->assertHasNoErrors();
|
||||||
|
|
||||||
|
$provider = Provider::where('name', 'Minimal Provider')->firstOrFail();
|
||||||
|
$this->assertNull($provider->phone);
|
||||||
|
$this->assertNull($provider->email);
|
||||||
|
$this->assertNull($provider->website);
|
||||||
|
$this->assertNull($provider->notes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_can_add_a_log_entry_to_a_provider(): void
|
||||||
|
{
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$provider = Provider::create(['name' => 'Orange Pro']);
|
||||||
|
|
||||||
|
$this->actingAs($user);
|
||||||
|
|
||||||
|
Livewire::test('providers.form', ['provider' => $provider])
|
||||||
|
->set('newLogCategory', 'contact')
|
||||||
|
->set('newLogNote', "Mail envoyé le 21/08 pour demander des précisions sur le contrat.")
|
||||||
|
->call('addLogEntry')
|
||||||
|
->assertHasNoErrors();
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('provider_log_entries', [
|
||||||
|
'provider_id' => $provider->id,
|
||||||
|
'category' => 'contact',
|
||||||
|
'created_by' => $user->id,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature;
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class SettingsEnvPageTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
public function test_admin_settings_page_renders_with_the_new_drawio_section(): void
|
||||||
|
{
|
||||||
|
$this->seed(\Database\Seeders\RolesAndPermissionsSeeder::class);
|
||||||
|
|
||||||
|
$admin = User::factory()->create();
|
||||||
|
$admin->assignRole('Administrateur');
|
||||||
|
|
||||||
|
$response = $this->actingAs($admin)->get(route('settings.env'));
|
||||||
|
|
||||||
|
$response->assertOk();
|
||||||
|
$response->assertSee('Draw.io');
|
||||||
|
$response->assertSee('DRAWIO_URL');
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user