Merge pull request #4499 from nextcloud/downstream-26984
Trigger change when a user is enabled/disabled
This commit is contained in:
commit
255c7df3bd
|
@ -60,6 +60,23 @@ class UserManagement extends Action {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log enabling of users
|
||||
*
|
||||
* @param array $params
|
||||
*/
|
||||
public function change(array $params) {
|
||||
if ($params['feature'] === 'enabled') {
|
||||
$this->log(
|
||||
$params['value'] === 'true' ? 'User enabled: "%s"' : 'User disabled: "%s"',
|
||||
['user' => $params['user']->getUID()],
|
||||
[
|
||||
'user',
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs changing of the user scope
|
||||
*
|
||||
|
|
|
@ -90,6 +90,7 @@ class AuditLogger {
|
|||
|
||||
Util::connectHook('OC_User', 'post_createUser', $userActions, 'create');
|
||||
Util::connectHook('OC_User', 'post_deleteUser', $userActions, 'delete');
|
||||
Util::connectHook('OC_User', 'changeUser', $userActions, 'change');
|
||||
$this->userSession->listen('\OC\User', 'postSetPassword', [$userActions, 'setPassword']);
|
||||
}
|
||||
|
||||
|
|
|
@ -342,9 +342,13 @@ class User implements IUser {
|
|||
* @param bool $enabled
|
||||
*/
|
||||
public function setEnabled($enabled) {
|
||||
$oldStatus = $this->isEnabled();
|
||||
$this->enabled = $enabled;
|
||||
$enabled = ($enabled) ? 'true' : 'false';
|
||||
$this->config->setUserValue($this->uid, 'core', 'enabled', $enabled);
|
||||
if ($oldStatus !== $this->enabled) {
|
||||
$this->triggerChange('enabled', $enabled);
|
||||
$this->config->setUserValue($this->uid, 'core', 'enabled', $enabled);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -705,7 +705,55 @@ class UserTest extends TestCase {
|
|||
'false'
|
||||
);
|
||||
|
||||
$user = new User('foo', $backend, null, $config);
|
||||
$user = $this->getMockBuilder(User::class)
|
||||
->setConstructorArgs([
|
||||
'foo',
|
||||
$backend,
|
||||
null,
|
||||
$config,
|
||||
])
|
||||
->setMethods(['isEnabled', 'triggerChange'])
|
||||
->getMock();
|
||||
|
||||
$user->expects($this->once())
|
||||
->method('isEnabled')
|
||||
->willReturn(true);
|
||||
$user->expects($this->once())
|
||||
->method('triggerChange')
|
||||
->with(
|
||||
'enabled',
|
||||
'false'
|
||||
);
|
||||
|
||||
$user->setEnabled(false);
|
||||
}
|
||||
|
||||
public function testSetDisabledAlreadyDisabled() {
|
||||
/**
|
||||
* @var Backend | \PHPUnit_Framework_MockObject_MockObject $backend
|
||||
*/
|
||||
$backend = $this->createMock(\Test\Util\User\Dummy::class);
|
||||
|
||||
$config = $this->createMock(IConfig::class);
|
||||
$config->expects($this->never())
|
||||
->method('setUserValue');
|
||||
|
||||
$user = $this->getMockBuilder(User::class)
|
||||
->setConstructorArgs([
|
||||
'foo',
|
||||
$backend,
|
||||
null,
|
||||
$config,
|
||||
])
|
||||
->setMethods(['isEnabled', 'triggerChange'])
|
||||
->getMock();
|
||||
|
||||
$user->expects($this->once())
|
||||
->method('isEnabled')
|
||||
->willReturn(false);
|
||||
$user->expects($this->never())
|
||||
->method('triggerChange');
|
||||
|
||||
$user->setEnabled(false);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue