calendar icon indicating copy to clipboard operation
calendar copied to clipboard

[Bug]: onEventClick does not pass Policy because action is null

Open juienpro opened this issue 1 year ago • 0 comments

What happened?

When I set $defaultEventClickAction, it does not pass policy in onEventClick in HandlesEventClick.php.

I think that the default action should be loaded before $this->authorize.

How to reproduce the bug

 public function onEventClick(array $info = [], ?string $action = null): void
    {
        \Log::debug('action: '.$action);
        try {
            $model = data_get($info, 'event.extendedProps.model');
            $key = data_get($info, 'event.extendedProps.key');
            \Log::debug('toto');
            if ($model && $key) {
                $this->resolveEventRecord(
                    data_get($info, 'event.extendedProps.model'),
                    data_get($info, 'event.extendedProps.key'),
                );

                \Log::debug('toto2');
                \Log::debug(print_r($action, true));
                $this->authorize(match ($action) {
                    'edit' => 'update',
                    default => $action,
                }, [$this->eventRecord]);

                \Log::debug('toto3');
                $action ??= data_get($info, 'event.extendedProps.action', $this->getDefaultEventClickAction());
                if ($action) {
                    $this->mountAction($action, [
                        'event' => data_get($info, 'event', []),
                    ]);
                }
            }
        } catch (AuthorizationException $e) {
            return;
        }
    }

The debug message toto3 is never displayed, while toto2 is shown. Except if I miss something, It's likely that the line:

$action ??= data_get($info, 'event.extendedProps.action', $this->getDefaultEventClickAction());

should be put before $this->authorize.

Package Version

1.7

PHP Version

8.2.0

Laravel Version

11.0.0

Which operating systems does with happen with?

Linux

Notes

No response

juienpro avatar Sep 23 '24 10:09 juienpro