Skip to content

Commit

Permalink
Merge branch 'release/1.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
adrenth committed Jul 28, 2021
2 parents 5293466 + fc6fce1 commit 2669e86
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 28 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea
vendor
composer.lock
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## 1.0.0 - 2021-07-28

First experimental version of this plugin.

>**It is not recommended to install this plugin on production environments!**
2 changes: 1 addition & 1 deletion Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function pluginDetails(): array

public function register(): void
{
if (!in_array($this->app->environment(), ['local', 'dev'], true)) {
if ($this->app->environment('local') === false) {
return;
}

Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ Create configuration file in `config/telescope.php`:
php artisan vendor:publish --tag telescope-config
```

## Permissions

- Users must have the proper permissions to access the Telescope Dashboard.
- If backend user is not logged in, access to the Telescope Dashboard will not be granted.

## Switching themes

> Each time you switch the default theme you need to re-publish the Telescope assets.
Expand Down
4 changes: 1 addition & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
},
"archive": {
"exclude": [
".editorconfig",
".gitattributes",
".github",
".gitignore",
".gitlab-ci.yml",
".idea/"
]
}
Expand Down
47 changes: 24 additions & 23 deletions serviceproviders/TelescopeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Vdlp\Telescope\ServiceProviders;

use Backend\Classes\AuthManager;
use Backend\Models\User;
use Cms\Classes\Theme;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Route;
Expand All @@ -22,6 +24,8 @@ public function boot(): void
return;
}

$this->authorization();

Route::middlewareGroup('telescope', config('telescope.middleware', []));

$this->registerRoutes();
Expand All @@ -34,6 +38,24 @@ public function boot(): void
$this->loadViewsFrom(plugins_path('vdlp/telescope/views'), 'telescope');
}

/**
* Configure the Telescope authorization services.
*/
private function authorization(): void
{
Telescope::auth(static function (): bool {
/** @var ?User $user */
$user = AuthManager::instance()->getUser();

if ($user === null) {
return false;
}

return $user->hasPermission('vdlp.telescope.access_dashboard')
|| $user->isSuperUser();
});
}

/**
* Register the package routes.
*/
Expand Down Expand Up @@ -69,20 +91,13 @@ private function registerMigrations(): void

/**
* Register the package's publishable resources.
*
* @return void
*/
private function registerPublishing()
private function registerPublishing(): void
{
if (!$this->app->runningInConsole()) {
return;
}

// TODO:
// $this->publishes([
// __DIR__.'/Storage/migrations' => database_path('migrations'),
// ], 'telescope-migrations');

$this->publishes([
base_path('vendor/laravel/telescope/public') => $this->getAssetPath(),
], 'telescope-assets');
Expand All @@ -100,7 +115,6 @@ public function register(): void

$this->commands([
ClearCommand::class,
// InstallCommand::class,
PruneCommand::class,
PublishCommand::class,
]);
Expand Down Expand Up @@ -141,21 +155,8 @@ private function hideSensitiveRequestDetails(): void
}

/**
* Register the Telescope gate.
*
* This gate determines who can access Telescope in non-local environments.
* Get the asset path for the current active October CMS theme.
*/
private function gate(): void
{
Gate::define('viewTelescope', function ($user): bool {
return true; // TODO: Access to backend user.

// return in_array($user->email, [
// //
// ]);
});
}

private function getAssetPath(): string
{
/** @var Theme $theme */
Expand Down

0 comments on commit 2669e86

Please # to comment.