mirror of
https://github.com/chylex/Nextcloud-News.git
synced 2025-04-25 20:15:47 +02:00
Unremove but deprecate User API
Signed-off-by: Sean Molenaar <sean@seanmolenaar.eu>
This commit is contained in:
parent
5bdc2df7f4
commit
7effe4654b
@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
|
||||
- Remove deprecated YouTube playlist API
|
||||
- Locale-aware sorting for folders and feeds
|
||||
- Fix empty unread item count
|
||||
- Deprecate User API: https://github.com/nextcloud/news/blob/master/docs/externalapi/Legacy.md#user
|
||||
|
||||
## 15.1.0-rc1
|
||||
|
||||
|
@ -59,6 +59,8 @@ return ['routes' => [
|
||||
['name' => 'api#index', 'url' => '/api', 'verb' => 'GET'],
|
||||
|
||||
// API 1.2
|
||||
['name' => 'user_api#index', 'url' => '/api/v1-2/user', 'verb' => 'GET'],
|
||||
['name' => 'user_api#avatar', 'url' => '/api/v1-2/user/avatar', 'verb' => 'GET'],
|
||||
['name' => 'utility_api#version', 'url' => '/api/v1-2/version', 'verb' => 'GET'],
|
||||
['name' => 'utility_api#status', 'url' => '/api/v1-2/status', 'verb' => 'GET'],
|
||||
['name' => 'utility_api#before_update', 'url' => '/api/v1-2/cleanup/before-update', 'verb' => 'GET'],
|
||||
|
@ -759,6 +759,8 @@ If **incorrectDbCharset** is true you should display a warning that database cha
|
||||
This API can be used to retrieve metadata about the current user.
|
||||
|
||||
DEPRECATED: This API is deprecated, use the Nextcloud APIs instead.
|
||||
- https://docs.nextcloud.com/server/latest/developer_manual/client_apis/OCS/ocs-api-overview.html#user-metadata for user data
|
||||
- `https://nc.url/avatar/{userid}/{size}?v={1|2}` for the avatar
|
||||
|
||||
## Get the status
|
||||
|
||||
|
54
lib/Controller/UserApiController.php
Normal file
54
lib/Controller/UserApiController.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* Nextcloud - News
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Alessandro Cosentino <cosenal@gmail.com>
|
||||
* @author Bernhard Posselt <dev@bernhard-posselt.com>
|
||||
* @author David Guillot <david@guillot.me>
|
||||
* @copyright 2012 Alessandro Cosentino
|
||||
* @copyright 2012-2014 Bernhard Posselt
|
||||
* @copyright 2018 David Guillot
|
||||
*/
|
||||
|
||||
namespace OCA\News\Controller;
|
||||
|
||||
use \OCP\IRequest;
|
||||
use \OCP\IUserSession;
|
||||
use \OCP\IURLGenerator;
|
||||
use \OCP\Files\IRootFolder;
|
||||
use \OCP\AppFramework\Http;
|
||||
|
||||
class UserApiController extends ApiController
|
||||
{
|
||||
public function __construct(
|
||||
string $appName,
|
||||
IRequest $request,
|
||||
IUserSession $userSession
|
||||
) {
|
||||
parent::__construct($appName, $request, $userSession);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
* @CORS
|
||||
*
|
||||
* @deprecated Should use https://docs.nextcloud.com/server/latest/developer_manual/client_apis/OCS/ocs-api-overview.html#user-metadata
|
||||
* and avatar is `https://nc.url/avatar/{userid}/{size}?v={1|2}`
|
||||
*/
|
||||
public function index(): array
|
||||
{
|
||||
$user = $this->getUser();
|
||||
$avatar = null;
|
||||
|
||||
return [
|
||||
'userId' => $user->getUID(),
|
||||
'displayName' => $user->getDisplayName(),
|
||||
'lastLoginTimestamp' => $user->getLastLogin(),
|
||||
'avatar' => $avatar
|
||||
];
|
||||
}
|
||||
}
|
@ -12,15 +12,11 @@
|
||||
|
||||
namespace OCA\News\Tests\Integration;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
use OCA\News\Db\Feed;
|
||||
use OCA\News\Db\Item;
|
||||
use OCP\AppFramework\Db\Entity;
|
||||
use OCP\AppFramework\IAppContainer;
|
||||
|
||||
use OCP\IDBConnection;
|
||||
use OCP\IUserSession;
|
||||
use OCP\IUserManager;
|
||||
|
||||
use OCA\News\AppInfo\Application;
|
||||
@ -30,8 +26,6 @@ use OCA\News\Tests\Integration\Fixtures\FolderFixture;
|
||||
use OCA\News\Db\FeedMapper;
|
||||
use OCA\News\Db\ItemMapper;
|
||||
use OCA\News\Db\FolderMapper;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
|
||||
abstract class IntegrationTest extends \Test\TestCase
|
||||
{
|
||||
|
149
tests/Unit/Controller/UserApiControllerTest.php
Normal file
149
tests/Unit/Controller/UserApiControllerTest.php
Normal file
@ -0,0 +1,149 @@
|
||||
<?php
|
||||
/**
|
||||
* Nextcloud - News
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Alessandro Cosentino <cosenal@gmail.com>
|
||||
* @author Bernhard Posselt <dev@bernhard-posselt.com>
|
||||
* @copyright 2012 Alessandro Cosentino
|
||||
* @copyright 2012-2014 Bernhard Posselt
|
||||
*/
|
||||
|
||||
namespace OCA\News\Tests\Unit\Controller;
|
||||
|
||||
use OCA\News\Controller\UserApiController;
|
||||
use OCP\Files\File;
|
||||
use OCP\Files\IRootFolder;
|
||||
use OCP\IRequest;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserSession;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class UserApiControllerTest extends TestCase
|
||||
{
|
||||
|
||||
private $request;
|
||||
private $appName;
|
||||
private $rootFolder;
|
||||
private $userSession;
|
||||
private $controller;
|
||||
private $user;
|
||||
private $file;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->appName = 'news';
|
||||
$this->request = $this->getMockBuilder(IRequest::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->rootFolder = $this->getMockBuilder(IRootFolder::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->file = $this->getMockBuilder(File::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->userSession = $this->getMockBuilder(IUserSession::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->user = $this->getMockBuilder(IUser::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->controller = new UserApiController(
|
||||
$this->appName, $this->request, $this->userSession,
|
||||
$this->rootFolder
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private function expectUser($uid, $displayName, $lastLogin)
|
||||
{
|
||||
$this->userSession->expects($this->any())
|
||||
->method('getUser')
|
||||
->will($this->returnValue($this->user));
|
||||
$this->user->expects($this->any())
|
||||
->method('getUID')
|
||||
->will($this->returnValue($uid));
|
||||
$this->user->expects($this->any())
|
||||
->method('getLastLogin')
|
||||
->will($this->returnValue($lastLogin));
|
||||
$this->user->expects($this->any())
|
||||
->method('getDisplayName')
|
||||
->will($this->returnValue($displayName));
|
||||
}
|
||||
|
||||
private function expectImg($isJpg, $isPng, $user, $exists, $data)
|
||||
{
|
||||
$jpg = '/' . $user . '/' . 'avatar.jpg';
|
||||
$png = '/' . $user . '/' . 'avatar.png';
|
||||
|
||||
$this->rootFolder->expects($this->any())
|
||||
->method('nodeExists')
|
||||
->will(
|
||||
$this->returnValueMap(
|
||||
[
|
||||
[$jpg, $isJpg],
|
||||
[$png, $isPng]
|
||||
]
|
||||
)
|
||||
);
|
||||
$this->rootFolder->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->returnValue($this->file));
|
||||
$this->file->expects($this->any())
|
||||
->method('getContent')
|
||||
->will($this->returnValue($data));
|
||||
}
|
||||
|
||||
public function testGetJpeg()
|
||||
{
|
||||
$this->expectUser('john', 'John', 123);
|
||||
$this->expectImg(true, false, 'john', true, 'hi');
|
||||
|
||||
$result = $this->controller->index();
|
||||
$expected = [
|
||||
'userId' => 'john',
|
||||
'displayName' => 'John',
|
||||
'lastLoginTimestamp' => 123,
|
||||
'avatar' => null
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testGetPng()
|
||||
{
|
||||
$this->expectUser('john', 'John', 123);
|
||||
$this->expectImg(false, true, 'john', false, 'hi');
|
||||
|
||||
$result = $this->controller->index();
|
||||
$expected = [
|
||||
'userId' => 'john',
|
||||
'displayName' => 'John',
|
||||
'lastLoginTimestamp' => 123,
|
||||
'avatar' => null
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testNoAvatar()
|
||||
{
|
||||
$this->expectUser('john', 'John', 123);
|
||||
$this->expectImg(false, false, 'john', false, 'hi');
|
||||
|
||||
$result = $this->controller->index();
|
||||
$expected = [
|
||||
'userId' => 'john',
|
||||
'displayName' => 'John',
|
||||
'lastLoginTimestamp' => 123,
|
||||
'avatar' => null
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user