/
RootAlbumRightsResource.php
38 lines (34 loc) · 1.12 KB
/
RootAlbumRightsResource.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
namespace App\Http\Resources\Rights;
use App\Contracts\Models\AbstractAlbum;
use App\Policies\AlbumPolicy;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\Gate;
/**
* Data Transfer Object (DTO) to transmit the rights of an user at the root level.
*/
class RootAlbumRightsResource extends JsonResource
{
public function __construct()
{
// Laravel applies a shortcut when this value === null but not when it is something else.
parent::__construct('must_not_be_null');
}
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
*
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request)
{
return [
// Needed to allow interaction such as moving albums
'can_edit' => Gate::check(AlbumPolicy::CAN_UPLOAD, [AbstractAlbum::class, null]),
// Needed to allow upload at root level (into unsorted)
'can_upload' => Gate::check(AlbumPolicy::CAN_UPLOAD, [AbstractAlbum::class, null]),
'can_import_from_server' => Gate::check(AlbumPolicy::CAN_IMPORT_FROM_SERVER, [AbstractAlbum::class]),
];
}
}