Skip to content

Commit

Permalink
Authorieze to any action if gates are not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Bubyakin committed Dec 30, 2018
1 parent 26ad4ee commit fe74200
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Fields/Medialibrary.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,17 @@ public function serializeMedia(MediaModel $media): array
'extension' => $media->extension,
'downloadUrl' => $media->getFullUrl(),
'thumbnailUrl' => $this->isImage($media) ? call_user_func($this->thumbnailUrlCallback, $media) : null,
'authorizedToView' => Gate::check('view', $media),
'authorizedToUpdate' => Gate::check('update', $media),
'authorizedToDelete' => Gate::check('delete', $media),
'authorizedToView' => $this->authorizedTo('view', $media),
'authorizedToUpdate' => $this->authorizedTo('update', $media),
'authorizedToDelete' => $this->authorizedTo('delete', $media),
];
}

protected function authorizedTo(string $ability, MediaModel $media): bool
{
return Gate::getPolicyFor($media) ? Gate::check($ability, $media) : true;
}

public function meta(): array
{
return array_merge([
Expand Down

0 comments on commit fe74200

Please sign in to comment.