forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubuserTransformer.php
More file actions
55 lines (48 loc) · 1.43 KB
/
Copy pathSubuserTransformer.php
File metadata and controls
55 lines (48 loc) · 1.43 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
namespace Pterodactyl\Transformers\Api\Client;
use Illuminate\Support\Str;
use Pterodactyl\Models\Subuser;
class SubuserTransformer extends BaseClientTransformer
{
protected $availableIncludes = ['permissions'];
/**
* Return the resource name for the JSONAPI output.
*
* @return string
*/
public function getResourceName(): string
{
return Subuser::RESOURCE_NAME;
}
/**
* Transforms a User model into a representation that can be shown to regular
* users of the API.
*
* @param \Pterodactyl\Models\Subuser $model
* @return array
*/
public function transform(Subuser $model)
{
$user = $model->user;
return [
'uuid' => $user->uuid,
'username' => $user->username,
'email' => $user->email,
'image' => 'https://gravatar.com/avatar/' . md5(Str::lower($user->email)),
'2fa_enabled' => $user->use_totp,
'created_at' => $model->created_at->toIso8601String(),
];
}
/**
* Include the permissions associated with this subuser.
*
* @param \Pterodactyl\Models\Subuser $model
* @return \League\Fractal\Resource\Item
*/
public function includePermissions(Subuser $model)
{
return $this->item($model, function (Subuser $model) {
return ['permissions' => $model->permissions->pluck('permission')];
});
}
}