do not offer to change display name or password, if not possible.

Fixes #12319

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
Arthur Schiwon 2018-11-07 16:35:51 +01:00
parent 836ba4f419
commit 505722cc0d
No known key found for this signature in database
GPG Key ID: 7424F1874854DF23
9 changed files with 70 additions and 15 deletions

View File

@ -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;
}

View File

@ -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')
@ -816,6 +819,10 @@ class UsersControllerTest extends TestCase {
->expects($this->once())
->method('getBackendClassName')
->will($this->returnValue('Database'));
$targetUser
->expects($this->once())
->method('getBackend')
->willReturn($backend);
$targetUser
->expects($this->exactly(6))
->method('getUID')
@ -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')
@ -922,6 +939,10 @@ class UsersControllerTest extends TestCase {
->expects($this->once())
->method('getBackendClassName')
->will($this->returnValue('Database'));
$targetUser
->expects($this->once())
->method('getBackend')
->willReturn($backend);
$targetUser
->expects($this->exactly(6))
->method('getUID')
@ -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']));
}

View File

@ -26,6 +26,8 @@
namespace OCP;
use OCP\UserInterface;
/**
* Interface IUser
*
@ -111,6 +113,7 @@ interface IUser {
/**
* Get the backend for the current user object
*
* @return UserInterface
* @since 15.0.0
*/
public function getBackend();

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -42,13 +42,17 @@
<!-- dirty hack to ellipsis on two lines -->
<div class="name">{{user.id}}</div>
<form class="displayName" :class="{'icon-loading-small': loading.displayName}" v-on:submit.prevent="updateDisplayName">
<input :id="'displayName'+user.id+rand" type="text"
:disabled="loading.displayName||loading.all"
:value="user.displayname" ref="displayName"
autocomplete="new-password" autocorrect="off" autocapitalize="off" spellcheck="false" />
<input type="submit" class="icon-confirm" value="" />
<template v-if="user.backendCapabilities.setDisplayName">
<input v-if="user.backendCapabilities.setDisplayName"
:id="'displayName'+user.id+rand" type="text"
:disabled="loading.displayName||loading.all"
:value="user.displayname" ref="displayName"
autocomplete="new-password" autocorrect="off" autocapitalize="off" spellcheck="false" />
<input v-if="user.backendCapabilities.setDisplayName" type="submit" class="icon-confirm" value="" />
</template>
<div v-else class="name" v-tooltip.auto="t('settings', 'The backend does not support changing the display name')">{{user.displayname}}</div>
</form>
<form class="password" v-if="settings.canChangePassword" :class="{'icon-loading-small': loading.password}"
<form class="password" v-if="settings.canChangePassword && user.backendCapabilities.setPassword" :class="{'icon-loading-small': loading.password}"
v-on:submit.prevent="updatePassword">
<input :id="'password'+user.id+rand" type="password" required
:disabled="loading.password||loading.all" :minlength="minPasswordLength"