Merge pull request #10687 from nextcloud/fix/noid/false-positive-change-mention
don't blame randome people for background email updates
This commit is contained in:
commit
9cf11bd73c
|
@ -97,14 +97,25 @@ class UserManagement extends Action {
|
||||||
* @param array $params
|
* @param array $params
|
||||||
*/
|
*/
|
||||||
public function change(array $params) {
|
public function change(array $params) {
|
||||||
if ($params['feature'] === 'enabled') {
|
switch($params['feature']) {
|
||||||
$this->log(
|
case 'enabled':
|
||||||
$params['value'] === 'true' ? 'User enabled: "%s"' : 'User disabled: "%s"',
|
$this->log(
|
||||||
['user' => $params['user']->getUID()],
|
$params['value'] === 'true' ? 'User enabled: "%s"' : 'User disabled: "%s"',
|
||||||
[
|
['user' => $params['user']->getUID()],
|
||||||
'user',
|
[
|
||||||
]
|
'user',
|
||||||
);
|
]
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case 'eMailAddress':
|
||||||
|
$this->log(
|
||||||
|
'Email address changed for user %s',
|
||||||
|
['user' => $params['user']->getUID()],
|
||||||
|
[
|
||||||
|
'user',
|
||||||
|
]
|
||||||
|
);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -318,11 +318,6 @@ class User_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserIn
|
||||||
$dn = $user->getDN();
|
$dn = $user->getDN();
|
||||||
//check if user really still exists by reading its entry
|
//check if user really still exists by reading its entry
|
||||||
if(!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) {
|
if(!is_array($this->access->readAttribute($dn, '', $this->access->connection->ldapUserFilter))) {
|
||||||
$lcr = $this->access->connection->getConnectionResource();
|
|
||||||
if(is_null($lcr)) {
|
|
||||||
throw new \Exception('No LDAP Connection to server ' . $this->access->connection->ldapHost);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$uuid = $this->access->getUserMapper()->getUUIDByDN($dn);
|
$uuid = $this->access->getUserMapper()->getUUIDByDN($dn);
|
||||||
if (!$uuid) {
|
if (!$uuid) {
|
||||||
|
@ -330,7 +325,7 @@ class User_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserIn
|
||||||
}
|
}
|
||||||
$newDn = $this->access->getUserDnByUuid($uuid);
|
$newDn = $this->access->getUserDnByUuid($uuid);
|
||||||
//check if renamed user is still valid by reapplying the ldap filter
|
//check if renamed user is still valid by reapplying the ldap filter
|
||||||
if (!is_array($this->access->readAttribute($newDn, '', $this->access->connection->ldapUserFilter))) {
|
if ($newDn === $dn || !is_array($this->access->readAttribute($newDn, '', $this->access->connection->ldapUserFilter))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$this->access->getUserMapper()->setDNbyUUID($newDn, $uuid);
|
$this->access->getUserMapper()->setDNbyUUID($newDn, $uuid);
|
||||||
|
@ -376,9 +371,6 @@ class User_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserIn
|
||||||
|
|
||||||
$result = $this->userExistsOnLDAP($user);
|
$result = $this->userExistsOnLDAP($user);
|
||||||
$this->access->connection->writeToCache('userExists'.$uid, $result);
|
$this->access->connection->writeToCache('userExists'.$uid, $result);
|
||||||
if($result === true) {
|
|
||||||
$user->update();
|
|
||||||
}
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -515,13 +515,16 @@ class User_LDAPTest extends TestCase {
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \Exception
|
|
||||||
*/
|
|
||||||
public function testUserExistsForDeleted() {
|
public function testUserExistsForDeleted() {
|
||||||
$backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
|
$backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
|
||||||
$this->prepareMockForUserExists();
|
$this->prepareMockForUserExists();
|
||||||
|
|
||||||
|
$mapper = $this->createMock(UserMapping::class);
|
||||||
|
$mapper->expects($this->any())
|
||||||
|
->method('getUUIDByDN')
|
||||||
|
->with('dnOfFormerUser,dc=test')
|
||||||
|
->willReturn('45673458748');
|
||||||
|
|
||||||
$this->access->expects($this->any())
|
$this->access->expects($this->any())
|
||||||
->method('readAttribute')
|
->method('readAttribute')
|
||||||
->will($this->returnCallback(function($dn) {
|
->will($this->returnCallback(function($dn) {
|
||||||
|
@ -530,13 +533,24 @@ class User_LDAPTest extends TestCase {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}));
|
}));
|
||||||
|
$this->access->expects($this->any())
|
||||||
|
->method('getUserMapper')
|
||||||
|
->willReturn($mapper);
|
||||||
|
$this->access->expects($this->once())
|
||||||
|
->method('getUserDnByUuid')
|
||||||
|
->willThrowException(new \Exception());
|
||||||
|
|
||||||
|
$user = $this->createMock(User::class);
|
||||||
|
$user->expects($this->any())
|
||||||
|
->method('getDN')
|
||||||
|
->willReturn('dnOfFormerUser,dc=test');
|
||||||
|
|
||||||
$this->userManager->expects($this->atLeastOnce())
|
$this->userManager->expects($this->atLeastOnce())
|
||||||
->method('get')
|
->method('get')
|
||||||
->willReturn($this->createMock(User::class));
|
->willReturn($user);
|
||||||
|
|
||||||
//test for deleted user
|
//test for deleted user
|
||||||
$backend->userExists('formerUser');
|
$this->assertFalse($backend->userExists('formerUser'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUserExistsForNeverExisting() {
|
public function testUserExistsForNeverExisting() {
|
||||||
|
@ -588,14 +602,17 @@ class User_LDAPTest extends TestCase {
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \Exception
|
|
||||||
*/
|
|
||||||
public function testUserExistsPublicAPIForDeleted() {
|
public function testUserExistsPublicAPIForDeleted() {
|
||||||
$backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
|
$backend = new UserLDAP($this->access, $this->config, $this->notificationManager, $this->session, $this->pluginManager);
|
||||||
$this->prepareMockForUserExists();
|
$this->prepareMockForUserExists();
|
||||||
\OC_User::useBackend($backend);
|
\OC_User::useBackend($backend);
|
||||||
|
|
||||||
|
$mapper = $this->createMock(UserMapping::class);
|
||||||
|
$mapper->expects($this->any())
|
||||||
|
->method('getUUIDByDN')
|
||||||
|
->with('dnOfFormerUser,dc=test')
|
||||||
|
->willReturn('45673458748');
|
||||||
|
|
||||||
$this->access->expects($this->any())
|
$this->access->expects($this->any())
|
||||||
->method('readAttribute')
|
->method('readAttribute')
|
||||||
->will($this->returnCallback(function($dn) {
|
->will($this->returnCallback(function($dn) {
|
||||||
|
@ -604,12 +621,24 @@ class User_LDAPTest extends TestCase {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}));
|
}));
|
||||||
|
$this->access->expects($this->any())
|
||||||
|
->method('getUserMapper')
|
||||||
|
->willReturn($mapper);
|
||||||
|
$this->access->expects($this->once())
|
||||||
|
->method('getUserDnByUuid')
|
||||||
|
->willThrowException(new \Exception());
|
||||||
|
|
||||||
|
$user = $this->createMock(User::class);
|
||||||
|
$user->expects($this->any())
|
||||||
|
->method('getDN')
|
||||||
|
->willReturn('dnOfFormerUser,dc=test');
|
||||||
|
|
||||||
$this->userManager->expects($this->atLeastOnce())
|
$this->userManager->expects($this->atLeastOnce())
|
||||||
->method('get')
|
->method('get')
|
||||||
->willReturn($this->createMock(User::class));
|
->willReturn($user);
|
||||||
|
|
||||||
//test for deleted user
|
//test for deleted user
|
||||||
\OC::$server->getUserManager()->userExists('formerUser');
|
$this->assertFalse(\OC::$server->getUserManager()->userExists('formerUser'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUserExistsPublicAPIForNeverExisting() {
|
public function testUserExistsPublicAPIForNeverExisting() {
|
||||||
|
@ -762,6 +791,14 @@ class User_LDAPTest extends TestCase {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
$this->access->connection->expects($this->any())
|
||||||
|
->method('getFromCache')
|
||||||
|
->willReturnCallback(function($key) {
|
||||||
|
if($key === 'userExistsnewyorker') {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
$user = $this->createMock(User::class);
|
$user = $this->createMock(User::class);
|
||||||
$user->expects($this->any())
|
$user->expects($this->any())
|
||||||
|
|
|
@ -165,6 +165,7 @@ class Hooks {
|
||||||
|
|
||||||
$actor = $this->userSession->getUser();
|
$actor = $this->userSession->getUser();
|
||||||
if ($actor instanceof IUser) {
|
if ($actor instanceof IUser) {
|
||||||
|
$subject = Provider::EMAIL_CHANGED_SELF;
|
||||||
if ($actor->getUID() !== $user->getUID()) {
|
if ($actor->getUID() !== $user->getUID()) {
|
||||||
$this->l = $this->languageFactory->get(
|
$this->l = $this->languageFactory->get(
|
||||||
'settings',
|
'settings',
|
||||||
|
@ -173,15 +174,11 @@ class Hooks {
|
||||||
$this->config->getSystemValue('default_language', 'en')
|
$this->config->getSystemValue('default_language', 'en')
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
$subject = Provider::EMAIL_CHANGED;
|
||||||
$text = $this->l->t('%1$s changed your email address on %2$s.', [$actor->getDisplayName(), $instanceUrl]);
|
|
||||||
$event->setAuthor($actor->getUID())
|
|
||||||
->setSubject(Provider::EMAIL_CHANGED_BY, [$actor->getUID()]);
|
|
||||||
} else {
|
|
||||||
$text = $this->l->t('Your email address on %s was changed.', [$instanceUrl]);
|
|
||||||
$event->setAuthor($actor->getUID())
|
|
||||||
->setSubject(Provider::EMAIL_CHANGED_SELF);
|
|
||||||
}
|
}
|
||||||
|
$text = $this->l->t('Your email address on %s was changed.', [$instanceUrl]);
|
||||||
|
$event->setAuthor($actor->getUID())
|
||||||
|
->setSubject($subject);
|
||||||
} else {
|
} else {
|
||||||
$text = $this->l->t('Your email address on %s was changed by an administrator.', [$instanceUrl]);
|
$text = $this->l->t('Your email address on %s was changed by an administrator.', [$instanceUrl]);
|
||||||
$event->setSubject(Provider::EMAIL_CHANGED);
|
$event->setSubject(Provider::EMAIL_CHANGED);
|
||||||
|
|
Loading…
Reference in New Issue