Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
do not offer to change display name or password, if not possible.
Fixes #12319

Signed-off-by: Arthur Schiwon <[email protected]>
  • Loading branch information
blizzz committed Nov 7, 2018
commit 505722cc0d949ff5606b71757ec8d2ad2691b62b
9 changes: 9 additions & 0 deletions apps/provisioning_api/lib/Controller/AUserData.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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;
Expand All @@ -32,6 +33,8 @@
use OCP\IRequest;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\User\Backend\ISetDisplayNameBackend;
use OCP\User\Backend\ISetPasswordBackend;

abstract class AUserData extends OCSController {

Expand Down Expand Up @@ -125,6 +128,12 @@ protected function getUserData(string $userId): array {
$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;
}

Expand Down
47 changes: 43 additions & 4 deletions apps/provisioning_api/tests/Controller/UsersControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,22 @@
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;

Expand Down Expand Up @@ -800,6 +797,12 @@ public function testGetUserDataAsAdmin() {
->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')
Expand All @@ -816,6 +819,10 @@ public function testGetUserDataAsAdmin() {
->expects($this->once())
->method('getBackendClassName')
->will($this->returnValue('Database'));
$targetUser
->expects($this->once())
->method('getBackend')
->willReturn($backend);
$targetUser
->expects($this->exactly(6))
->method('getUID')
Expand All @@ -838,6 +845,10 @@ public function testGetUserDataAsAdmin() {
'groups' => ['group0', 'group1', 'group2'],
'language' => 'de',
'locale' => null,
'backendCapabilities' => [
'setDisplayName' => true,
'setPassword' => true,
]
];
$this->assertEquals($expected, $this->invokePrivate($this->api, 'getUserData', ['UID']));
}
Expand Down Expand Up @@ -906,6 +917,12 @@ public function testGetUserDataAsSubAdminAndUserIsAccessible() {
->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')
Expand All @@ -922,6 +939,10 @@ public function testGetUserDataAsSubAdminAndUserIsAccessible() {
->expects($this->once())
->method('getBackendClassName')
->will($this->returnValue('Database'));
$targetUser
->expects($this->once())
->method('getBackend')
->willReturn($backend);
$targetUser
->expects($this->exactly(6))
->method('getUID')
Expand Down Expand Up @@ -954,6 +975,10 @@ public function testGetUserDataAsSubAdminAndUserIsAccessible() {
'groups' => [],
'language' => 'da',
'locale' => null,
'backendCapabilities' => [
'setDisplayName' => true,
'setPassword' => true,
]
];
$this->assertEquals($expected, $this->invokePrivate($this->api, 'getUserData', ['UID']));
}
Expand Down Expand Up @@ -1054,6 +1079,12 @@ public function testGetUserDataAsSubAdminSelfLookup() {
->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')
Expand All @@ -1078,6 +1109,10 @@ public function testGetUserDataAsSubAdminSelfLookup() {
->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')
Expand Down Expand Up @@ -1110,6 +1145,10 @@ public function testGetUserDataAsSubAdminSelfLookup() {
'groups' => [],
'language' => 'ru',
'locale' => null,
'backendCapabilities' => [
'setDisplayName' => false,
'setPassword' => false,
]
];
$this->assertEquals($expected, $this->invokePrivate($this->api, 'getUserData', ['UID']));
}
Expand Down
3 changes: 3 additions & 0 deletions lib/public/IUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

namespace OCP;

use OCP\UserInterface;

/**
* Interface IUser
*
Expand Down Expand Up @@ -111,6 +113,7 @@ public function getBackendClassName();
/**
* Get the backend for the current user object
*
* @return UserInterface
* @since 15.0.0
*/
public function getBackend();
Expand Down
2 changes: 1 addition & 1 deletion settings/js/4.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion settings/js/5.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion settings/js/5.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion settings/js/settings-admin-security.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion settings/js/settings-vue.js.map

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions settings/src/components/userList/userRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down