diff --git a/app/Console/Commands/PluginEnable.php b/app/Console/Commands/PluginEnable.php index 325855d2f8..5cb022bbe6 100644 --- a/app/Console/Commands/PluginEnable.php +++ b/app/Console/Commands/PluginEnable.php @@ -40,6 +40,9 @@ class PluginEnable extends LnmsCommand return 0; } + //Caching application Routes + $this->callSilent('route:cache'); + $this->info(trans_choice('commands.plugin:enable.enabled', $updated, ['count' => $updated])); return 0; diff --git a/app/Plugins/ExamplePlugin/DeviceOverview.php b/app/Plugins/ExamplePlugin/DeviceOverview.php index 92d8f2dd6d..ac88da665a 100644 --- a/app/Plugins/ExamplePlugin/DeviceOverview.php +++ b/app/Plugins/ExamplePlugin/DeviceOverview.php @@ -35,7 +35,7 @@ class DeviceOverview extends DeviceOverviewHook // public string $view = 'resources.views.device-overview'; - public function authorize(\App\Models\User $user, \App\Models\Device $device): bool + public function authorize(\Illuminate\Contracts\Auth\Authenticatable $user, \App\Models\Device $device): bool { // In this example, we check if the user has a custom role/permission and if it is member of any device groups // return $user->can('view-extra-port-info') && $device->has('groups'); diff --git a/app/Plugins/ExamplePlugin/Menu.php b/app/Plugins/ExamplePlugin/Menu.php index 7a2101f7ad..c36f4a1b1f 100644 --- a/app/Plugins/ExamplePlugin/Menu.php +++ b/app/Plugins/ExamplePlugin/Menu.php @@ -15,12 +15,18 @@ class Menu extends MenuEntryHook // public string $view = 'resources.views.menu'; // this will determine if the menu entry should be shown to the user - public function authorize(\App\Models\User $user, array $settings = []): bool + public function authorize(\Illuminate\Contracts\Auth\Authenticatable $user, array $settings = []): bool { - // menu entry shown if users has the global-read role and there is a setting that has > one entries in it -// return $user->can('global-read') && isset($settings['some_data']) && count($settings['some_data']) > 0; + /** + * // menu entry shown if users has the global-read role and there is a setting that has > one entries in it + * return $user->can('global-read') && isset($settings['some_data']) && count($settings['some_data']) > 0; + * + * // allow every logged in user + * return true; + **/ - return true; // allow every logged in user + // Allow users with GLOBAL_READ or better + return $user->can('global-read'); } // override the data function to add additional data to be accessed in the view diff --git a/app/Plugins/ExamplePlugin/Page.php b/app/Plugins/ExamplePlugin/Page.php index 78f320bec0..6772a0c066 100644 --- a/app/Plugins/ExamplePlugin/Page.php +++ b/app/Plugins/ExamplePlugin/Page.php @@ -39,7 +39,7 @@ class Page extends PageHook // The authorize method will determine if the user has access to this page. // if you want all users to be able to access this page simple return true - public function authorize(\App\Models\User $user): bool + public function authorize(\Illuminate\Contracts\Auth\Authenticatable $user): bool { // you can check user's roles like this: // return $user->can('admin'); diff --git a/app/Plugins/ExamplePlugin/PortTab.php b/app/Plugins/ExamplePlugin/PortTab.php index aa91728f60..e427ecac28 100644 --- a/app/Plugins/ExamplePlugin/PortTab.php +++ b/app/Plugins/ExamplePlugin/PortTab.php @@ -28,4 +28,17 @@ class PortTab extends PortTabHook 'total' => $total_delta, ]; } + + // The authorize method will determine if the user will see this tab or not + // if you want all users to see it, simple return true + public function authorize(\Illuminate\Contracts\Auth\Authenticatable $user, \App\Models\Port $port): bool + { + // you can check user's roles like this: +// return $user->can('admin'); + + // or use whatever you like. Including conditions on the \App\Models\Port $port of course +// return \Carbon\Carbon::now()->dayOfWeek == Carbon::THURSDAY; // only allowed access on Thursdays! + + return true; // allow every logged in user to access + } } diff --git a/doc/Extensions/Plugin-System.md b/doc/Extensions/Plugin-System.md index b861be0a82..3c78cf5063 100644 --- a/doc/Extensions/Plugin-System.md +++ b/doc/Extensions/Plugin-System.md @@ -137,7 +137,7 @@ https://laravel.com/docs/packages > This is untested, please come to discord and share any expriences and update this documentation! -## Version 1 Plugin System structure (legacy verion) +## Version 1 Plugin System structure (legacy version) Plugins need to be installed into html/plugins