Add collection name to auth
This commit is contained in:
parent
bcf708ecc3
commit
c385212f75
|
@ -25,9 +25,9 @@ class MediaController
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$model = $this->validateModel($request);
|
$model = $this->validateModel($request);
|
||||||
$this->authorize('storeMedia', $model);
|
|
||||||
$collection = $model->getMediaCollection($request->input('collection'));
|
$collection = $model->getMediaCollection($request->input('collection'));
|
||||||
$isSingle = 1 === $collection->collectionSizeLimit;
|
$isSingle = 1 === $collection->collectionSizeLimit;
|
||||||
|
$this->authorize('storeMedia', [$model, $collection->name]);
|
||||||
|
|
||||||
$request->validate($isSingle ? [
|
$request->validate($isSingle ? [
|
||||||
'payload' => 'array',
|
'payload' => 'array',
|
||||||
|
@ -62,7 +62,7 @@ class MediaController
|
||||||
|
|
||||||
public function update(Request $request, Media $media): MediaData
|
public function update(Request $request, Media $media): MediaData
|
||||||
{
|
{
|
||||||
$this->authorize('updateMedia', $media->model);
|
$this->authorize('updateMedia', [$media->model, $media->collection_name]);
|
||||||
|
|
||||||
$rules = collect($media->model->getMediaCollection($media->collection_name)->runCallback('withPropertyValidation', $media->file_name))
|
$rules = collect($media->model->getMediaCollection($media->collection_name)->runCallback('withPropertyValidation', $media->file_name))
|
||||||
->mapWithKeys(fn ($rule, $key) => ["properties.{$key}" => $rule])->toArray();
|
->mapWithKeys(fn ($rule, $key) => ["properties.{$key}" => $rule])->toArray();
|
||||||
|
@ -78,7 +78,7 @@ class MediaController
|
||||||
{
|
{
|
||||||
$model = app('media-library-helpers')->get($parentModel);
|
$model = app('media-library-helpers')->get($parentModel);
|
||||||
$model = $model::find($parentId);
|
$model = $model::find($parentId);
|
||||||
$this->authorize('listMedia', $model);
|
$this->authorize('listMedia', [$model, $collectionName]);
|
||||||
$collection = $model->getMediaCollection($collectionName);
|
$collection = $model->getMediaCollection($collectionName);
|
||||||
$isSingle = 1 === $collection->collectionSizeLimit;
|
$isSingle = 1 === $collection->collectionSizeLimit;
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ class MediaController
|
||||||
|
|
||||||
public function destroy(Media $media, Request $request): JsonResponse
|
public function destroy(Media $media, Request $request): JsonResponse
|
||||||
{
|
{
|
||||||
$this->authorize('destroyMedia', $media->model);
|
$this->authorize('destroyMedia', [$media->model, $media->collection_name]);
|
||||||
$media->delete();
|
$media->delete();
|
||||||
|
|
||||||
return response()->json([]);
|
return response()->json([]);
|
||||||
|
|
|
@ -74,7 +74,7 @@ class TestCase extends BaseTestCase
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($policies as $ability => $result) {
|
foreach ($policies as $ability => $result) {
|
||||||
Gate::define($ability, fn (?string $whatever) => $result);
|
Gate::define($ability, fn (?string $user, string $collectionName) => $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|
Loading…
Reference in New Issue