Merge pull request #8000 from nextcloud/fix_7983
Provide list of editable fields via OCS API
This commit is contained in:
commit
78e4f6f312
|
@ -44,6 +44,7 @@ return [
|
|||
['root' => '/cloud', 'name' => 'Users#addUser', 'url' => '/users', 'verb' => 'POST'],
|
||||
['root' => '/cloud', 'name' => 'Users#getUser', 'url' => '/users/{userId}', 'verb' => 'GET'],
|
||||
['root' => '/cloud', 'name' => 'Users#getCurrentUser', 'url' => '/user', 'verb' => 'GET'],
|
||||
['root' => '/cloud', 'name' => 'Users#getEditableFields', 'url' => '/user/fields', 'verb' => 'GET'],
|
||||
['root' => '/cloud', 'name' => 'Users#editUser', 'url' => '/users/{userId}', 'verb' => 'PUT'],
|
||||
['root' => '/cloud', 'name' => 'Users#deleteUser', 'url' => '/users/{userId}', 'verb' => 'DELETE'],
|
||||
['root' => '/cloud', 'name' => 'Users#enableUser', 'url' => '/users/{userId}/enable', 'verb' => 'PUT'],
|
||||
|
|
|
@ -11,6 +11,7 @@ return array(
|
|||
'OCA\\Provisioning_API\\Controller\\AppsController' => $baseDir . '/../lib/Controller/AppsController.php',
|
||||
'OCA\\Provisioning_API\\Controller\\GroupsController' => $baseDir . '/../lib/Controller/GroupsController.php',
|
||||
'OCA\\Provisioning_API\\Controller\\UsersController' => $baseDir . '/../lib/Controller/UsersController.php',
|
||||
'OCA\\Provisioning_API\\FederatedFileSharingFactory' => $baseDir . '/../lib/FederatedFileSharingFactory.php',
|
||||
'OCA\\Provisioning_API\\Middleware\\Exceptions\\NotSubAdminException' => $baseDir . '/../lib/Middleware/Exceptions/NotSubAdminException.php',
|
||||
'OCA\\Provisioning_API\\Middleware\\ProvisioningApiMiddleware' => $baseDir . '/../lib/Middleware/ProvisioningApiMiddleware.php',
|
||||
);
|
||||
|
|
|
@ -26,6 +26,7 @@ class ComposerStaticInitProvisioning_API
|
|||
'OCA\\Provisioning_API\\Controller\\AppsController' => __DIR__ . '/..' . '/../lib/Controller/AppsController.php',
|
||||
'OCA\\Provisioning_API\\Controller\\GroupsController' => __DIR__ . '/..' . '/../lib/Controller/GroupsController.php',
|
||||
'OCA\\Provisioning_API\\Controller\\UsersController' => __DIR__ . '/..' . '/../lib/Controller/UsersController.php',
|
||||
'OCA\\Provisioning_API\\FederatedFileSharingFactory' => __DIR__ . '/..' . '/../lib/FederatedFileSharingFactory.php',
|
||||
'OCA\\Provisioning_API\\Middleware\\Exceptions\\NotSubAdminException' => __DIR__ . '/..' . '/../lib/Middleware/Exceptions/NotSubAdminException.php',
|
||||
'OCA\\Provisioning_API\\Middleware\\ProvisioningApiMiddleware' => __DIR__ . '/..' . '/../lib/Middleware/ProvisioningApiMiddleware.php',
|
||||
);
|
||||
|
|
|
@ -33,6 +33,7 @@ namespace OCA\Provisioning_API\Controller;
|
|||
use OC\Accounts\AccountManager;
|
||||
use OC\Settings\Mailer\NewUserMailHelper;
|
||||
use OC_Helper;
|
||||
use OCA\Provisioning_API\FederatedFileSharingFactory;
|
||||
use OCP\App\IAppManager;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\AppFramework\OCS\OCSException;
|
||||
|
@ -68,6 +69,8 @@ class UsersController extends OCSController {
|
|||
private $l10nFactory;
|
||||
/** @var NewUserMailHelper */
|
||||
private $newUserMailHelper;
|
||||
/** @var FederatedFileSharingFactory */
|
||||
private $federatedFileSharingFactory;
|
||||
|
||||
/**
|
||||
* @param string $appName
|
||||
|
@ -81,6 +84,7 @@ class UsersController extends OCSController {
|
|||
* @param ILogger $logger
|
||||
* @param IFactory $l10nFactory
|
||||
* @param NewUserMailHelper $newUserMailHelper
|
||||
* @param FederatedFileSharingFactory $federatedFileSharingFactory
|
||||
*/
|
||||
public function __construct($appName,
|
||||
IRequest $request,
|
||||
|
@ -92,7 +96,8 @@ class UsersController extends OCSController {
|
|||
AccountManager $accountManager,
|
||||
ILogger $logger,
|
||||
IFactory $l10nFactory,
|
||||
NewUserMailHelper $newUserMailHelper) {
|
||||
NewUserMailHelper $newUserMailHelper,
|
||||
FederatedFileSharingFactory $federatedFileSharingFactory) {
|
||||
parent::__construct($appName, $request);
|
||||
|
||||
$this->userManager = $userManager;
|
||||
|
@ -104,6 +109,7 @@ class UsersController extends OCSController {
|
|||
$this->logger = $logger;
|
||||
$this->l10nFactory = $l10nFactory;
|
||||
$this->newUserMailHelper = $newUserMailHelper;
|
||||
$this->federatedFileSharingFactory = $federatedFileSharingFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -296,6 +302,33 @@ class UsersController extends OCSController {
|
|||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoSubAdminRequired
|
||||
*/
|
||||
public function getEditableFields() {
|
||||
$permittedFields = [];
|
||||
|
||||
// Editing self (display, email)
|
||||
if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) {
|
||||
$permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME;
|
||||
$permittedFields[] = AccountManager::PROPERTY_EMAIL;
|
||||
}
|
||||
|
||||
if ($this->appManager->isEnabledForUser('federatedfilesharing')) {
|
||||
$federatedFileSharing = $this->federatedFileSharingFactory->get();
|
||||
$shareProvider = $federatedFileSharing->getFederatedShareProvider();
|
||||
if ($shareProvider->isLookupServerUploadEnabled()) {
|
||||
$permittedFields[] = AccountManager::PROPERTY_PHONE;
|
||||
$permittedFields[] = AccountManager::PROPERTY_ADDRESS;
|
||||
$permittedFields[] = AccountManager::PROPERTY_WEBSITE;
|
||||
$permittedFields[] = AccountManager::PROPERTY_TWITTER;
|
||||
}
|
||||
}
|
||||
|
||||
return new DataResponse($permittedFields);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoSubAdminRequired
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\Provisioning_API;
|
||||
|
||||
use OCA\FederatedFileSharing\AppInfo\Application;
|
||||
|
||||
class FederatedFileSharingFactory {
|
||||
public function get(): Application {
|
||||
return new Application();
|
||||
}
|
||||
}
|
|
@ -34,6 +34,9 @@ namespace OCA\Provisioning_API\Tests\Controller;
|
|||
use Exception;
|
||||
use OC\Accounts\AccountManager;
|
||||
use OC\Group\Manager;
|
||||
use OCA\FederatedFileSharing\AppInfo\Application;
|
||||
use OCA\FederatedFileSharing\FederatedShareProvider;
|
||||
use OCA\Provisioning_API\FederatedFileSharingFactory;
|
||||
use OCP\App\IAppManager;
|
||||
use OCP\AppFramework\OCS\OCSException;
|
||||
use OCP\Mail\IEMailTemplate;
|
||||
|
@ -80,6 +83,8 @@ class UsersControllerTest extends TestCase {
|
|||
private $l10nFactory;
|
||||
/** @var NewUserMailHelper|PHPUnit_Framework_MockObject_MockObject */
|
||||
private $newUserMailHelper;
|
||||
/** @var FederatedFileSharingFactory|\PHPUnit_Framework_MockObject_MockObject */
|
||||
private $federatedFileSharingFactory;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
@ -94,6 +99,7 @@ class UsersControllerTest extends TestCase {
|
|||
$this->accountManager = $this->createMock(AccountManager::class);
|
||||
$this->l10nFactory = $this->createMock(IFactory::class);
|
||||
$this->newUserMailHelper = $this->createMock(NewUserMailHelper::class);
|
||||
$this->federatedFileSharingFactory = $this->createMock(FederatedFileSharingFactory::class);
|
||||
|
||||
$this->api = $this->getMockBuilder(UsersController::class)
|
||||
->setConstructorArgs([
|
||||
|
@ -107,7 +113,8 @@ class UsersControllerTest extends TestCase {
|
|||
$this->accountManager,
|
||||
$this->logger,
|
||||
$this->l10nFactory,
|
||||
$this->newUserMailHelper
|
||||
$this->newUserMailHelper,
|
||||
$this->federatedFileSharingFactory
|
||||
])
|
||||
->setMethods(['fillStorageInfo'])
|
||||
->getMock();
|
||||
|
@ -2877,7 +2884,8 @@ class UsersControllerTest extends TestCase {
|
|||
$this->accountManager,
|
||||
$this->logger,
|
||||
$this->l10nFactory,
|
||||
$this->newUserMailHelper
|
||||
$this->newUserMailHelper,
|
||||
$this->federatedFileSharingFactory
|
||||
])
|
||||
->setMethods(['getUserData'])
|
||||
->getMock();
|
||||
|
@ -2938,7 +2946,8 @@ class UsersControllerTest extends TestCase {
|
|||
$this->accountManager,
|
||||
$this->logger,
|
||||
$this->l10nFactory,
|
||||
$this->newUserMailHelper
|
||||
$this->newUserMailHelper,
|
||||
$this->federatedFileSharingFactory
|
||||
])
|
||||
->setMethods(['getUserData'])
|
||||
->getMock();
|
||||
|
@ -3318,4 +3327,64 @@ class UsersControllerTest extends TestCase {
|
|||
|
||||
$this->api->resendWelcomeMessage('UserToGet');
|
||||
}
|
||||
|
||||
|
||||
public function dataGetEditableFields() {
|
||||
return [
|
||||
[false, false, []],
|
||||
[false, true, [
|
||||
AccountManager::PROPERTY_PHONE,
|
||||
AccountManager::PROPERTY_ADDRESS,
|
||||
AccountManager::PROPERTY_WEBSITE,
|
||||
AccountManager::PROPERTY_TWITTER,
|
||||
]],
|
||||
[ true, false, [
|
||||
AccountManager::PROPERTY_DISPLAYNAME,
|
||||
AccountManager::PROPERTY_EMAIL,
|
||||
]],
|
||||
[ true, true ,[
|
||||
AccountManager::PROPERTY_DISPLAYNAME,
|
||||
AccountManager::PROPERTY_EMAIL,
|
||||
AccountManager::PROPERTY_PHONE,
|
||||
AccountManager::PROPERTY_ADDRESS,
|
||||
AccountManager::PROPERTY_WEBSITE,
|
||||
AccountManager::PROPERTY_TWITTER,
|
||||
]]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataGetEditableFields
|
||||
*
|
||||
* @param bool $allowedToChangeDisplayName
|
||||
* @param bool $federatedSharingEnabled
|
||||
* @param array $expected
|
||||
*/
|
||||
public function testGetEditableFields(bool $allowedToChangeDisplayName, bool $federatedSharingEnabled, array $expected) {
|
||||
$this->config
|
||||
->method('getSystemValue')
|
||||
->with(
|
||||
$this->equalTo('allow_user_to_change_display_name'),
|
||||
$this->anything()
|
||||
)->willReturn($allowedToChangeDisplayName);
|
||||
$this->appManager
|
||||
->method('isEnabledForUser')
|
||||
->with($this->equalTo('federatedfilesharing'))
|
||||
->willReturn($federatedSharingEnabled);
|
||||
|
||||
$shareprovider = $this->createMock(FederatedShareProvider::class);
|
||||
$shareprovider->method('isLookupServerUploadEnabled')->willReturn(true);
|
||||
|
||||
$federatedFileSharing = $this->createMock(Application::class);
|
||||
$federatedFileSharing
|
||||
->method('getFederatedShareProvider')
|
||||
->willReturn($shareprovider);
|
||||
|
||||
$this->federatedFileSharingFactory
|
||||
->method('get')
|
||||
->willReturn($federatedFileSharing);
|
||||
|
||||
$expectedResp = new DataResponse($expected);
|
||||
$this->assertEquals($expectedResp, $this->api->getEditableFields());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue