Skip to content

Commit

Permalink
Add deprecated "user" filter for posts
Browse files Browse the repository at this point in the history
In the filterer refactor for ListPostsController, the filter key was changed to `author` for consistency with the AuthorFilterGambit used in discussions. This commit adds a deprecated `user` filter back in for a release to allow for a graceful transition
  • Loading branch information
askvortsov1 committed Mar 8, 2021
1 parent ba9665e commit 91e8b56
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Filter/FilterServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function register()
PostFilter\IdFilter::class,
PostFilter\NumberFilter::class,
PostFilter\TypeFilter::class,
PostFilter\UserFilter::class,
],
];
});
Expand Down
21 changes: 21 additions & 0 deletions src/Post/Filter/UserFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/

namespace Flarum\Post\Filter;

/**
* @deprecated beta 16, remove beta 17. Use AuthorFilter instead.
*/
class UserFilter extends AuthorFilter
{
public function getFilterKey(): string
{
return 'user';
}
}
38 changes: 38 additions & 0 deletions tests/integration/api/posts/ListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,44 @@ public function author_filter_works_with_multiple_values()
$this->assertEquals(['1', '2', '3', '4', '5'], Arr::pluck($data['data'], 'id'));
}

/**
* @test
* @deprecated
*/
public function user_filter_works()
{
$response = $this->send(
$this->request('GET', '/api/posts', ['authenticatedAs' => 1])
->withQueryParams([
'filter' => ['user' => 'admin'],
])
);

$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($response->getBody()->getContents(), true);

$this->assertEquals(['1', '2'], Arr::pluck($data['data'], 'id'));
}

/**
* @test
* @deprecated
*/
public function user_filter_works_with_multiple_values()
{
$response = $this->send(
$this->request('GET', '/api/posts', ['authenticatedAs' => 1])
->withQueryParams([
'filter' => ['user' => 'admin,normal'],
])
);

$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($response->getBody()->getContents(), true);

$this->assertEquals(['1', '2', '3', '4', '5'], Arr::pluck($data['data'], 'id'));
}

/**
* @test
*/
Expand Down

0 comments on commit 91e8b56

Please sign in to comment.