Skip to content

Commit 8aab2a3

Browse files
committed
UP
1 parent 888e32c commit 8aab2a3

File tree

4 files changed

+34
-11
lines changed

4 files changed

+34
-11
lines changed

resources/views/livewire/column.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class="ml-2 px-2.5 py-0.5 rounded-full text-xs font-medium kanban-color-{{ $colu
1414
{{ $column['total'] ?? (isset($column['items']) ? count($column['items']) : 0) }}
1515
</div>
1616
</div>
17-
@if($permissions['create'])
17+
@if($permissions['canCreate'])
1818
<button
1919
type="button"
2020
wire:click="openCreateForm('{{ $columnId }}')"

resources/views/livewire/kanban-board.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ class="w-full h-full flex flex-col relative"
2929
</div>
3030
</div>
3131

32-
<x-flowforge::modals.create-card :config="$config" />
33-
<x-flowforge::modals.edit-card :config="$config" />
32+
<x-flowforge::modals.create-card :permissions="$this->permissions" :config="$config" />
33+
<x-flowforge::modals.edit-card :permissions="$this->permissions" :config="$config" />
3434
</div>

resources/views/livewire/modals/edit-card.blade.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
@props(['config'])
1+
@props(['config', 'permissions'])
22

33
<x-filament::modal id="edit-card-modal" :heading="__('Edit :cardLabel', ['cardLabel' => $config->cardLabel ?? 'Card'])">
44
{{ $this->editRecordForm }}
55

66
<x-slot name="footer">
77
<div class="flex items-center justify-between">
8-
<x-filament::button
9-
color="danger"
10-
wire:click="deleteRecord"
11-
>
12-
{{ __('Delete') }}
13-
</x-filament::button>
8+
@if($this->permissions['canDelete'])
9+
<x-filament::button
10+
color="danger"
11+
wire:click="deleteRecord"
12+
>
13+
{{ __('Delete') }}
14+
</x-filament::button>
15+
@endif
16+
17+
1418

1519
<div class="flex gap-x-3">
1620
<x-filament::button

src/Livewire/KanbanBoard.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ public function mount(
115115

116116
// Check permissions
117117
$this->permissions = [
118-
'create' => Gate::check('create', $this->adapter->baseQuery->getModel())
118+
'canCreate' => Gate::check('create', $this->adapter->baseQuery->getModel()),
119+
'canDelete' => Gate::check('delete', $this->adapter->baseQuery->getModel()),
119120
];
120121

121122
// Set default limits
@@ -370,6 +371,15 @@ public function openEditForm(string|int $recordId, string|int $columnId): void
370371
*/
371372
public function createRecord(): void
372373
{
374+
if(! $this->permissions['canCreate']) {
375+
Notification::make()
376+
->title('You do not have permission to create records')
377+
->danger()
378+
->send();
379+
380+
return;
381+
}
382+
373383
// Use form state to get data with validation applied
374384
$data = $this->createRecordForm->getState();
375385

@@ -482,6 +492,15 @@ public function confirmDelete(string|int $cardId, string $columnId): void
482492
*/
483493
public function deleteRecord(): void
484494
{
495+
if (! $this->permissions['canDelete']) {
496+
Notification::make()
497+
->title('You do not have permission to delete records')
498+
->danger()
499+
->send();
500+
501+
return;
502+
}
503+
485504
$record = $this->adapter->getModelById($this->currentRecord);
486505

487506
if (!$record) {

0 commit comments

Comments
 (0)