import fix for update so it does not insert person and client case
This commit is contained in:
parent
ed62311ba4
commit
e782bcca7c
|
|
@ -4,7 +4,9 @@
|
|||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\StorePermissionRequest;
|
||||
use App\Http\Requests\UpdatePermissionRequest;
|
||||
use App\Models\Permission;
|
||||
use App\Models\Role;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
|
@ -22,15 +24,51 @@ public function index(): Response
|
|||
'permissions' => $permissions,
|
||||
]);
|
||||
}
|
||||
|
||||
public function create(): Response
|
||||
{
|
||||
return Inertia::render('Admin/Permissions/Create');
|
||||
$roles = Role::orderBy('name')->get(['id', 'name', 'slug']);
|
||||
|
||||
return Inertia::render('Admin/Permissions/Create', [
|
||||
'roles' => $roles,
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(StorePermissionRequest $request): RedirectResponse
|
||||
{
|
||||
Permission::create($request->validated());
|
||||
$data = $request->validated();
|
||||
$roleIds = $data['roles'] ?? [];
|
||||
unset($data['roles']);
|
||||
|
||||
return redirect()->route('admin.index')->with('success', 'Dovoljenje ustvarjeno.');
|
||||
$permission = Permission::create($data);
|
||||
if (! empty($roleIds)) {
|
||||
$permission->roles()->sync($roleIds);
|
||||
}
|
||||
|
||||
return redirect()->route('admin.permissions.index')->with('success', 'Dovoljenje ustvarjeno.');
|
||||
}
|
||||
|
||||
public function edit(Permission $permission): Response
|
||||
{
|
||||
$roles = Role::orderBy('name')->get(['id', 'name', 'slug']);
|
||||
$selected = $permission->roles()->pluck('roles.id');
|
||||
|
||||
return Inertia::render('Admin/Permissions/Edit', [
|
||||
'permission' => $permission->only('id', 'name', 'slug', 'description'),
|
||||
'roles' => $roles,
|
||||
'selectedRoleIds' => $selected,
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(UpdatePermissionRequest $request, Permission $permission): RedirectResponse
|
||||
{
|
||||
$data = $request->validated();
|
||||
$roleIds = $data['roles'] ?? [];
|
||||
unset($data['roles']);
|
||||
|
||||
$permission->update($data);
|
||||
$permission->roles()->sync($roleIds);
|
||||
|
||||
return redirect()->route('admin.permissions.index')->with('success', 'Dovoljenje posodobljeno.');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ public function rules(): array
|
|||
'name' => ['required', 'string', 'max:255'],
|
||||
'slug' => ['required', 'string', 'max:255', 'alpha_dash', 'unique:permissions,slug'],
|
||||
'description' => ['nullable', 'string', 'max:500'],
|
||||
'roles' => ['sometimes', 'array'],
|
||||
'roles.*' => ['integer', 'exists:roles,id'],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
36
app/Http/Requests/UpdatePermissionRequest.php
Normal file
36
app/Http/Requests/UpdatePermissionRequest.php
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class UpdatePermissionRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return $this->user()?->hasPermission('manage-settings') || $this->user()?->hasRole('admin');
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
$permissionId = $this->route('permission')->id ?? null;
|
||||
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'slug' => ['required', 'string', 'max:255', 'alpha_dash', Rule::unique('permissions', 'slug')->ignore($permissionId)],
|
||||
'description' => ['nullable', 'string', 'max:500'],
|
||||
'roles' => ['sometimes', 'array'],
|
||||
'roles.*' => ['integer', 'exists:roles,id'],
|
||||
];
|
||||
}
|
||||
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'name.required' => 'Ime je obvezno.',
|
||||
'slug.required' => 'Slug je obvezen.',
|
||||
'slug.unique' => 'Slug že obstaja.',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1490,6 +1490,9 @@ private function upsertContractChain(Import $import, array $mapped, $mappings):
|
|||
return ['action' => 'invalid', 'message' => 'Missing contract.reference'];
|
||||
}
|
||||
|
||||
// Determine mapping mode for contract.reference (e.g., keyref)
|
||||
$refMode = $this->mappingMode($mappings, 'contract.reference');
|
||||
|
||||
// Determine client_case_id: prefer provided, else derive via person/client
|
||||
$clientCaseId = $contractData['client_case_id'] ?? null;
|
||||
$clientId = $import->client_id; // may be null
|
||||
|
|
@ -1513,6 +1516,19 @@ private function upsertContractChain(Import $import, array $mapped, $mappings):
|
|||
->first();
|
||||
}
|
||||
|
||||
// If contract.reference is keyref and contract not found, do not create any entities
|
||||
if (! $existing && $refMode === 'keyref') {
|
||||
ImportEvent::create([
|
||||
'import_id' => $import->id,
|
||||
'user_id' => null,
|
||||
'event' => 'row_skipped',
|
||||
'level' => 'warning',
|
||||
'message' => 'Contract reference '.$reference.' does not exist (keyref); row skipped.',
|
||||
]);
|
||||
|
||||
return ['action' => 'skipped', 'message' => 'contract.reference keyref lookup failed: not found'];
|
||||
}
|
||||
|
||||
// If we still need to insert, we must resolve clientCaseId, but avoid creating new person/case unless necessary
|
||||
if (! $existing && ! $clientCaseId) {
|
||||
$clientRef = $mapped['client_case']['client_ref'] ?? null;
|
||||
|
|
@ -1573,7 +1589,7 @@ private function upsertContractChain(Import $import, array $mapped, $mappings):
|
|||
continue;
|
||||
}
|
||||
$parts = explode('.', $map->target_field);
|
||||
if ($parts[0] !== 'contract') {
|
||||
if (($parts[0] ?? null) !== 'contract') {
|
||||
continue;
|
||||
}
|
||||
$field = $parts[1] ?? null;
|
||||
|
|
@ -1588,31 +1604,16 @@ private function upsertContractChain(Import $import, array $mapped, $mappings):
|
|||
// keyref: used as lookup and applied on insert, but not on update
|
||||
if ($mode === 'keyref') {
|
||||
$applyInsert[$field] = $value;
|
||||
|
||||
continue;
|
||||
}
|
||||
if (in_array($mode, ['insert', 'both'])) {
|
||||
if (in_array($mode, ['insert', 'both'], true)) {
|
||||
$applyInsert[$field] = $value;
|
||||
}
|
||||
if (in_array($mode, ['update', 'both'])) {
|
||||
if (in_array($mode, ['update', 'both'], true)) {
|
||||
$applyUpdate[$field] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
// If contract not found and contract.reference is keyref, skip without creating entities
|
||||
$refMode = $this->mappingMode($mappings, 'contract.reference');
|
||||
if (! $existing && $refMode === 'keyref') {
|
||||
ImportEvent::create([
|
||||
'import_id' => $import->id,
|
||||
'user_id' => null,
|
||||
'event' => 'row_skipped',
|
||||
'level' => 'warning',
|
||||
'message' => 'Contract reference '.$reference.' does not exist (keyref); row skipped.',
|
||||
]);
|
||||
|
||||
return ['action' => 'skipped', 'message' => 'contract.reference keyref lookup failed: not found'];
|
||||
}
|
||||
|
||||
if ($existing) {
|
||||
// 1) Prepare contract field changes (non-null)
|
||||
$changes = array_filter($applyUpdate, fn ($v) => ! is_null($v));
|
||||
|
|
|
|||
|
|
@ -77,7 +77,9 @@ function applyFilters() {
|
|||
'bg-amber-50 text-amber-700 border-amber-200': log.status === 'queued' || log.status === 'sending',
|
||||
'bg-red-50 text-red-700 border-red-200': log.status === 'failed',
|
||||
}">{{ log.status }}</span></td>
|
||||
<td class="p-2 truncate max-w-[220px]">{{ log.to_email }}</td>
|
||||
<td class="p-2 truncate max-w-[220px]">
|
||||
{{ log.to_email || (Array.isArray(log.to_recipients) && log.to_recipients.length ? log.to_recipients.join(', ') : '-') }}
|
||||
</td>
|
||||
<td class="p-2 truncate max-w-[320px]">{{ log.subject }}</td>
|
||||
<td class="p-2 truncate max-w-[220px]">{{ log.template?.name || '-' }}</td>
|
||||
<td class="p-2">{{ log.duration_ms ? log.duration_ms + ' ms' : '-' }}</td>
|
||||
|
|
|
|||
|
|
@ -4,16 +4,21 @@ import { useForm, Link } from '@inertiajs/vue3'
|
|||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
|
||||
import { faKey, faArrowLeft, faPlus } from '@fortawesome/free-solid-svg-icons'
|
||||
|
||||
const props = defineProps({
|
||||
roles: Array,
|
||||
})
|
||||
|
||||
const form = useForm({
|
||||
name: '',
|
||||
slug: '',
|
||||
description: ''
|
||||
description: '',
|
||||
roles: [],
|
||||
})
|
||||
|
||||
function submit() {
|
||||
form.post(route('admin.permissions.store'), {
|
||||
preserveScroll: true,
|
||||
onSuccess: () => form.reset('name','slug','description')
|
||||
onSuccess: () => form.reset('name','slug','description','roles')
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
|
@ -51,6 +56,16 @@ function submit() {
|
|||
<textarea v-model="form.description" rows="3" class="w-full border rounded-md px-3 py-2 text-sm focus:ring-indigo-500 focus:border-indigo-500" />
|
||||
<p v-if="form.errors.description" class="text-xs text-red-600 mt-1">{{ form.errors.description }}</p>
|
||||
</div>
|
||||
<div class="sm:col-span-2 space-y-1">
|
||||
<label class="block text-xs font-medium uppercase tracking-wide text-gray-600">Veži na vloge</label>
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-2">
|
||||
<label v-for="r in props.roles" :key="r.id" class="inline-flex items-center gap-2 text-sm">
|
||||
<input type="checkbox" :value="r.id" v-model="form.roles" class="rounded border-gray-300 text-indigo-600 focus:ring-indigo-500"/>
|
||||
<span><span class="font-medium">{{ r.name }}</span> <span class="text-xs text-gray-500">({{ r.slug }})</span></span>
|
||||
</label>
|
||||
</div>
|
||||
<p v-if="form.errors.roles" class="text-xs text-red-600 mt-1">{{ form.errors.roles }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-3 pt-2">
|
||||
|
|
|
|||
137
resources/js/Pages/Admin/Permissions/Edit.vue
Normal file
137
resources/js/Pages/Admin/Permissions/Edit.vue
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
<script setup>
|
||||
import AdminLayout from "@/Layouts/AdminLayout.vue";
|
||||
import { useForm, Link } from "@inertiajs/vue3";
|
||||
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
|
||||
import { faKey, faArrowLeft, faSave } from "@fortawesome/free-solid-svg-icons";
|
||||
|
||||
const props = defineProps({
|
||||
permission: Object,
|
||||
roles: Array,
|
||||
selectedRoleIds: Array,
|
||||
});
|
||||
|
||||
const form = useForm({
|
||||
name: props.permission.name,
|
||||
slug: props.permission.slug,
|
||||
description: props.permission.description || "",
|
||||
roles: [...props.selectedRoleIds],
|
||||
});
|
||||
|
||||
function submit() {
|
||||
form.put(route("admin.permissions.update", props.permission.id), {
|
||||
preserveScroll: true,
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AdminLayout :title="`Uredi dovoljenje — ${props.permission.name}`">
|
||||
<div class="max-w-2xl mx-auto bg-white border rounded-xl shadow-sm p-6 space-y-8">
|
||||
<header class="flex items-start justify-between gap-6">
|
||||
<div class="space-y-1">
|
||||
<h1 class="text-xl font-semibold tracking-tight flex items-center gap-2">
|
||||
<span
|
||||
class="inline-flex items-center justify-center h-9 w-9 rounded-md bg-indigo-50 text-indigo-600"
|
||||
><FontAwesomeIcon :icon="faKey"
|
||||
/></span>
|
||||
Uredi dovoljenje
|
||||
</h1>
|
||||
<p class="text-sm text-gray-500">
|
||||
Posodobi sistemsko dovoljenje in pripete vloge.
|
||||
</p>
|
||||
</div>
|
||||
<Link
|
||||
:href="route('admin.permissions.index')"
|
||||
class="inline-flex items-center gap-1 text-xs font-medium text-gray-500 hover:text-gray-700"
|
||||
>
|
||||
<FontAwesomeIcon :icon="faArrowLeft" class="w-4 h-4" /> Nazaj
|
||||
</Link>
|
||||
</header>
|
||||
|
||||
<form @submit.prevent="submit" class="space-y-6">
|
||||
<div class="grid sm:grid-cols-2 gap-6">
|
||||
<div class="space-y-1">
|
||||
<label class="block text-xs font-medium uppercase tracking-wide text-gray-600"
|
||||
>Ime</label
|
||||
>
|
||||
<input
|
||||
v-model="form.name"
|
||||
type="text"
|
||||
class="w-full border rounded-md px-3 py-2 text-sm focus:ring-indigo-500 focus:border-indigo-500"
|
||||
/>
|
||||
<p v-if="form.errors.name" class="text-xs text-red-600 mt-1">
|
||||
{{ form.errors.name }}
|
||||
</p>
|
||||
</div>
|
||||
<div class="space-y-1">
|
||||
<label class="block text-xs font-medium uppercase tracking-wide text-gray-600"
|
||||
>Slug</label
|
||||
>
|
||||
<input
|
||||
v-model="form.slug"
|
||||
type="text"
|
||||
class="w-full border rounded-md px-3 py-2 text-sm font-mono focus:ring-indigo-500 focus:border-indigo-500"
|
||||
/>
|
||||
<p v-if="form.errors.slug" class="text-xs text-red-600 mt-1">
|
||||
{{ form.errors.slug }}
|
||||
</p>
|
||||
</div>
|
||||
<div class="sm:col-span-2 space-y-1">
|
||||
<label class="block text-xs font-medium uppercase tracking-wide text-gray-600"
|
||||
>Opis</label
|
||||
>
|
||||
<textarea
|
||||
v-model="form.description"
|
||||
rows="3"
|
||||
class="w-full border rounded-md px-3 py-2 text-sm focus:ring-indigo-500 focus:border-indigo-500"
|
||||
/>
|
||||
<p v-if="form.errors.description" class="text-xs text-red-600 mt-1">
|
||||
{{ form.errors.description }}
|
||||
</p>
|
||||
</div>
|
||||
<div class="sm:col-span-2 space-y-1">
|
||||
<label class="block text-xs font-medium uppercase tracking-wide text-gray-600"
|
||||
>Veži na vloge</label
|
||||
>
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-2">
|
||||
<label
|
||||
v-for="r in props.roles"
|
||||
:key="r.id"
|
||||
class="inline-flex items-center gap-2 text-sm"
|
||||
>
|
||||
<input
|
||||
type="checkbox"
|
||||
:value="r.id"
|
||||
v-model="form.roles"
|
||||
class="rounded border-gray-300 text-indigo-600 focus:ring-indigo-500"
|
||||
/>
|
||||
<span
|
||||
><span class="font-medium">{{ r.name }}</span>
|
||||
<span class="text-xs text-gray-500">({{ r.slug }})</span></span
|
||||
>
|
||||
</label>
|
||||
</div>
|
||||
<p v-if="form.errors.roles" class="text-xs text-red-600 mt-1">
|
||||
{{ form.errors.roles }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-3 pt-2">
|
||||
<button
|
||||
:disabled="form.processing"
|
||||
type="submit"
|
||||
class="inline-flex items-center gap-2 px-4 py-2 rounded-md bg-indigo-600 text-white text-sm font-medium hover:bg-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-500 disabled:opacity-50"
|
||||
>
|
||||
<FontAwesomeIcon :icon="faSave" class="w-4 h-4" /> Shrani
|
||||
</button>
|
||||
<Link
|
||||
:href="route('admin.permissions.index')"
|
||||
class="text-sm text-gray-500 hover:text-gray-700"
|
||||
>Prekliči</Link
|
||||
>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</AdminLayout>
|
||||
</template>
|
||||
|
|
@ -1,24 +1,30 @@
|
|||
<script setup>
|
||||
import AdminLayout from '@/Layouts/AdminLayout.vue'
|
||||
import { Link, usePage } from '@inertiajs/vue3'
|
||||
import { ref, computed } from 'vue'
|
||||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
|
||||
import { faMagnifyingGlass, faPlus, faKey } from '@fortawesome/free-solid-svg-icons'
|
||||
import AdminLayout from "@/Layouts/AdminLayout.vue";
|
||||
import { Link, usePage } from "@inertiajs/vue3";
|
||||
import { ref, computed } from "vue";
|
||||
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
|
||||
import {
|
||||
faMagnifyingGlass,
|
||||
faPlus,
|
||||
faKey,
|
||||
faPen,
|
||||
} from "@fortawesome/free-solid-svg-icons";
|
||||
|
||||
const props = defineProps({
|
||||
permissions: Array,
|
||||
})
|
||||
});
|
||||
|
||||
const q = ref('')
|
||||
const q = ref("");
|
||||
const filtered = computed(() => {
|
||||
const term = q.value.toLowerCase().trim()
|
||||
if (!term) return props.permissions
|
||||
return props.permissions.filter(p =>
|
||||
const term = q.value.toLowerCase().trim();
|
||||
if (!term) return props.permissions;
|
||||
return props.permissions.filter(
|
||||
(p) =>
|
||||
p.name.toLowerCase().includes(term) ||
|
||||
p.slug.toLowerCase().includes(term) ||
|
||||
(p.description || '').toLowerCase().includes(term)
|
||||
)
|
||||
})
|
||||
(p.description || "").toLowerCase().includes(term)
|
||||
);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
|
@ -30,7 +36,10 @@ const filtered = computed(() => {
|
|||
<h1 class="text-xl font-semibold tracking-tight">Dovoljenja</h1>
|
||||
<p class="text-sm text-gray-500">Pregled vseh sistemskih dovoljenj.</p>
|
||||
</div>
|
||||
<Link :href="route('admin.permissions.create')" class="inline-flex items-center gap-2 px-3 py-2 rounded-md text-xs font-medium bg-indigo-600 text-white hover:bg-indigo-500">
|
||||
<Link
|
||||
:href="route('admin.permissions.create')"
|
||||
class="inline-flex items-center gap-2 px-3 py-2 rounded-md text-xs font-medium bg-indigo-600 text-white hover:bg-indigo-500"
|
||||
>
|
||||
<FontAwesomeIcon :icon="faPlus" class="w-4 h-4" /> Novo
|
||||
</Link>
|
||||
</header>
|
||||
|
|
@ -40,33 +49,78 @@ const filtered = computed(() => {
|
|||
<span class="absolute left-2 top-2 text-gray-400">
|
||||
<FontAwesomeIcon :icon="faMagnifyingGlass" class="w-4 h-4" />
|
||||
</span>
|
||||
<input v-model="q" type="text" placeholder="Išči..." class="pl-8 pr-3 py-1.5 text-sm rounded-md border border-gray-300 focus:ring-indigo-500 focus:border-indigo-500 w-full" />
|
||||
<input
|
||||
v-model="q"
|
||||
type="text"
|
||||
placeholder="Išči..."
|
||||
class="pl-8 pr-3 py-1.5 text-sm rounded-md border border-gray-300 focus:ring-indigo-500 focus:border-indigo-500 w-full"
|
||||
/>
|
||||
</div>
|
||||
<div class="text-xs text-gray-500">
|
||||
{{ filtered.length }} / {{ props.permissions.length }} rezultatov
|
||||
</div>
|
||||
<div class="text-xs text-gray-500">{{ filtered.length }} / {{ props.permissions.length }} rezultatov</div>
|
||||
</div>
|
||||
|
||||
<div class="overflow-x-auto rounded-lg border border-slate-200">
|
||||
<table class="min-w-full text-sm">
|
||||
<thead class="bg-slate-50 text-slate-600">
|
||||
<tr>
|
||||
<th class="p-2 text-left text-[11px] uppercase tracking-wide font-medium">Ime</th>
|
||||
<th class="p-2 text-left text-[11px] uppercase tracking-wide font-medium">Slug</th>
|
||||
<th class="p-2 text-left text-[11px] uppercase tracking-wide font-medium">Opis</th>
|
||||
<th class="p-2 text-left text-[11px] uppercase tracking-wide font-medium">Ustvarjeno</th>
|
||||
<th class="p-2 text-left text-[11px] uppercase tracking-wide font-medium">
|
||||
Ime
|
||||
</th>
|
||||
<th class="p-2 text-left text-[11px] uppercase tracking-wide font-medium">
|
||||
Slug
|
||||
</th>
|
||||
<th class="p-2 text-left text-[11px] uppercase tracking-wide font-medium">
|
||||
Opis
|
||||
</th>
|
||||
<th class="p-2 text-left text-[11px] uppercase tracking-wide font-medium">
|
||||
Ustvarjeno
|
||||
</th>
|
||||
<th class="p-2 text-left text-[11px] uppercase tracking-wide font-medium">
|
||||
Akcije
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="p in filtered" :key="p.id" class="border-t border-slate-100 hover:bg-slate-50/60">
|
||||
<tr
|
||||
v-for="p in filtered"
|
||||
:key="p.id"
|
||||
class="border-t border-slate-100 hover:bg-slate-50/60"
|
||||
>
|
||||
<td class="p-2 whitespace-nowrap font-medium flex items-center gap-2">
|
||||
<span class="inline-flex items-center justify-center h-7 w-7 rounded-md bg-indigo-50 text-indigo-600"><FontAwesomeIcon :icon="faKey" /></span>
|
||||
{{ p.name }}
|
||||
<span
|
||||
class="inline-flex items-center justify-center h-7 w-7 rounded-md bg-indigo-50 text-indigo-600"
|
||||
><FontAwesomeIcon :icon="faKey"
|
||||
/></span>
|
||||
<Link
|
||||
:href="route('admin.permissions.edit', p.id)"
|
||||
class="hover:underline"
|
||||
>{{ p.name }}</Link
|
||||
>
|
||||
</td>
|
||||
<td class="p-2 whitespace-nowrap font-mono text-xs text-gray-600">
|
||||
{{ p.slug }}
|
||||
</td>
|
||||
<td class="p-2 text-xs text-gray-600 max-w-md">
|
||||
{{ p.description || "—" }}
|
||||
</td>
|
||||
<td class="p-2 whitespace-nowrap text-xs text-gray-500">
|
||||
{{ new Date(p.created_at).toLocaleDateString() }}
|
||||
</td>
|
||||
<td class="p-2 whitespace-nowrap text-xs">
|
||||
<Link
|
||||
:href="route('admin.permissions.edit', p.id)"
|
||||
class="inline-flex items-center gap-1 px-2 py-1 rounded-md border border-slate-200 text-slate-700 hover:bg-slate-50"
|
||||
>
|
||||
<FontAwesomeIcon :icon="faPen" class="w-3.5 h-3.5" /> Uredi
|
||||
</Link>
|
||||
</td>
|
||||
<td class="p-2 whitespace-nowrap font-mono text-xs text-gray-600">{{ p.slug }}</td>
|
||||
<td class="p-2 text-xs text-gray-600 max-w-md">{{ p.description || '—' }}</td>
|
||||
<td class="p-2 whitespace-nowrap text-xs text-gray-500">{{ new Date(p.created_at).toLocaleDateString() }}</td>
|
||||
</tr>
|
||||
<tr v-if="!filtered.length">
|
||||
<td colspan="4" class="p-6 text-center text-sm text-gray-500">Ni rezultatov</td>
|
||||
<td colspan="5" class="p-6 text-center text-sm text-gray-500">
|
||||
Ni rezultatov
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
|
|||
|
|
@ -24,6 +24,16 @@ const fmtCurrency = (v) => {
|
|||
return `${n.toFixed(2)} €`;
|
||||
}
|
||||
};
|
||||
|
||||
const fmtDateDMY = (v) => {
|
||||
if (!v) return "-";
|
||||
const d = new Date(v);
|
||||
if (isNaN(d)) return "-";
|
||||
const dd = String(d.getDate()).padStart(2, "0");
|
||||
const mm = String(d.getMonth() + 1).padStart(2, "0");
|
||||
const yyyy = d.getFullYear();
|
||||
return `${dd}.${mm}.${yyyy}`;
|
||||
};
|
||||
</script>
|
||||
<template>
|
||||
<AppLayout title="Client cases">
|
||||
|
|
@ -43,6 +53,7 @@ const fmtCurrency = (v) => {
|
|||
{ key: 'case', label: 'Primer', sortable: false },
|
||||
{ key: 'client', label: 'Stranka', sortable: false },
|
||||
{ key: 'tax', label: 'Davčna', sortable: false },
|
||||
{ key: 'created_at', label: 'Ustvarjeno', sortable: false },
|
||||
{
|
||||
key: 'active_contracts',
|
||||
label: 'Aktivne pogodbe',
|
||||
|
|
@ -97,6 +108,9 @@ const fmtCurrency = (v) => {
|
|||
<template #cell-tax="{ row }">
|
||||
{{ row.person?.tax_number || "-" }}
|
||||
</template>
|
||||
<template #cell-created_at="{ row }">
|
||||
{{ fmtDateDMY(row.created_at) }}
|
||||
</template>
|
||||
<template #cell-active_contracts="{ row }">
|
||||
<div class="text-right">{{ row.active_contracts_count ?? 0 }}</div>
|
||||
</template>
|
||||
|
|
|
|||
|
|
@ -52,6 +52,8 @@
|
|||
Route::get('permissions', [\App\Http\Controllers\Admin\PermissionController::class, 'index'])->name('permissions.index');
|
||||
Route::get('permissions/create', [\App\Http\Controllers\Admin\PermissionController::class, 'create'])->name('permissions.create');
|
||||
Route::post('permissions', [\App\Http\Controllers\Admin\PermissionController::class, 'store'])->name('permissions.store');
|
||||
Route::get('permissions/{permission}/edit', [\App\Http\Controllers\Admin\PermissionController::class, 'edit'])->name('permissions.edit');
|
||||
Route::put('permissions/{permission}', [\App\Http\Controllers\Admin\PermissionController::class, 'update'])->name('permissions.update');
|
||||
|
||||
// Document templates & global document settings
|
||||
Route::get('document-templates', [\App\Http\Controllers\Admin\DocumentTemplateController::class, 'index'])->name('document-templates.index');
|
||||
|
|
|
|||
38
tests/Feature/PermissionRoleBindingTest.php
Normal file
38
tests/Feature/PermissionRoleBindingTest.php
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Permission;
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
it('binds selected roles to a newly created permission', function () {
|
||||
// Create admin user with manage-settings permission via a role
|
||||
$admin = User::factory()->create();
|
||||
$role = Role::create(['name' => 'Admin', 'slug' => 'admin']);
|
||||
$admin->roles()->syncWithoutDetaching([$role->id]);
|
||||
|
||||
// Grant manage-settings to the role so controller authorize passes
|
||||
$permManage = Permission::create(['name' => 'Manage Settings', 'slug' => 'manage-settings']);
|
||||
$role->permissions()->syncWithoutDetaching([$permManage->id]);
|
||||
|
||||
// Create some roles to bind
|
||||
$r1 = Role::create(['name' => 'Editor', 'slug' => 'editor']);
|
||||
$r2 = Role::create(['name' => 'Viewer', 'slug' => 'viewer']);
|
||||
|
||||
// Act
|
||||
$response = $this->actingAs($admin)
|
||||
->post(route('admin.permissions.store'), [
|
||||
'name' => 'Export Data',
|
||||
'slug' => 'export-data',
|
||||
'description' => 'Can export data',
|
||||
'roles' => [$r1->id, $r2->id],
|
||||
]);
|
||||
|
||||
$response->assertRedirect();
|
||||
|
||||
$permission = Permission::where('slug', 'export-data')->firstOrFail();
|
||||
expect($permission->roles()->pluck('slug')->sort()->values()->all())
|
||||
->toEqualCanonicalizing(['editor', 'viewer']);
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user