Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,21 @@ protected static function getEditEventFormSchema(): array

## Authorizing actions

If you want to authorize the `view` action, you can override the default authorization methods that comes with this package.

```php
public static function canView(?array $event = null): bool
{
// When event is null, MAKE SURE you allow View otherwise the entire widget/calendar won't be rendered
if ($event === null) {
return true;
}

// Returning 'false' will not show the event Modal.
return true;
}
```

If you want to authorize the `edit` or `create` action, you can override the default authorization methods that comes with this package.

```php
Expand Down
31 changes: 23 additions & 8 deletions resources/views/components/edit-event-modal.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
<x-filament::modal id="fullcalendar--edit-event-modal" :width="$this->getModalWidth()">
<x-slot name="header">
<x-filament::modal.heading>
{{ __('filament::resources/pages/edit-record.title', ['label' => $this->getModalLabel()]) }}
{{
$this->editEventForm->isDisabled()
? __('filament::resources/pages/view-record.title', ['label' => $this->getModalLabel()])
: __('filament::resources/pages/edit-record.title', ['label' => $this->getModalLabel()])
}}
</x-filament::modal.heading>
</x-slot>

Expand All @@ -13,19 +17,30 @@
{{ $this->editEventForm }}

<x-slot name="footer">
<x-filament::button type="submit" form="onEditEventSubmit">
{{ __('filament::resources/pages/edit-record.form.actions.save.label') }}
</x-filament::button>
@if(!$this->editEventForm->isDisabled())
<x-filament::button type="submit" form="onEditEventSubmit">
{{ __('filament::resources/pages/edit-record.form.actions.save.label') }}
</x-filament::button>
@endif

@if($this->isListeningCancelledEditModal())
<x-filament::button color="secondary" x-on:click="isOpen = false; Livewire.emit('cancelledFullcalendarEditEventModal')">
{{ __('filament::resources/pages/edit-record.form.actions.cancel.label') }}
<x-filament::button color="secondary"
x-on:click="isOpen = false; Livewire.emit('cancelledFullcalendarEditEventModal')">
{{
$this->editEventForm->isDisabled()
? __('filament-support::actions/view.single.modal.actions.close.label')
: __('filament::resources/pages/edit-record.form.actions.cancel.label')
}}
</x-filament::button>
@else
<x-filament::button color="secondary" x-on:click="isOpen = false">
{{ __('filament::resources/pages/edit-record.form.actions.cancel.label') }}
{{
$this->editEventForm->isDisabled()
? __('filament-support::actions/view.single.modal.actions.close.label')
: __('filament::resources/pages/edit-record.form.actions.cancel.label')
}}
</x-filament::button>
@endif
@endif
</x-slot>
</x-filament::modal>
</x-filament::form>
10 changes: 10 additions & 0 deletions src/Widgets/Concerns/AuthorizesActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@

trait AuthorizesActions
{
public static function canView(?array $event = null): bool
{
// If we want to prevent breaking changes, we need to "fallback"
// to "canEdit(Event)". Not doing that since the new behaviour
// is likely the desired one. The fallback would be:
// return static::canEdit($event);

return true;
}

public static function canCreate(): bool
{
return true;
Expand Down
14 changes: 8 additions & 6 deletions src/Widgets/Concerns/CanManageEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
namespace Saade\FilamentFullCalendar\Widgets\Concerns;

use Closure;
use Filament\Forms\ComponentContainer;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Carbon;
use Saade\FilamentFullCalendar\Widgets\Forms\CreateEventForm;
use Saade\FilamentFullCalendar\Widgets\Forms\EditEventForm;
use Saade\FilamentFullCalendar\Widgets\FullCalendarWidget;

/**
* @property \Filament\Forms\ComponentContainer $createEventForm
* @property \Filament\Forms\ComponentContainer $editEventForm
* @property ComponentContainer $createEventForm
* @property ComponentContainer $editEventForm
*/
trait CanManageEvents
{
Expand All @@ -22,7 +23,6 @@ trait CanManageEvents
use EvaluateClosures;

public ?int $event_id = null;

public ?Model $event = null;

protected function setUpForms(): void
Expand All @@ -46,11 +46,13 @@ protected function getForms(): array

public function onEventClick($event): void
{
if (! static::canEdit($event)) {
if (!static::canView($event)) {
return;
}

$this->editEventForm->fill($event);
$this->editEventForm
->disabled(!static::canView($event))
->fill($event);

if (method_exists($this, 'resolveEventRecord')) {
$this->event = $this->resolveEventRecord($event);
Expand All @@ -63,7 +65,7 @@ public function onEventClick($event): void

public function onCreateEventClick(array $date): void
{
if (! static::canCreate()) {
if (!static::canCreate()) {
return;
}

Expand Down