diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2018-11-07 16:35:51 +0100 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2018-11-07 22:37:41 +0100 |
commit | 505722cc0d949ff5606b71757ec8d2ad2691b62b (patch) | |
tree | d636c7370b519ad0c8a02bd7c34fc477a67b6145 /apps/provisioning_api | |
parent | 836ba4f4192d042921507f9eea4ff69b4d54480e (diff) | |
download | nextcloud-server-505722cc0d949ff5606b71757ec8d2ad2691b62b.tar.gz nextcloud-server-505722cc0d949ff5606b71757ec8d2ad2691b62b.zip |
do not offer to change display name or password, if not possible.
Fixes #12319
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/provisioning_api')
-rw-r--r-- | apps/provisioning_api/lib/Controller/AUserData.php | 9 | ||||
-rw-r--r-- | apps/provisioning_api/tests/Controller/UsersControllerTest.php | 47 |
2 files changed, 52 insertions, 4 deletions
diff --git a/apps/provisioning_api/lib/Controller/AUserData.php b/apps/provisioning_api/lib/Controller/AUserData.php index 25e5ab5c86d..864ed65e69e 100644 --- a/apps/provisioning_api/lib/Controller/AUserData.php +++ b/apps/provisioning_api/lib/Controller/AUserData.php @@ -22,6 +22,7 @@ declare(strict_types=1); namespace OCA\Provisioning_API\Controller; use OC\Accounts\AccountManager; +use OC\User\Backend; use OCP\AppFramework\OCS\OCSException; use OCP\AppFramework\OCS\OCSNotFoundException; use OCP\AppFramework\OCSController; @@ -32,6 +33,8 @@ use OCP\IGroupManager; use OCP\IRequest; use OCP\IUserManager; use OCP\IUserSession; +use OCP\User\Backend\ISetDisplayNameBackend; +use OCP\User\Backend\ISetPasswordBackend; abstract class AUserData extends OCSController { @@ -125,6 +128,12 @@ abstract class AUserData extends OCSController { $data['language'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'lang'); $data['locale'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'locale'); + $backend = $targetUserObject->getBackend(); + $data['backendCapabilities'] = [ + 'setDisplayName' => $backend instanceof ISetDisplayNameBackend || $backend->implementsActions(Backend::SET_DISPLAYNAME), + 'setPassword' => $backend instanceof ISetPasswordBackend || $backend->implementsActions(Backend::SET_PASSWORD), + ]; + return $data; } diff --git a/apps/provisioning_api/tests/Controller/UsersControllerTest.php b/apps/provisioning_api/tests/Controller/UsersControllerTest.php index 57283e11912..0d6d811acbc 100644 --- a/apps/provisioning_api/tests/Controller/UsersControllerTest.php +++ b/apps/provisioning_api/tests/Controller/UsersControllerTest.php @@ -38,25 +38,22 @@ 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; use OC\Settings\Mailer\NewUserMailHelper; use OC\SubAdmin; use OCA\Provisioning_API\Controller\UsersController; use OCP\AppFramework\Http\DataResponse; -use OCP\Defaults; use OCP\IConfig; use OCP\IGroup; use OCP\ILogger; use OCP\IL10N; use OCP\IRequest; -use OCP\IURLGenerator; use OCP\IUser; use OCP\IUserManager; use OCP\IUserSession; use OCP\L10N\IFactory; -use OCP\Mail\IMailer; use OCP\Security\ISecureRandom; +use OCP\UserInterface; use PHPUnit_Framework_MockObject_MockObject; use Test\TestCase; @@ -800,6 +797,12 @@ class UsersControllerTest extends TestCase { ->method('fillStorageInfo') ->with('UID') ->will($this->returnValue(['DummyValue'])); + + $backend = $this->createMock(UserInterface::class); + $backend->expects($this->any()) + ->method('implementsActions') + ->willReturn(true); + $targetUser ->expects($this->once()) ->method('getDisplayName') @@ -817,6 +820,10 @@ class UsersControllerTest extends TestCase { ->method('getBackendClassName') ->will($this->returnValue('Database')); $targetUser + ->expects($this->once()) + ->method('getBackend') + ->willReturn($backend); + $targetUser ->expects($this->exactly(6)) ->method('getUID') ->will($this->returnValue('UID')); @@ -838,6 +845,10 @@ class UsersControllerTest extends TestCase { 'groups' => ['group0', 'group1', 'group2'], 'language' => 'de', 'locale' => null, + 'backendCapabilities' => [ + 'setDisplayName' => true, + 'setPassword' => true, + ] ]; $this->assertEquals($expected, $this->invokePrivate($this->api, 'getUserData', ['UID'])); } @@ -906,6 +917,12 @@ class UsersControllerTest extends TestCase { ->method('fillStorageInfo') ->with('UID') ->will($this->returnValue(['DummyValue'])); + + $backend = $this->createMock(UserInterface::class); + $backend->expects($this->any()) + ->method('implementsActions') + ->willReturn(true); + $targetUser ->expects($this->once()) ->method('getDisplayName') @@ -923,6 +940,10 @@ class UsersControllerTest extends TestCase { ->method('getBackendClassName') ->will($this->returnValue('Database')); $targetUser + ->expects($this->once()) + ->method('getBackend') + ->willReturn($backend); + $targetUser ->expects($this->exactly(6)) ->method('getUID') ->will($this->returnValue('UID')); @@ -954,6 +975,10 @@ class UsersControllerTest extends TestCase { 'groups' => [], 'language' => 'da', 'locale' => null, + 'backendCapabilities' => [ + 'setDisplayName' => true, + 'setPassword' => true, + ] ]; $this->assertEquals($expected, $this->invokePrivate($this->api, 'getUserData', ['UID'])); } @@ -1054,6 +1079,12 @@ class UsersControllerTest extends TestCase { ->method('fillStorageInfo') ->with('UID') ->will($this->returnValue(['DummyValue'])); + + $backend = $this->createMock(UserInterface::class); + $backend->expects($this->atLeastOnce()) + ->method('implementsActions') + ->willReturn(false); + $targetUser ->expects($this->once()) ->method('getDisplayName') @@ -1078,6 +1109,10 @@ class UsersControllerTest extends TestCase { ->expects($this->once()) ->method('getBackendClassName') ->will($this->returnValue('Database')); + $targetUser + ->expects($this->once()) + ->method('getBackend') + ->willReturn($backend); $this->config ->expects($this->at(0)) ->method('getUserValue') @@ -1110,6 +1145,10 @@ class UsersControllerTest extends TestCase { 'groups' => [], 'language' => 'ru', 'locale' => null, + 'backendCapabilities' => [ + 'setDisplayName' => false, + 'setPassword' => false, + ] ]; $this->assertEquals($expected, $this->invokePrivate($this->api, 'getUserData', ['UID'])); } |