add data from the users profile to the provisioning api

Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
This commit is contained in:
Bjoern Schiessle 2017-01-24 14:07:52 +01:00
parent 026ceab35f
commit c4ae0cd433
No known key found for this signature in database
GPG Key ID: 2378A753E2BF04F6
2 changed files with 65 additions and 4 deletions

View File

@ -29,6 +29,7 @@
namespace OCA\Provisioning_API\Controller; namespace OCA\Provisioning_API\Controller;
use OC\Accounts\AccountManager;
use \OC_Helper; use \OC_Helper;
use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSException; use OCP\AppFramework\OCS\OCSException;
@ -53,6 +54,8 @@ class UsersController extends OCSController {
private $groupManager; private $groupManager;
/** @var IUserSession */ /** @var IUserSession */
private $userSession; private $userSession;
/** @var AccountManager */
private $accountManager;
/** @var ILogger */ /** @var ILogger */
private $logger; private $logger;
@ -63,6 +66,7 @@ class UsersController extends OCSController {
* @param IConfig $config * @param IConfig $config
* @param IGroupManager $groupManager * @param IGroupManager $groupManager
* @param IUserSession $userSession * @param IUserSession $userSession
* @param AccountManager $accountManager
* @param ILogger $logger * @param ILogger $logger
*/ */
public function __construct($appName, public function __construct($appName,
@ -71,6 +75,7 @@ class UsersController extends OCSController {
IConfig $config, IConfig $config,
IGroupManager $groupManager, IGroupManager $groupManager,
IUserSession $userSession, IUserSession $userSession,
AccountManager $accountManager,
ILogger $logger) { ILogger $logger) {
parent::__construct($appName, $request); parent::__construct($appName, $request);
@ -78,6 +83,7 @@ class UsersController extends OCSController {
$this->config = $config; $this->config = $config;
$this->groupManager = $groupManager; $this->groupManager = $groupManager;
$this->userSession = $userSession; $this->userSession = $userSession;
$this->accountManager = $accountManager;
$this->logger = $logger; $this->logger = $logger;
} }
@ -107,7 +113,7 @@ class UsersController extends OCSController {
} }
if($offset === null) { if($offset === null) {
$offset = 0; $offset = 0;
} }
$users = []; $users = [];
@ -159,7 +165,7 @@ class UsersController extends OCSController {
throw new OCSException('no group specified (required for subadmins)', 106); throw new OCSException('no group specified (required for subadmins)', 106);
} }
} }
try { try {
$newUser = $this->userManager->createUser($userid, $password); $newUser = $this->userManager->createUser($userid, $password);
$this->logger->info('Successful addUser call with userid: '.$userid, ['app' => 'ocs_api']); $this->logger->info('Successful addUser call with userid: '.$userid, ['app' => 'ocs_api']);
@ -209,10 +215,16 @@ class UsersController extends OCSController {
} }
} }
$userAccount = $this->accountManager->getUser($targetUserObject);
// Find the data // Find the data
$data['quota'] = $this->fillStorageInfo($userId); $data['quota'] = $this->fillStorageInfo($userId);
$data['email'] = $targetUserObject->getEMailAddress(); $data['email'] = $targetUserObject->getEMailAddress();
$data['displayname'] = $targetUserObject->getDisplayName(); $data['displayname'] = $targetUserObject->getDisplayName();
$data['phone'] = $userAccount[\OC\Accounts\AccountManager::PROPERTY_PHONE]['value'];
$data['address'] = $userAccount[\OC\Accounts\AccountManager::PROPERTY_ADDRESS]['value'];
$data['webpage'] = $userAccount[\OC\Accounts\AccountManager::PROPERTY_WEBSITE]['value'];
$data['twitter'] = $userAccount[\OC\Accounts\AccountManager::PROPERTY_TWITTER]['value'];
return new DataResponse($data); return new DataResponse($data);
} }
@ -435,7 +447,7 @@ class UsersController extends OCSController {
throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED); throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
} }
} }
} }
/** /**

View File

@ -29,6 +29,7 @@
namespace OCA\Provisioning_API\Tests\Controller; namespace OCA\Provisioning_API\Tests\Controller;
use OC\Accounts\AccountManager;
use OCA\Provisioning_API\Controller\UsersController; use OCA\Provisioning_API\Controller\UsersController;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\IConfig; use OCP\IConfig;
@ -38,7 +39,7 @@ use Test\TestCase as OriginalTest;
use OCP\ILogger; use OCP\ILogger;
class UsersControllerTest extends OriginalTest { class UsersControllerTest extends OriginalTest {
/** @var IUserManager | PHPUnit_Framework_MockObject_MockObject */ /** @var IUserManager | PHPUnit_Framework_MockObject_MockObject */
protected $userManager; protected $userManager;
/** @var IConfig | PHPUnit_Framework_MockObject_MockObject */ /** @var IConfig | PHPUnit_Framework_MockObject_MockObject */
@ -51,6 +52,8 @@ class UsersControllerTest extends OriginalTest {
protected $logger; protected $logger;
/** @var UsersController | PHPUnit_Framework_MockObject_MockObject */ /** @var UsersController | PHPUnit_Framework_MockObject_MockObject */
protected $api; protected $api;
/** @var AccountManager | PHPUnit_Framework_MockObject_MockObject */
protected $accountManager;
protected function tearDown() { protected function tearDown() {
parent::tearDown(); parent::tearDown();
@ -77,6 +80,9 @@ class UsersControllerTest extends OriginalTest {
$request = $this->getMockBuilder('OCP\IRequest') $request = $this->getMockBuilder('OCP\IRequest')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$this->accountManager = $this->getMockBuilder(AccountManager::class)
->disableOriginalConstructor()
->getMock();
$this->api = $this->getMockBuilder('OCA\Provisioning_API\Controller\UsersController') $this->api = $this->getMockBuilder('OCA\Provisioning_API\Controller\UsersController')
->setConstructorArgs([ ->setConstructorArgs([
'provisioning_api', 'provisioning_api',
@ -85,6 +91,7 @@ class UsersControllerTest extends OriginalTest {
$this->config, $this->config,
$this->groupManager, $this->groupManager,
$this->userSession, $this->userSession,
$this->accountManager,
$this->logger, $this->logger,
]) ])
->setMethods(['fillStorageInfo']) ->setMethods(['fillStorageInfo'])
@ -649,6 +656,16 @@ class UsersControllerTest extends OriginalTest {
->method('isAdmin') ->method('isAdmin')
->with('admin') ->with('admin')
->will($this->returnValue(true)); ->will($this->returnValue(true));
$this->accountManager->expects($this->any())->method('getUser')
->with($targetUser)
->willReturn(
[
AccountManager::PROPERTY_ADDRESS => ['value' => 'address'],
AccountManager::PROPERTY_PHONE => ['value' => 'phone'],
AccountManager::PROPERTY_TWITTER => ['value' => 'twitter'],
AccountManager::PROPERTY_WEBSITE => ['value' => 'website'],
]
);
$this->config $this->config
->expects($this->at(0)) ->expects($this->at(0))
->method('getUserValue') ->method('getUserValue')
@ -669,6 +686,10 @@ class UsersControllerTest extends OriginalTest {
'quota' => ['DummyValue'], 'quota' => ['DummyValue'],
'email' => 'demo@owncloud.org', 'email' => 'demo@owncloud.org',
'displayname' => 'Demo User', 'displayname' => 'Demo User',
'phone' => 'phone',
'address' => 'address',
'webpage' => 'website',
'twitter' => 'twitter'
]; ];
$this->assertEquals($expected, $this->api->getUser('UserToGet')->getData()); $this->assertEquals($expected, $this->api->getUser('UserToGet')->getData());
} }
@ -728,12 +749,26 @@ class UsersControllerTest extends OriginalTest {
->expects($this->once()) ->expects($this->once())
->method('getDisplayName') ->method('getDisplayName')
->will($this->returnValue('Demo User')); ->will($this->returnValue('Demo User'));
$this->accountManager->expects($this->any())->method('getUser')
->with($targetUser)
->willReturn(
[
AccountManager::PROPERTY_ADDRESS => ['value' => 'address'],
AccountManager::PROPERTY_PHONE => ['value' => 'phone'],
AccountManager::PROPERTY_TWITTER => ['value' => 'twitter'],
AccountManager::PROPERTY_WEBSITE => ['value' => 'website'],
]
);
$expected = [ $expected = [
'enabled' => 'true', 'enabled' => 'true',
'quota' => ['DummyValue'], 'quota' => ['DummyValue'],
'email' => 'demo@owncloud.org', 'email' => 'demo@owncloud.org',
'displayname' => 'Demo User', 'displayname' => 'Demo User',
'phone' => 'phone',
'address' => 'address',
'webpage' => 'website',
'twitter' => 'twitter'
]; ];
$this->assertEquals($expected, $this->api->getUser('UserToGet')->getData()); $this->assertEquals($expected, $this->api->getUser('UserToGet')->getData());
} }
@ -834,11 +869,25 @@ class UsersControllerTest extends OriginalTest {
->expects($this->once()) ->expects($this->once())
->method('getEMailAddress') ->method('getEMailAddress')
->will($this->returnValue('subadmin@owncloud.org')); ->will($this->returnValue('subadmin@owncloud.org'));
$this->accountManager->expects($this->any())->method('getUser')
->with($targetUser)
->willReturn(
[
AccountManager::PROPERTY_ADDRESS => ['value' => 'address'],
AccountManager::PROPERTY_PHONE => ['value' => 'phone'],
AccountManager::PROPERTY_TWITTER => ['value' => 'twitter'],
AccountManager::PROPERTY_WEBSITE => ['value' => 'website'],
]
);
$expected = [ $expected = [
'quota' => ['DummyValue'], 'quota' => ['DummyValue'],
'email' => 'subadmin@owncloud.org', 'email' => 'subadmin@owncloud.org',
'displayname' => 'Subadmin User', 'displayname' => 'Subadmin User',
'phone' => 'phone',
'address' => 'address',
'webpage' => 'website',
'twitter' => 'twitter'
]; ];
$this->assertEquals($expected, $this->api->getUser('subadmin')->getData()); $this->assertEquals($expected, $this->api->getUser('subadmin')->getData());
} }