Skip to content

Commit 75b8753

Browse files
committed
Simplify server and api key policy.
1 parent c492446 commit 75b8753

File tree

2 files changed

+12
-629
lines changed

2 files changed

+12
-629
lines changed

app/Policies/APIKeyPolicy.php

Lines changed: 6 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class APIKeyPolicy
4040
* @param string $permission
4141
* @return bool
4242
*/
43-
private function checkPermission(User $user, Key $key, $permission)
43+
protected function checkPermission(User $user, Key $key, $permission)
4444
{
4545
// We don't tag this cache key with the user uuid because the key is already unique,
4646
// and multiple users are not defiend for a single key.
@@ -54,162 +54,15 @@ private function checkPermission(User $user, Key $key, $permission)
5454
}
5555

5656
/**
57+
* Determine if a user has permission to perform this action against the system.
58+
*
5759
* @param \Pterodactyl\Models\User $user
60+
* @param string $permission
5861
* @param \Pterodactyl\Models\APIKey $key
5962
* @return bool
6063
*/
61-
public function locationList(User $user, Key $key)
62-
{
63-
return $this->checkPermission($user, $key, 'location-list');
64-
}
65-
66-
/**
67-
* @param \Pterodactyl\Models\User $user
68-
* @param \Pterodactyl\Models\APIKey $key
69-
* @return bool
70-
*/
71-
public function serverList(User $user, Key $key)
72-
{
73-
return $this->checkPermission($user, $key, 'server-list');
74-
}
75-
76-
/**
77-
* @param \Pterodactyl\Models\User $user
78-
* @param \Pterodactyl\Models\APIKey $key
79-
* @return bool
80-
*/
81-
public function serverView(User $user, Key $key)
82-
{
83-
return $this->checkPermission($user, $key, 'server-view');
84-
}
85-
86-
/**
87-
* @param \Pterodactyl\Models\User $user
88-
* @param \Pterodactyl\Models\APIKey $key
89-
* @return bool
90-
*/
91-
public function serverCreate(User $user, Key $key)
92-
{
93-
return $this->checkPermission($user, $key, 'server-create');
94-
}
95-
96-
/**
97-
* @param \Pterodactyl\Models\User $user
98-
* @param \Pterodactyl\Models\APIKey $key
99-
* @return bool
100-
*/
101-
public function serverDelete(User $user, Key $key)
102-
{
103-
return $this->checkPermission($user, $key, 'server-delete');
104-
}
105-
106-
/**
107-
* @param \Pterodactyl\Models\User $user
108-
* @param \Pterodactyl\Models\APIKey $key
109-
* @return bool
110-
*/
111-
public function serverEditDetails(User $user, Key $key)
112-
{
113-
return $this->checkPermission($user, $key, 'server-edit-details');
114-
}
115-
116-
/**
117-
* @param \Pterodactyl\Models\User $user
118-
* @param \Pterodactyl\Models\APIKey $key
119-
* @return bool
120-
*/
121-
public function serverEditContainer(User $user, Key $key)
122-
{
123-
return $this->checkPermission($user, $key, 'server-edit-container');
124-
}
125-
126-
/**
127-
* @param \Pterodactyl\Models\User $user
128-
* @param \Pterodactyl\Models\APIKey $key
129-
* @return bool
130-
*/
131-
public function serverEditBuild(User $user, Key $key)
132-
{
133-
return $this->checkPermission($user, $key, 'server-edit-build');
134-
}
135-
136-
/**
137-
* @param \Pterodactyl\Models\User $user
138-
* @param \Pterodactyl\Models\APIKey $key
139-
* @return bool
140-
*/
141-
public function serverEditStartup(User $user, Key $key)
142-
{
143-
return $this->checkPermission($user, $key, 'server-edit-startup');
144-
}
145-
146-
/**
147-
* @param \Pterodactyl\Models\User $user
148-
* @param \Pterodactyl\Models\APIKey $key
149-
* @return bool
150-
*/
151-
public function serverSuspend(User $user, Key $key)
152-
{
153-
return $this->checkPermission($user, $key, 'server-suspend');
154-
}
155-
156-
/**
157-
* @param \Pterodactyl\Models\User $user
158-
* @param \Pterodactyl\Models\APIKey $key
159-
* @return bool
160-
*/
161-
public function servrerInstall(User $user, Key $key)
162-
{
163-
return $this->checkPermission($user, $key, 'server-install');
164-
}
165-
166-
/**
167-
* @param \Pterodactyl\Models\User $user
168-
* @param \Pterodactyl\Models\APIKey $key
169-
* @return bool
170-
*/
171-
public function serverRebuild(User $user, Key $key)
172-
{
173-
return $this->checkPermission($user, $key, 'server-rebuild');
174-
}
175-
176-
/**
177-
* @param \Pterodactyl\Models\User $user
178-
* @param \Pterodactyl\Models\APIKey $key
179-
* @return bool
180-
*/
181-
public function userServerList(User $user, Key $key)
182-
{
183-
return $this->checkPermission($user, $key, 'user-server-list');
184-
}
185-
186-
/**
187-
* @param \Pterodactyl\Models\User $user
188-
* @param \Pterodactyl\Models\APIKey $key
189-
* @return bool
190-
*/
191-
public function userServerView(User $user, Key $key)
192-
{
193-
return $this->checkPermission($user, $key, 'user-server-view');
194-
}
195-
196-
/**
197-
* @param \Pterodactyl\Models\User $user
198-
* @param \Pterodactyl\Models\APIKey $key
199-
* @return bool
200-
*/
201-
public function userServerPower(User $user, Key $key)
202-
{
203-
return $this->checkPermission($user, $key, 'user-server-power');
204-
}
205-
206-
/**
207-
* @param \Pterodactyl\Models\User $user
208-
* @param \Pterodactyl\Models\APIKey $key
209-
* @return bool
210-
*/
211-
public function userServerCommand(User $user, Key $key)
64+
public function before(User $user, $permission, Key $key)
21265
{
213-
return $this->checkPermission($user, $key, 'user-server-command');
66+
return $this->checkPermission($user, $key, $permission);
21467
}
21568
}

0 commit comments

Comments
 (0)