Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Http/Requests/Api/Remote/ActivityEventRequest.php
10266 views
1
<?php
2
3
namespace Pterodactyl\Http\Requests\Api\Remote;
4
5
use Illuminate\Support\Collection;
6
use Illuminate\Foundation\Http\FormRequest;
7
8
class ActivityEventRequest extends FormRequest
9
{
10
public function authorize(): bool
11
{
12
return true;
13
}
14
15
public function rules(): array
16
{
17
return [
18
'data' => ['required', 'array'],
19
'data.*' => ['array'],
20
'data.*.user' => ['sometimes', 'nullable', 'uuid'],
21
'data.*.server' => ['required', 'uuid'],
22
'data.*.event' => ['required', 'string'],
23
'data.*.metadata' => ['present', 'nullable', 'array'],
24
'data.*.ip' => ['sometimes', 'nullable', 'ip'],
25
'data.*.timestamp' => ['required', 'string'],
26
];
27
}
28
29
/**
30
* Returns all the unique server UUIDs that were received in this request.
31
*/
32
public function servers(): array
33
{
34
return Collection::make($this->input('data'))->pluck('server')->unique()->toArray();
35
}
36
37
/**
38
* Returns all the unique user UUIDs that were submitted in this request.
39
*/
40
public function users(): array
41
{
42
return Collection::make($this->input('data'))
43
->filter(function ($value) {
44
return !empty($value['user']);
45
})
46
->pluck('user')
47
->unique()
48
->toArray();
49
}
50
}
51
52