1 | <?php |
||
33 | class APIKeyPolicy |
||
34 | { |
||
35 | /** |
||
36 | * Checks if the API key has permission to perform an action. |
||
37 | * |
||
38 | * @param \Pterodactyl\Models\User $user |
||
39 | * @param \Pterodactyl\Models\APIKey $key |
||
40 | * @param string $permission |
||
41 | * @return bool |
||
42 | */ |
||
43 | protected function checkPermission(User $user, Key $key, $permission) |
||
44 | { |
||
45 | // Non-administrative users cannot use administrative routes. |
||
46 | if (! starts_with($key, 'user.') && ! $user->isRootAdmin()) { |
||
47 | return false; |
||
48 | } |
||
49 | |||
50 | // We don't tag this cache key with the user uuid because the key is already unique, |
||
51 | // and multiple users are not defiend for a single key. |
||
52 | $permissions = Cache::remember('APIKeyPolicy.' . $key->public, Carbon::now()->addSeconds(5), function () use ($key) { |
||
53 | return $key->permissions()->get()->transform(function ($item) { |
||
54 | return $item->permission; |
||
55 | })->values(); |
||
56 | }); |
||
57 | |||
58 | return $permissions->search($permission, true) !== false; |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * Determine if a user has permission to perform this action against the system. |
||
63 | * |
||
64 | * @param \Pterodactyl\Models\User $user |
||
65 | * @param string $permission |
||
66 | * @param \Pterodactyl\Models\APIKey $key |
||
67 | * @return bool |
||
68 | */ |
||
69 | public function before(User $user, $permission, Key $key) |
||
73 | } |
||
74 |