From b996316d923ef12169b4ddecacccab88ede5b1ee Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Fri, 8 Jan 2016 22:22:57 -0500 Subject: [PATCH] Fixes some permissions stuff --- app/Policies/ServerPolicy.php | 34 ++++++++++++- app/Providers/AuthServiceProvider.php | 6 +-- resources/views/layouts/master.blade.php | 6 +-- resources/views/server/index.blade.php | 64 +++++++++++++----------- 4 files changed, 71 insertions(+), 39 deletions(-) diff --git a/app/Policies/ServerPolicy.php b/app/Policies/ServerPolicy.php index 2f9355cca..1922ce56e 100644 --- a/app/Policies/ServerPolicy.php +++ b/app/Policies/ServerPolicy.php @@ -2,8 +2,6 @@ namespace Pterodactyl\Policies; -use Log; -use Debugbar; use Pterodactyl\Models\User; use Pterodactyl\Models\Server; @@ -191,4 +189,36 @@ class ServerPolicy return $user->permissions()->server($server)->permission('set-connection')->exists(); } + /** + * Check if user has permission to view subusers for the server. + * + * @param Pterodactyl\Models\User $user + * @param Pterodactyl\Models\Server $server + * @return boolean + */ + public function viewSubusers(User $user, Server $server) + { + if ($this->isOwner($user, $server)) { + return true; + } + + return $user->permissions()->server($server)->permission('view-subusers')->exists(); + } + + /** + * Check if user has permission to view the server management page. + * + * @param Pterodactyl\Models\User $user + * @param Pterodactyl\Models\Server $server + * @return boolean + */ + public function viewManage(User $user, Server $server) + { + if ($this->isOwner($user, $server)) { + return true; + } + + return $user->permissions()->server($server)->permission('view-manage')->exists(); + } + } diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index f7062f7b4..757101e2d 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -2,9 +2,6 @@ namespace Pterodactyl\Providers; -use Pterodactyl\Models\Server; -use Pterodactyl\Policies\ServerPolicy; - use Illuminate\Contracts\Auth\Access\Gate as GateContract; use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; @@ -16,8 +13,7 @@ class AuthServiceProvider extends ServiceProvider * @var array */ protected $policies = [ - 'Pterodactyl\Model' => 'Pterodactyl\Policies\ModelPolicy', - Server::class => ServerPolicy::class, + 'Pterodactyl\Models\Server' => 'Pterodactyl\Policies\ServerPolicy' ]; /** diff --git a/resources/views/layouts/master.blade.php b/resources/views/layouts/master.blade.php index 0da099b4f..b5cfa3e6f 100644 --- a/resources/views/layouts/master.blade.php +++ b/resources/views/layouts/master.blade.php @@ -193,9 +193,9 @@
{{ trans('pagination.sidebar.server_controls') }} {{ trans('pagination.sidebar.overview') }} - {{ trans('pagination.sidebar.files') }} - {{ trans('pagination.sidebar.subusers') }} - {{ trans('pagination.sidebar.manage') }} + @can('list-files', Auth::user()){{ trans('pagination.sidebar.files') }}@endcan + @can('view-subusers', Auth::user()){{ trans('pagination.sidebar.subusers') }}@endcan + @can('view-manage', Auth::user()){{ trans('pagination.sidebar.manage') }}@endcan
@endif @show diff --git a/resources/views/server/index.blade.php b/resources/views/server/index.blade.php index 610529ded..598a4c6c2 100644 --- a/resources/views/server/index.blade.php +++ b/resources/views/server/index.blade.php @@ -14,7 +14,7 @@
@@ -27,26 +27,30 @@

- - + @can('command', $server) + + + @endcan

- - - - - - + @can('power', $server) + + + + + + + @endcan
@@ -74,19 +78,21 @@
-
-
-
-
-
Below is a listing of all avaliable IPs and Ports for your service. To change the default connection address for your server, simply click on the one you would like to make default below.
- + @can('allocation', $server) +
+
+
+
+
Below is a listing of all avaliable IPs and Ports for your service. To change the default connection address for your server, simply click on the one you would like to make default below.
+ +
-
+ @endcan