diff --git a/src/Discussion/IdWithSlugDriver.php b/src/Discussion/IdWithSlugDriver.php index 85690883a..e9685736a 100644 --- a/src/Discussion/IdWithSlugDriver.php +++ b/src/Discussion/IdWithSlugDriver.php @@ -1,16 +1,20 @@ id.(trim($instance->slug) ? '-'.$instance->slug : ''); @@ -22,6 +26,7 @@ class IdWithSlugDriver implements SlugDriverInterface $slug_array = explode('-', $slug); $slug = $slug_array[0]; } + return Discussion::where('id', $slug)->whereVisibleTo($actor)->firstOrFail(); } } diff --git a/src/Forum/Content/Discussion.php b/src/Forum/Content/Discussion.php index 780d41631..0fc9b72e4 100644 --- a/src/Forum/Content/Discussion.php +++ b/src/Forum/Content/Discussion.php @@ -10,7 +10,6 @@ namespace Flarum\Forum\Content; use Flarum\Api\Client; -use Flarum\Discussion\Discussion as FlarumDiscussion; use Flarum\Frontend\Document; use Flarum\Http\Exception\RouteNotFoundException; use Flarum\Http\UrlGenerator; diff --git a/src/Http/HttpServiceProvider.php b/src/Http/HttpServiceProvider.php index 919f46a16..fc2c0bc39 100644 --- a/src/Http/HttpServiceProvider.php +++ b/src/Http/HttpServiceProvider.php @@ -33,7 +33,7 @@ class HttpServiceProvider extends AbstractServiceProvider return new Middleware\CheckCsrfToken($app->make('flarum.http.csrfExemptPaths')); }); - $this->app->singleton('flarum.http.slugDrivers', function() { + $this->app->singleton('flarum.http.slugDrivers', function () { return [ Discussion::class => [ 'default' => IdWithSlugDriver::class @@ -44,12 +44,12 @@ class HttpServiceProvider extends AbstractServiceProvider ]; }); - $this->app->singleton('flarum.http.selectedSlugDrivers', function() { + $this->app->singleton('flarum.http.selectedSlugDrivers', function () { $settings = $this->app->make(SettingsRepositoryInterface::class); $compiledDrivers = []; - foreach($this->app->make('flarum.http.slugDrivers') as $resourceClass => $resourceDrivers) { + foreach ($this->app->make('flarum.http.slugDrivers') as $resourceClass => $resourceDrivers) { $driverClass = $resourceDrivers[$settings->get("slug_driver_$resourceClass", 'default')]; $compiledDrivers[$resourceClass] = $this->app->make($driverClass); } @@ -57,36 +57,37 @@ class HttpServiceProvider extends AbstractServiceProvider return $compiledDrivers; }); - $this->app->singleton('flarum.http.resourceUrlGenerators', function() { + $this->app->singleton('flarum.http.resourceUrlGenerators', function () { $slugManager = $this->app->make(SlugManager::class); return [ - Discussion::class => function(UrlGenerator $urlGenerator, Discussion $discussion) use ($slugManager) { + Discussion::class => function (UrlGenerator $urlGenerator, Discussion $discussion) use ($slugManager) { return $urlGenerator->to('forum')->route('discussion', [ 'id' => $slugManager->toResource(Discussion::class)->toSlug($discussion) ]); }, - Post::class => function(UrlGenerator $urlGenerator, Post $post) use ($slugManager) { + Post::class => function (UrlGenerator $urlGenerator, Post $post) use ($slugManager) { return $urlGenerator->to('forum')->route('user', [ 'id' => $slugManager->toResource(Discussion::class)->toSlug($post->discussion), 'near' => $post->id, ]); }, - User::class => function(UrlGenerator $urlGenerator, User $user) use ($slugManager) { + User::class => function (UrlGenerator $urlGenerator, User $user) use ($slugManager) { return $urlGenerator->to('forum')->route('user', [ 'id' => $slugManager->toResource(User::class)->toSlug($user) ]); }, ]; }); - $this->app->bind(SlugManager::class, function() { + $this->app->bind(SlugManager::class, function () { return new SlugManager($this->app->make('flarum.http.selectedSlugDrivers')); }); - $this->app->bind(UrlGenerator::class, function() { + $this->app->bind(UrlGenerator::class, function () { return new UrlGenerator( $this->app->make(Application::class), - $this->app->make('flarum.http.resourceUrlGenerators')); + $this->app->make('flarum.http.resourceUrlGenerators') + ); }); } } diff --git a/src/Http/SlugDriverInterface.php b/src/Http/SlugDriverInterface.php index 822b3a29a..84d3a621e 100644 --- a/src/Http/SlugDriverInterface.php +++ b/src/Http/SlugDriverInterface.php @@ -1,9 +1,14 @@ username; diff --git a/tests/integration/api/discussions/ShowTest.php b/tests/integration/api/discussions/ShowTest.php index 6f25e2e44..b4300a34a 100644 --- a/tests/integration/api/discussions/ShowTest.php +++ b/tests/integration/api/discussions/ShowTest.php @@ -77,7 +77,7 @@ class ShowTest extends TestCase $this->request('GET', '/api/discussions/1-fdsafdsajfsakf', [ 'authenticatedAs' => 2, ])->withQueryParams([ - "bySlug" => true + 'bySlug' => true ]) ); diff --git a/tests/integration/api/users/CreateTest.php b/tests/integration/api/users/CreateTest.php index 87100e2c4..65e821ab7 100644 --- a/tests/integration/api/users/CreateTest.php +++ b/tests/integration/api/users/CreateTest.php @@ -57,7 +57,7 @@ class CreateTest extends TestCase $this->assertEquals(422, $response->getStatusCode()); // The response body should contain details about the failed validation - $body = (string)$response->getBody(); + $body = (string) $response->getBody(); $this->assertJson($body); $this->assertEquals([ 'errors' => [ diff --git a/tests/integration/api/users/ShowTest.php b/tests/integration/api/users/ShowTest.php index 788d63909..afaff63d5 100644 --- a/tests/integration/api/users/ShowTest.php +++ b/tests/integration/api/users/ShowTest.php @@ -1,9 +1,14 @@ request('GET', '/api/users/normal', [ 'authenticatedAs' => 1, ])->withQueryParams([ - "bySlug" => true + 'bySlug' => true ]) ); @@ -81,7 +86,7 @@ class ShowTest extends TestCase { $response = $this->send( $this->request('GET', '/api/users/2')->withQueryParams([ - "bySlug" => true + 'bySlug' => true ]) ); @@ -111,7 +116,7 @@ class ShowTest extends TestCase $this->request('GET', '/api/users/normal', [ 'authenticatedAs' => 2, ])->withQueryParams([ - "bySlug" => true + 'bySlug' => true ]) ); @@ -141,7 +146,7 @@ class ShowTest extends TestCase $this->request('GET', '/api/users/admin', [ 'authenticatedAs' => 2, ])->withQueryParams([ - "bySlug" => true + 'bySlug' => true ]) ); @@ -173,7 +178,7 @@ class ShowTest extends TestCase $this->request('GET', '/api/users/admin', [ 'authenticatedAs' => 2, ])->withQueryParams([ - "bySlug" => true + 'bySlug' => true ]) );