-
Notifications
You must be signed in to change notification settings - Fork 1
feat: change telescope middleware #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Pull Request Test Coverage Report for Build 18311554711Details
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Updates Laravel Telescope middleware configuration from default authorization to web authentication. The change replaces the Telescope-specific Authorize::class
middleware with 'auth:web'
for telescope route access control.
- Replaces Telescope authorization middleware with web authentication
- Removes unused Authorize middleware import from telescope config
- Updates all test fixtures to reflect the middleware change
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
src/Commands/InitCommand.php | Adds method to replace Telescope Authorize middleware with auth:web |
tests/InitCommandTest.php | Updates test expectations to mock telescope config file operations |
tests/fixtures/InitCommandTest/origin_telescope_config.php | Original telescope config with Authorize middleware |
tests/fixtures/InitCommandTest/updated_telescope_config.php | Updated telescope config with auth:web middleware |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
src/Commands/InitCommand.php
Outdated
|
||
protected function changeMiddlewareForTelescopeAuthorization(): void | ||
{ | ||
$telescopeConfigPath = base_path('/config/telescope.php'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the leading slash from the path. The base_path()
function expects a relative path, and including a leading slash can cause issues on different operating systems.
$telescopeConfigPath = base_path('/config/telescope.php'); | |
$telescopeConfigPath = base_path('config/telescope.php'); |
Copilot uses AI. Check for mistakes.
src/Commands/InitCommand.php
Outdated
$content = Str::replace('Authorize::class', "'auth:web'", file_get_contents($telescopeConfigPath)); | ||
$content = Str::replace("use Laravel\Telescope\Http\Middleware\Authorize;\n", '', $content); | ||
|
||
file_put_contents($telescopeConfigPath, $content); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The string replacement approach is fragile and could fail if the telescope config format changes. Consider using a more robust approach like parsing the PHP array structure or checking if the file exists before performing replacements.
$content = Str::replace('Authorize::class', "'auth:web'", file_get_contents($telescopeConfigPath)); | |
$content = Str::replace("use Laravel\Telescope\Http\Middleware\Authorize;\n", '', $content); | |
file_put_contents($telescopeConfigPath, $content); | |
$config = ArrayFile::load($telescopeConfigPath); | |
// Update the 'middleware' key to use 'auth:web' | |
if (isset($config['middleware'])) { | |
$config['middleware'] = ['auth:web']; | |
} | |
ArrayFile::save($telescopeConfigPath, $config); |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pirs1337 please use already installed library for updating config files, here is example
protected function setAutoDocContactEmail(string $email): void |
src/Commands/InitCommand.php
Outdated
$content = Str::replace('Authorize::class', "'auth:web'", file_get_contents($telescopeConfigPath)); | ||
$content = Str::replace("use Laravel\Telescope\Http\Middleware\Authorize;\n", '', $content); | ||
|
||
file_put_contents($telescopeConfigPath, $content); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pirs1337 please use already installed library for updating config files, here is example
protected function setAutoDocContactEmail(string $email): void |
…iddleware # Conflicts: # src/Commands/InitCommand.php # tests/InitCommandTest.php # tests/Support/Traits/InitCommandMockTrait.php
refs: #38
refs: #38