Make code strict
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
eab710c2fd
commit
da9462b482
|
@ -26,6 +26,7 @@
|
||||||
namespace OCA\DAV\CardDAV;
|
namespace OCA\DAV\CardDAV;
|
||||||
|
|
||||||
use OC\Accounts\AccountManager;
|
use OC\Accounts\AccountManager;
|
||||||
|
use OCP\Accounts\IAccountManager;
|
||||||
use OCP\IImage;
|
use OCP\IImage;
|
||||||
use OCP\IUser;
|
use OCP\IUser;
|
||||||
use Sabre\VObject\Component\VCard;
|
use Sabre\VObject\Component\VCard;
|
||||||
|
@ -62,8 +63,8 @@ class Converter {
|
||||||
|
|
||||||
$publish = false;
|
$publish = false;
|
||||||
|
|
||||||
if ($image !== null && isset($userData[AccountManager::PROPERTY_AVATAR])) {
|
if ($image !== null && isset($userData[IAccountManager::PROPERTY_AVATAR])) {
|
||||||
$userData[AccountManager::PROPERTY_AVATAR]['value'] = true;
|
$userData[IAccountManager::PROPERTY_AVATAR]['value'] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($userData as $property => $value) {
|
foreach ($userData as $property => $value) {
|
||||||
|
@ -76,28 +77,28 @@ class Converter {
|
||||||
if ($shareWithTrustedServers && !$emptyValue) {
|
if ($shareWithTrustedServers && !$emptyValue) {
|
||||||
$publish = true;
|
$publish = true;
|
||||||
switch ($property) {
|
switch ($property) {
|
||||||
case AccountManager::PROPERTY_DISPLAYNAME:
|
case IAccountManager::PROPERTY_DISPLAYNAME:
|
||||||
$vCard->add(new Text($vCard, 'FN', $value['value']));
|
$vCard->add(new Text($vCard, 'FN', $value['value']));
|
||||||
$vCard->add(new Text($vCard, 'N', $this->splitFullName($value['value'])));
|
$vCard->add(new Text($vCard, 'N', $this->splitFullName($value['value'])));
|
||||||
break;
|
break;
|
||||||
case AccountManager::PROPERTY_AVATAR:
|
case IAccountManager::PROPERTY_AVATAR:
|
||||||
if ($image !== null) {
|
if ($image !== null) {
|
||||||
$vCard->add('PHOTO', $image->data(), ['ENCODING' => 'b', 'TYPE' => $image->mimeType()]);
|
$vCard->add('PHOTO', $image->data(), ['ENCODING' => 'b', 'TYPE' => $image->mimeType()]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case AccountManager::PROPERTY_EMAIL:
|
case IAccountManager::PROPERTY_EMAIL:
|
||||||
$vCard->add(new Text($vCard, 'EMAIL', $value['value'], ['TYPE' => 'OTHER']));
|
$vCard->add(new Text($vCard, 'EMAIL', $value['value'], ['TYPE' => 'OTHER']));
|
||||||
break;
|
break;
|
||||||
case AccountManager::PROPERTY_WEBSITE:
|
case IAccountManager::PROPERTY_WEBSITE:
|
||||||
$vCard->add(new Text($vCard, 'URL', $value['value']));
|
$vCard->add(new Text($vCard, 'URL', $value['value']));
|
||||||
break;
|
break;
|
||||||
case AccountManager::PROPERTY_PHONE:
|
case IAccountManager::PROPERTY_PHONE:
|
||||||
$vCard->add(new Text($vCard, 'TEL', $value['value'], ['TYPE' => 'OTHER']));
|
$vCard->add(new Text($vCard, 'TEL', $value['value'], ['TYPE' => 'OTHER']));
|
||||||
break;
|
break;
|
||||||
case AccountManager::PROPERTY_ADDRESS:
|
case IAccountManager::PROPERTY_ADDRESS:
|
||||||
$vCard->add(new Text($vCard, 'ADR', $value['value'], ['TYPE' => 'OTHER']));
|
$vCard->add(new Text($vCard, 'ADR', $value['value'], ['TYPE' => 'OTHER']));
|
||||||
break;
|
break;
|
||||||
case AccountManager::PROPERTY_TWITTER:
|
case IAccountManager::PROPERTY_TWITTER:
|
||||||
$vCard->add(new Text($vCard, 'X-SOCIALPROFILE', $value['value'], ['TYPE' => 'TWITTER']));
|
$vCard->add(new Text($vCard, 'X-SOCIALPROFILE', $value['value'], ['TYPE' => 'TWITTER']));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,13 +29,14 @@ namespace OCA\DAV\Tests\unit\CardDAV;
|
||||||
|
|
||||||
use OC\Accounts\AccountManager;
|
use OC\Accounts\AccountManager;
|
||||||
use OCA\DAV\CardDAV\Converter;
|
use OCA\DAV\CardDAV\Converter;
|
||||||
|
use OCP\Accounts\IAccountManager;
|
||||||
use OCP\IImage;
|
use OCP\IImage;
|
||||||
use OCP\IUser;
|
use OCP\IUser;
|
||||||
use Test\TestCase;
|
use Test\TestCase;
|
||||||
|
|
||||||
class ConverterTest extends TestCase {
|
class ConverterTest extends TestCase {
|
||||||
|
|
||||||
/** @var AccountManager | \PHPUnit\Framework\MockObject\MockObject */
|
/** @var AccountManager|\PHPUnit\Framework\MockObject\MockObject */
|
||||||
private $accountManager;
|
private $accountManager;
|
||||||
|
|
||||||
protected function setUp(): void {
|
protected function setUp(): void {
|
||||||
|
@ -49,36 +50,36 @@ class ConverterTest extends TestCase {
|
||||||
->disableOriginalConstructor()->getMock();
|
->disableOriginalConstructor()->getMock();
|
||||||
$accountManager->expects($this->any())->method('getUser')->willReturn(
|
$accountManager->expects($this->any())->method('getUser')->willReturn(
|
||||||
[
|
[
|
||||||
AccountManager::PROPERTY_DISPLAYNAME =>
|
IAccountManager::PROPERTY_DISPLAYNAME =>
|
||||||
[
|
[
|
||||||
'value' => $user->getDisplayName(),
|
'value' => $user->getDisplayName(),
|
||||||
'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY,
|
'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY,
|
||||||
],
|
],
|
||||||
AccountManager::PROPERTY_ADDRESS =>
|
IAccountManager::PROPERTY_ADDRESS =>
|
||||||
[
|
[
|
||||||
'value' => '',
|
'value' => '',
|
||||||
'scope' => AccountManager::VISIBILITY_PRIVATE,
|
'scope' => AccountManager::VISIBILITY_PRIVATE,
|
||||||
],
|
],
|
||||||
AccountManager::PROPERTY_WEBSITE =>
|
IAccountManager::PROPERTY_WEBSITE =>
|
||||||
[
|
[
|
||||||
'value' => '',
|
'value' => '',
|
||||||
'scope' => AccountManager::VISIBILITY_PRIVATE,
|
'scope' => AccountManager::VISIBILITY_PRIVATE,
|
||||||
],
|
],
|
||||||
AccountManager::PROPERTY_EMAIL =>
|
IAccountManager::PROPERTY_EMAIL =>
|
||||||
[
|
[
|
||||||
'value' => $user->getEMailAddress(),
|
'value' => $user->getEMailAddress(),
|
||||||
'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY,
|
'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY,
|
||||||
],
|
],
|
||||||
AccountManager::PROPERTY_AVATAR =>
|
IAccountManager::PROPERTY_AVATAR =>
|
||||||
[
|
[
|
||||||
'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY
|
'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY
|
||||||
],
|
],
|
||||||
AccountManager::PROPERTY_PHONE =>
|
IAccountManager::PROPERTY_PHONE =>
|
||||||
[
|
[
|
||||||
'value' => '',
|
'value' => '',
|
||||||
'scope' => AccountManager::VISIBILITY_PRIVATE,
|
'scope' => AccountManager::VISIBILITY_PRIVATE,
|
||||||
],
|
],
|
||||||
AccountManager::PROPERTY_TWITTER =>
|
IAccountManager::PROPERTY_TWITTER =>
|
||||||
[
|
[
|
||||||
'value' => '',
|
'value' => '',
|
||||||
'scope' => AccountManager::VISIBILITY_PRIVATE,
|
'scope' => AccountManager::VISIBILITY_PRIVATE,
|
||||||
|
|
|
@ -31,6 +31,7 @@ namespace OCA\DAV\Tests\unit\CardDAV;
|
||||||
use OC\Accounts\AccountManager;
|
use OC\Accounts\AccountManager;
|
||||||
use OCA\DAV\CardDAV\CardDavBackend;
|
use OCA\DAV\CardDAV\CardDavBackend;
|
||||||
use OCA\DAV\CardDAV\SyncService;
|
use OCA\DAV\CardDAV\SyncService;
|
||||||
|
use OCP\Accounts\IAccountManager;
|
||||||
use OCP\ILogger;
|
use OCP\ILogger;
|
||||||
use OCP\IUser;
|
use OCP\IUser;
|
||||||
use OCP\IUserManager;
|
use OCP\IUserManager;
|
||||||
|
@ -132,36 +133,36 @@ class SyncServiceTest extends TestCase {
|
||||||
$accountManager = $this->getMockBuilder(AccountManager::class)->disableOriginalConstructor()->getMock();
|
$accountManager = $this->getMockBuilder(AccountManager::class)->disableOriginalConstructor()->getMock();
|
||||||
$accountManager->expects($this->any())->method('getUser')
|
$accountManager->expects($this->any())->method('getUser')
|
||||||
->willReturn([
|
->willReturn([
|
||||||
AccountManager::PROPERTY_DISPLAYNAME =>
|
IAccountManager::PROPERTY_DISPLAYNAME =>
|
||||||
[
|
[
|
||||||
'value' => $user->getDisplayName(),
|
'value' => $user->getDisplayName(),
|
||||||
'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY,
|
'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY,
|
||||||
],
|
],
|
||||||
AccountManager::PROPERTY_ADDRESS =>
|
IAccountManager::PROPERTY_ADDRESS =>
|
||||||
[
|
[
|
||||||
'value' => '',
|
'value' => '',
|
||||||
'scope' => AccountManager::VISIBILITY_PRIVATE,
|
'scope' => AccountManager::VISIBILITY_PRIVATE,
|
||||||
],
|
],
|
||||||
AccountManager::PROPERTY_WEBSITE =>
|
IAccountManager::PROPERTY_WEBSITE =>
|
||||||
[
|
[
|
||||||
'value' => '',
|
'value' => '',
|
||||||
'scope' => AccountManager::VISIBILITY_PRIVATE,
|
'scope' => AccountManager::VISIBILITY_PRIVATE,
|
||||||
],
|
],
|
||||||
AccountManager::PROPERTY_EMAIL =>
|
IAccountManager::PROPERTY_EMAIL =>
|
||||||
[
|
[
|
||||||
'value' => $user->getEMailAddress(),
|
'value' => $user->getEMailAddress(),
|
||||||
'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY,
|
'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY,
|
||||||
],
|
],
|
||||||
AccountManager::PROPERTY_AVATAR =>
|
IAccountManager::PROPERTY_AVATAR =>
|
||||||
[
|
[
|
||||||
'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY
|
'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY
|
||||||
],
|
],
|
||||||
AccountManager::PROPERTY_PHONE =>
|
IAccountManager::PROPERTY_PHONE =>
|
||||||
[
|
[
|
||||||
'value' => '',
|
'value' => '',
|
||||||
'scope' => AccountManager::VISIBILITY_PRIVATE,
|
'scope' => AccountManager::VISIBILITY_PRIVATE,
|
||||||
],
|
],
|
||||||
AccountManager::PROPERTY_TWITTER =>
|
IAccountManager::PROPERTY_TWITTER =>
|
||||||
[
|
[
|
||||||
'value' => '',
|
'value' => '',
|
||||||
'scope' => AccountManager::VISIBILITY_PRIVATE,
|
'scope' => AccountManager::VISIBILITY_PRIVATE,
|
||||||
|
|
|
@ -35,6 +35,7 @@ use OC\Accounts\AccountManager;
|
||||||
use OC\User\Backend;
|
use OC\User\Backend;
|
||||||
use OC\User\NoUserException;
|
use OC\User\NoUserException;
|
||||||
use OC_Helper;
|
use OC_Helper;
|
||||||
|
use OCP\Accounts\IAccountManager;
|
||||||
use OCP\AppFramework\OCS\OCSException;
|
use OCP\AppFramework\OCS\OCSException;
|
||||||
use OCP\AppFramework\OCS\OCSNotFoundException;
|
use OCP\AppFramework\OCS\OCSNotFoundException;
|
||||||
use OCP\AppFramework\OCSController;
|
use OCP\AppFramework\OCSController;
|
||||||
|
@ -135,12 +136,12 @@ abstract class AUserData extends OCSController {
|
||||||
$data['backend'] = $targetUserObject->getBackendClassName();
|
$data['backend'] = $targetUserObject->getBackendClassName();
|
||||||
$data['subadmin'] = $this->getUserSubAdminGroupsData($targetUserObject->getUID());
|
$data['subadmin'] = $this->getUserSubAdminGroupsData($targetUserObject->getUID());
|
||||||
$data['quota'] = $this->fillStorageInfo($targetUserObject->getUID());
|
$data['quota'] = $this->fillStorageInfo($targetUserObject->getUID());
|
||||||
$data[AccountManager::PROPERTY_EMAIL] = $targetUserObject->getEMailAddress();
|
$data[IAccountManager::PROPERTY_EMAIL] = $targetUserObject->getEMailAddress();
|
||||||
$data[AccountManager::PROPERTY_DISPLAYNAME] = $targetUserObject->getDisplayName();
|
$data[IAccountManager::PROPERTY_DISPLAYNAME] = $targetUserObject->getDisplayName();
|
||||||
$data[AccountManager::PROPERTY_PHONE] = $userAccount[AccountManager::PROPERTY_PHONE]['value'];
|
$data[IAccountManager::PROPERTY_PHONE] = $userAccount[IAccountManager::PROPERTY_PHONE]['value'];
|
||||||
$data[AccountManager::PROPERTY_ADDRESS] = $userAccount[AccountManager::PROPERTY_ADDRESS]['value'];
|
$data[IAccountManager::PROPERTY_ADDRESS] = $userAccount[IAccountManager::PROPERTY_ADDRESS]['value'];
|
||||||
$data[AccountManager::PROPERTY_WEBSITE] = $userAccount[AccountManager::PROPERTY_WEBSITE]['value'];
|
$data[IAccountManager::PROPERTY_WEBSITE] = $userAccount[IAccountManager::PROPERTY_WEBSITE]['value'];
|
||||||
$data[AccountManager::PROPERTY_TWITTER] = $userAccount[AccountManager::PROPERTY_TWITTER]['value'];
|
$data[IAccountManager::PROPERTY_TWITTER] = $userAccount[IAccountManager::PROPERTY_TWITTER]['value'];
|
||||||
$data['groups'] = $gids;
|
$data['groups'] = $gids;
|
||||||
$data['language'] = $this->l10nFactory->getUserLanguage($targetUserObject);
|
$data['language'] = $this->l10nFactory->getUserLanguage($targetUserObject);
|
||||||
$data['locale'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'locale');
|
$data['locale'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'locale');
|
||||||
|
|
|
@ -46,6 +46,7 @@ use OC\Authentication\Token\RemoteWipe;
|
||||||
use OC\HintException;
|
use OC\HintException;
|
||||||
use OCA\Provisioning_API\FederatedShareProviderFactory;
|
use OCA\Provisioning_API\FederatedShareProviderFactory;
|
||||||
use OCA\Settings\Mailer\NewUserMailHelper;
|
use OCA\Settings\Mailer\NewUserMailHelper;
|
||||||
|
use OCP\Accounts\IAccountManager;
|
||||||
use OCP\App\IAppManager;
|
use OCP\App\IAppManager;
|
||||||
use OCP\AppFramework\Http\DataResponse;
|
use OCP\AppFramework\Http\DataResponse;
|
||||||
use OCP\AppFramework\OCS\OCSException;
|
use OCP\AppFramework\OCS\OCSException;
|
||||||
|
@ -431,17 +432,17 @@ class UsersController extends AUserData {
|
||||||
|
|
||||||
// Editing self (display, email)
|
// Editing self (display, email)
|
||||||
if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) {
|
if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) {
|
||||||
$permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME;
|
$permittedFields[] = IAccountManager::PROPERTY_DISPLAYNAME;
|
||||||
$permittedFields[] = AccountManager::PROPERTY_EMAIL;
|
$permittedFields[] = IAccountManager::PROPERTY_EMAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->appManager->isEnabledForUser('federatedfilesharing')) {
|
if ($this->appManager->isEnabledForUser('federatedfilesharing')) {
|
||||||
$shareProvider = $this->federatedShareProviderFactory->get();
|
$shareProvider = $this->federatedShareProviderFactory->get();
|
||||||
if ($shareProvider->isLookupServerUploadEnabled()) {
|
if ($shareProvider->isLookupServerUploadEnabled()) {
|
||||||
$permittedFields[] = AccountManager::PROPERTY_PHONE;
|
$permittedFields[] = IAccountManager::PROPERTY_PHONE;
|
||||||
$permittedFields[] = AccountManager::PROPERTY_ADDRESS;
|
$permittedFields[] = IAccountManager::PROPERTY_ADDRESS;
|
||||||
$permittedFields[] = AccountManager::PROPERTY_WEBSITE;
|
$permittedFields[] = IAccountManager::PROPERTY_WEBSITE;
|
||||||
$permittedFields[] = AccountManager::PROPERTY_TWITTER;
|
$permittedFields[] = IAccountManager::PROPERTY_TWITTER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -474,8 +475,8 @@ class UsersController extends AUserData {
|
||||||
// Editing self (display, email)
|
// Editing self (display, email)
|
||||||
if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) {
|
if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) {
|
||||||
$permittedFields[] = 'display';
|
$permittedFields[] = 'display';
|
||||||
$permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME;
|
$permittedFields[] = IAccountManager::PROPERTY_DISPLAYNAME;
|
||||||
$permittedFields[] = AccountManager::PROPERTY_EMAIL;
|
$permittedFields[] = IAccountManager::PROPERTY_EMAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
$permittedFields[] = 'password';
|
$permittedFields[] = 'password';
|
||||||
|
@ -492,10 +493,10 @@ class UsersController extends AUserData {
|
||||||
if ($this->appManager->isEnabledForUser('federatedfilesharing')) {
|
if ($this->appManager->isEnabledForUser('federatedfilesharing')) {
|
||||||
$shareProvider = $this->federatedShareProviderFactory->get();
|
$shareProvider = $this->federatedShareProviderFactory->get();
|
||||||
if ($shareProvider->isLookupServerUploadEnabled()) {
|
if ($shareProvider->isLookupServerUploadEnabled()) {
|
||||||
$permittedFields[] = AccountManager::PROPERTY_PHONE;
|
$permittedFields[] = IAccountManager::PROPERTY_PHONE;
|
||||||
$permittedFields[] = AccountManager::PROPERTY_ADDRESS;
|
$permittedFields[] = IAccountManager::PROPERTY_ADDRESS;
|
||||||
$permittedFields[] = AccountManager::PROPERTY_WEBSITE;
|
$permittedFields[] = IAccountManager::PROPERTY_WEBSITE;
|
||||||
$permittedFields[] = AccountManager::PROPERTY_TWITTER;
|
$permittedFields[] = IAccountManager::PROPERTY_TWITTER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -510,15 +511,15 @@ class UsersController extends AUserData {
|
||||||
|| $subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) {
|
|| $subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) {
|
||||||
// They have permissions over the user
|
// They have permissions over the user
|
||||||
$permittedFields[] = 'display';
|
$permittedFields[] = 'display';
|
||||||
$permittedFields[] = AccountManager::PROPERTY_DISPLAYNAME;
|
$permittedFields[] = IAccountManager::PROPERTY_DISPLAYNAME;
|
||||||
$permittedFields[] = AccountManager::PROPERTY_EMAIL;
|
$permittedFields[] = IAccountManager::PROPERTY_EMAIL;
|
||||||
$permittedFields[] = 'password';
|
$permittedFields[] = 'password';
|
||||||
$permittedFields[] = 'language';
|
$permittedFields[] = 'language';
|
||||||
$permittedFields[] = 'locale';
|
$permittedFields[] = 'locale';
|
||||||
$permittedFields[] = AccountManager::PROPERTY_PHONE;
|
$permittedFields[] = IAccountManager::PROPERTY_PHONE;
|
||||||
$permittedFields[] = AccountManager::PROPERTY_ADDRESS;
|
$permittedFields[] = IAccountManager::PROPERTY_ADDRESS;
|
||||||
$permittedFields[] = AccountManager::PROPERTY_WEBSITE;
|
$permittedFields[] = IAccountManager::PROPERTY_WEBSITE;
|
||||||
$permittedFields[] = AccountManager::PROPERTY_TWITTER;
|
$permittedFields[] = IAccountManager::PROPERTY_TWITTER;
|
||||||
$permittedFields[] = 'quota';
|
$permittedFields[] = 'quota';
|
||||||
} else {
|
} else {
|
||||||
// No rights
|
// No rights
|
||||||
|
@ -532,7 +533,7 @@ class UsersController extends AUserData {
|
||||||
// Process the edit
|
// Process the edit
|
||||||
switch ($key) {
|
switch ($key) {
|
||||||
case 'display':
|
case 'display':
|
||||||
case AccountManager::PROPERTY_DISPLAYNAME:
|
case IAccountManager::PROPERTY_DISPLAYNAME:
|
||||||
$targetUser->setDisplayName($value);
|
$targetUser->setDisplayName($value);
|
||||||
break;
|
break;
|
||||||
case 'quota':
|
case 'quota':
|
||||||
|
@ -577,17 +578,17 @@ class UsersController extends AUserData {
|
||||||
}
|
}
|
||||||
$this->config->setUserValue($targetUser->getUID(), 'core', 'locale', $value);
|
$this->config->setUserValue($targetUser->getUID(), 'core', 'locale', $value);
|
||||||
break;
|
break;
|
||||||
case AccountManager::PROPERTY_EMAIL:
|
case IAccountManager::PROPERTY_EMAIL:
|
||||||
if (filter_var($value, FILTER_VALIDATE_EMAIL) || $value === '') {
|
if (filter_var($value, FILTER_VALIDATE_EMAIL) || $value === '') {
|
||||||
$targetUser->setEMailAddress($value);
|
$targetUser->setEMailAddress($value);
|
||||||
} else {
|
} else {
|
||||||
throw new OCSException('', 102);
|
throw new OCSException('', 102);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case AccountManager::PROPERTY_PHONE:
|
case IAccountManager::PROPERTY_PHONE:
|
||||||
case AccountManager::PROPERTY_ADDRESS:
|
case IAccountManager::PROPERTY_ADDRESS:
|
||||||
case AccountManager::PROPERTY_WEBSITE:
|
case IAccountManager::PROPERTY_WEBSITE:
|
||||||
case AccountManager::PROPERTY_TWITTER:
|
case IAccountManager::PROPERTY_TWITTER:
|
||||||
$userAccount = $this->accountManager->getUser($targetUser);
|
$userAccount = $this->accountManager->getUser($targetUser);
|
||||||
if ($userAccount[$key]['value'] !== $value) {
|
if ($userAccount[$key]['value'] !== $value) {
|
||||||
$userAccount[$key]['value'] = $value;
|
$userAccount[$key]['value'] = $value;
|
||||||
|
|
|
@ -35,6 +35,7 @@ use OC\Group\Manager;
|
||||||
use OC\SubAdmin;
|
use OC\SubAdmin;
|
||||||
use OC\User\NoUserException;
|
use OC\User\NoUserException;
|
||||||
use OCA\Provisioning_API\Controller\GroupsController;
|
use OCA\Provisioning_API\Controller\GroupsController;
|
||||||
|
use OCP\Accounts\IAccountManager;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
use OCP\ILogger;
|
use OCP\ILogger;
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
|
@ -185,10 +186,10 @@ class GroupsControllerTest extends \Test\TestCase {
|
||||||
->method('getUser')
|
->method('getUser')
|
||||||
->willReturnCallback(function (IUser $user) {
|
->willReturnCallback(function (IUser $user) {
|
||||||
return [
|
return [
|
||||||
AccountManager::PROPERTY_PHONE => ['value' => '0800-call-' . $user->getUID()],
|
IAccountManager::PROPERTY_PHONE => ['value' => '0800-call-' . $user->getUID()],
|
||||||
AccountManager::PROPERTY_ADDRESS => ['value' => 'Holzweg 99, 0601 Herrera, Panama'],
|
IAccountManager::PROPERTY_ADDRESS => ['value' => 'Holzweg 99, 0601 Herrera, Panama'],
|
||||||
AccountManager::PROPERTY_WEBSITE => ['value' => 'https://' . $user->getUid() . '.pa'],
|
IAccountManager::PROPERTY_WEBSITE => ['value' => 'https://' . $user->getUid() . '.pa'],
|
||||||
AccountManager::PROPERTY_TWITTER => ['value' => '@' . $user->getUID()],
|
IAccountManager::PROPERTY_TWITTER => ['value' => '@' . $user->getUID()],
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,7 @@ use OCA\FederatedFileSharing\FederatedShareProvider;
|
||||||
use OCA\Provisioning_API\Controller\UsersController;
|
use OCA\Provisioning_API\Controller\UsersController;
|
||||||
use OCA\Provisioning_API\FederatedShareProviderFactory;
|
use OCA\Provisioning_API\FederatedShareProviderFactory;
|
||||||
use OCA\Settings\Mailer\NewUserMailHelper;
|
use OCA\Settings\Mailer\NewUserMailHelper;
|
||||||
|
use OCP\Accounts\IAccountManager;
|
||||||
use OCP\App\IAppManager;
|
use OCP\App\IAppManager;
|
||||||
use OCP\AppFramework\Http\DataResponse;
|
use OCP\AppFramework\Http\DataResponse;
|
||||||
use OCP\EventDispatcher\IEventDispatcher;
|
use OCP\EventDispatcher\IEventDispatcher;
|
||||||
|
@ -993,10 +994,10 @@ class UsersControllerTest extends TestCase {
|
||||||
->with($targetUser)
|
->with($targetUser)
|
||||||
->willReturn(
|
->willReturn(
|
||||||
[
|
[
|
||||||
AccountManager::PROPERTY_ADDRESS => ['value' => 'address'],
|
IAccountManager::PROPERTY_ADDRESS => ['value' => 'address'],
|
||||||
AccountManager::PROPERTY_PHONE => ['value' => 'phone'],
|
IAccountManager::PROPERTY_PHONE => ['value' => 'phone'],
|
||||||
AccountManager::PROPERTY_TWITTER => ['value' => 'twitter'],
|
IAccountManager::PROPERTY_TWITTER => ['value' => 'twitter'],
|
||||||
AccountManager::PROPERTY_WEBSITE => ['value' => 'website'],
|
IAccountManager::PROPERTY_WEBSITE => ['value' => 'website'],
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
$this->config
|
$this->config
|
||||||
|
@ -1162,10 +1163,10 @@ class UsersControllerTest extends TestCase {
|
||||||
->with($targetUser)
|
->with($targetUser)
|
||||||
->willReturn(
|
->willReturn(
|
||||||
[
|
[
|
||||||
AccountManager::PROPERTY_ADDRESS => ['value' => 'address'],
|
IAccountManager::PROPERTY_ADDRESS => ['value' => 'address'],
|
||||||
AccountManager::PROPERTY_PHONE => ['value' => 'phone'],
|
IAccountManager::PROPERTY_PHONE => ['value' => 'phone'],
|
||||||
AccountManager::PROPERTY_TWITTER => ['value' => 'twitter'],
|
IAccountManager::PROPERTY_TWITTER => ['value' => 'twitter'],
|
||||||
AccountManager::PROPERTY_WEBSITE => ['value' => 'website'],
|
IAccountManager::PROPERTY_WEBSITE => ['value' => 'website'],
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1333,10 +1334,10 @@ class UsersControllerTest extends TestCase {
|
||||||
->with($targetUser)
|
->with($targetUser)
|
||||||
->willReturn(
|
->willReturn(
|
||||||
[
|
[
|
||||||
AccountManager::PROPERTY_ADDRESS => ['value' => 'address'],
|
IAccountManager::PROPERTY_ADDRESS => ['value' => 'address'],
|
||||||
AccountManager::PROPERTY_PHONE => ['value' => 'phone'],
|
IAccountManager::PROPERTY_PHONE => ['value' => 'phone'],
|
||||||
AccountManager::PROPERTY_TWITTER => ['value' => 'twitter'],
|
IAccountManager::PROPERTY_TWITTER => ['value' => 'twitter'],
|
||||||
AccountManager::PROPERTY_WEBSITE => ['value' => 'website'],
|
IAccountManager::PROPERTY_WEBSITE => ['value' => 'website'],
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -3566,22 +3567,22 @@ class UsersControllerTest extends TestCase {
|
||||||
return [
|
return [
|
||||||
[false, false, []],
|
[false, false, []],
|
||||||
[false, true, [
|
[false, true, [
|
||||||
AccountManager::PROPERTY_PHONE,
|
IAccountManager::PROPERTY_PHONE,
|
||||||
AccountManager::PROPERTY_ADDRESS,
|
IAccountManager::PROPERTY_ADDRESS,
|
||||||
AccountManager::PROPERTY_WEBSITE,
|
IAccountManager::PROPERTY_WEBSITE,
|
||||||
AccountManager::PROPERTY_TWITTER,
|
IAccountManager::PROPERTY_TWITTER,
|
||||||
]],
|
]],
|
||||||
[ true, false, [
|
[ true, false, [
|
||||||
AccountManager::PROPERTY_DISPLAYNAME,
|
IAccountManager::PROPERTY_DISPLAYNAME,
|
||||||
AccountManager::PROPERTY_EMAIL,
|
IAccountManager::PROPERTY_EMAIL,
|
||||||
]],
|
]],
|
||||||
[ true, true ,[
|
[ true, true ,[
|
||||||
AccountManager::PROPERTY_DISPLAYNAME,
|
IAccountManager::PROPERTY_DISPLAYNAME,
|
||||||
AccountManager::PROPERTY_EMAIL,
|
IAccountManager::PROPERTY_EMAIL,
|
||||||
AccountManager::PROPERTY_PHONE,
|
IAccountManager::PROPERTY_PHONE,
|
||||||
AccountManager::PROPERTY_ADDRESS,
|
IAccountManager::PROPERTY_ADDRESS,
|
||||||
AccountManager::PROPERTY_WEBSITE,
|
IAccountManager::PROPERTY_WEBSITE,
|
||||||
AccountManager::PROPERTY_TWITTER,
|
IAccountManager::PROPERTY_TWITTER,
|
||||||
]]
|
]]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
namespace OCA\Settings\BackgroundJobs;
|
namespace OCA\Settings\BackgroundJobs;
|
||||||
|
|
||||||
use OC\Accounts\AccountManager;
|
use OC\Accounts\AccountManager;
|
||||||
|
use OCP\Accounts\IAccountManager;
|
||||||
use OCP\AppFramework\Http;
|
use OCP\AppFramework\Http;
|
||||||
use OCP\BackgroundJob\IJobList;
|
use OCP\BackgroundJob\IJobList;
|
||||||
use OCP\BackgroundJob\Job;
|
use OCP\BackgroundJob\Job;
|
||||||
|
@ -114,11 +115,11 @@ class VerifyUserData extends Job {
|
||||||
$try = (int)$argument['try'] + 1;
|
$try = (int)$argument['try'] + 1;
|
||||||
|
|
||||||
switch ($argument['type']) {
|
switch ($argument['type']) {
|
||||||
case AccountManager::PROPERTY_WEBSITE:
|
case IAccountManager::PROPERTY_WEBSITE:
|
||||||
$result = $this->verifyWebsite($argument);
|
$result = $this->verifyWebsite($argument);
|
||||||
break;
|
break;
|
||||||
case AccountManager::PROPERTY_TWITTER:
|
case IAccountManager::PROPERTY_TWITTER:
|
||||||
case AccountManager::PROPERTY_EMAIL:
|
case IAccountManager::PROPERTY_EMAIL:
|
||||||
$result = $this->verifyViaLookupServer($argument, $argument['type']);
|
$result = $this->verifyViaLookupServer($argument, $argument['type']);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -164,9 +165,9 @@ class VerifyUserData extends Job {
|
||||||
$userData = $this->accountManager->getUser($user);
|
$userData = $this->accountManager->getUser($user);
|
||||||
|
|
||||||
if ($publishedCodeSanitized === $argument['verificationCode']) {
|
if ($publishedCodeSanitized === $argument['verificationCode']) {
|
||||||
$userData[AccountManager::PROPERTY_WEBSITE]['verified'] = AccountManager::VERIFIED;
|
$userData[IAccountManager::PROPERTY_WEBSITE]['verified'] = AccountManager::VERIFIED;
|
||||||
} else {
|
} else {
|
||||||
$userData[AccountManager::PROPERTY_WEBSITE]['verified'] = AccountManager::NOT_VERIFIED;
|
$userData[IAccountManager::PROPERTY_WEBSITE]['verified'] = AccountManager::NOT_VERIFIED;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->accountManager->updateUser($user, $userData);
|
$this->accountManager->updateUser($user, $userData);
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
/**
|
/**
|
||||||
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
||||||
*
|
*
|
||||||
|
@ -30,7 +32,6 @@
|
||||||
|
|
||||||
// FIXME: disabled for now to be able to inject IGroupManager and also use
|
// FIXME: disabled for now to be able to inject IGroupManager and also use
|
||||||
// getSubAdmin()
|
// getSubAdmin()
|
||||||
//declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace OCA\Settings\Controller;
|
namespace OCA\Settings\Controller;
|
||||||
|
|
||||||
|
@ -46,6 +47,7 @@ use OCA\FederatedFileSharing\FederatedShareProvider;
|
||||||
use OCA\Settings\BackgroundJobs\VerifyUserData;
|
use OCA\Settings\BackgroundJobs\VerifyUserData;
|
||||||
use OCA\Settings\Events\BeforeTemplateRenderedEvent;
|
use OCA\Settings\Events\BeforeTemplateRenderedEvent;
|
||||||
use OCA\User_LDAP\User_Proxy;
|
use OCA\User_LDAP\User_Proxy;
|
||||||
|
use OCP\Accounts\IAccountManager;
|
||||||
use OCP\App\IAppManager;
|
use OCP\App\IAppManager;
|
||||||
use OCP\AppFramework\Controller;
|
use OCP\AppFramework\Controller;
|
||||||
use OCP\AppFramework\Http\DataResponse;
|
use OCP\AppFramework\Http\DataResponse;
|
||||||
|
@ -140,7 +142,7 @@ class UsersController extends Controller {
|
||||||
*
|
*
|
||||||
* @return TemplateResponse
|
* @return TemplateResponse
|
||||||
*/
|
*/
|
||||||
public function usersListByGroup() {
|
public function usersListByGroup(): TemplateResponse {
|
||||||
return $this->usersList();
|
return $this->usersList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,7 +154,7 @@ class UsersController extends Controller {
|
||||||
*
|
*
|
||||||
* @return TemplateResponse
|
* @return TemplateResponse
|
||||||
*/
|
*/
|
||||||
public function usersList() {
|
public function usersList(): TemplateResponse {
|
||||||
$user = $this->userSession->getUser();
|
$user = $this->userSession->getUser();
|
||||||
$uid = $user->getUID();
|
$uid = $user->getUID();
|
||||||
|
|
||||||
|
@ -309,7 +311,7 @@ class UsersController extends Controller {
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function canAdminChangeUserPasswords() {
|
protected function canAdminChangeUserPasswords(): bool {
|
||||||
$isEncryptionEnabled = $this->encryptionManager->isEnabled();
|
$isEncryptionEnabled = $this->encryptionManager->isEnabled();
|
||||||
try {
|
try {
|
||||||
$noUserSpecificEncryptionKeys = !$this->encryptionManager->getEncryptionModule()->needDetailedAccessList();
|
$noUserSpecificEncryptionKeys = !$this->encryptionManager->getEncryptionModule()->needDetailedAccessList();
|
||||||
|
@ -344,19 +346,19 @@ class UsersController extends Controller {
|
||||||
* @param string $twitterScope
|
* @param string $twitterScope
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
public function setUserSettings($avatarScope,
|
public function setUserSettings(string $avatarScope,
|
||||||
$displayname,
|
string $displayname,
|
||||||
$displaynameScope,
|
string $displaynameScope,
|
||||||
$phone,
|
string $phone,
|
||||||
$phoneScope,
|
string $phoneScope,
|
||||||
$email,
|
string $email,
|
||||||
$emailScope,
|
string $emailScope,
|
||||||
$website,
|
string $website,
|
||||||
$websiteScope,
|
string $websiteScope,
|
||||||
$address,
|
string $address,
|
||||||
$addressScope,
|
string $addressScope,
|
||||||
$twitter,
|
string $twitter,
|
||||||
$twitterScope
|
string $twitterScope
|
||||||
) {
|
) {
|
||||||
$email = strtolower($email);
|
$email = strtolower($email);
|
||||||
if (!empty($email) && !$this->mailer->validateMailAddress($email)) {
|
if (!empty($email) && !$this->mailer->validateMailAddress($email)) {
|
||||||
|
@ -372,18 +374,18 @@ class UsersController extends Controller {
|
||||||
}
|
}
|
||||||
$user = $this->userSession->getUser();
|
$user = $this->userSession->getUser();
|
||||||
$data = $this->accountManager->getUser($user);
|
$data = $this->accountManager->getUser($user);
|
||||||
$data[AccountManager::PROPERTY_AVATAR] = ['scope' => $avatarScope];
|
$data[IAccountManager::PROPERTY_AVATAR] = ['scope' => $avatarScope];
|
||||||
if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) {
|
if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) {
|
||||||
$data[AccountManager::PROPERTY_DISPLAYNAME] = ['value' => $displayname, 'scope' => $displaynameScope];
|
$data[IAccountManager::PROPERTY_DISPLAYNAME] = ['value' => $displayname, 'scope' => $displaynameScope];
|
||||||
$data[AccountManager::PROPERTY_EMAIL] = ['value' => $email, 'scope' => $emailScope];
|
$data[IAccountManager::PROPERTY_EMAIL] = ['value' => $email, 'scope' => $emailScope];
|
||||||
}
|
}
|
||||||
if ($this->appManager->isEnabledForUser('federatedfilesharing')) {
|
if ($this->appManager->isEnabledForUser('federatedfilesharing')) {
|
||||||
$shareProvider = \OC::$server->query(FederatedShareProvider::class);
|
$shareProvider = \OC::$server->query(FederatedShareProvider::class);
|
||||||
if ($shareProvider->isLookupServerUploadEnabled()) {
|
if ($shareProvider->isLookupServerUploadEnabled()) {
|
||||||
$data[AccountManager::PROPERTY_WEBSITE] = ['value' => $website, 'scope' => $websiteScope];
|
$data[IAccountManager::PROPERTY_WEBSITE] = ['value' => $website, 'scope' => $websiteScope];
|
||||||
$data[AccountManager::PROPERTY_ADDRESS] = ['value' => $address, 'scope' => $addressScope];
|
$data[IAccountManager::PROPERTY_ADDRESS] = ['value' => $address, 'scope' => $addressScope];
|
||||||
$data[AccountManager::PROPERTY_PHONE] = ['value' => $phone, 'scope' => $phoneScope];
|
$data[IAccountManager::PROPERTY_PHONE] = ['value' => $phone, 'scope' => $phoneScope];
|
||||||
$data[AccountManager::PROPERTY_TWITTER] = ['value' => $twitter, 'scope' => $twitterScope];
|
$data[IAccountManager::PROPERTY_TWITTER] = ['value' => $twitter, 'scope' => $twitterScope];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
@ -393,15 +395,15 @@ class UsersController extends Controller {
|
||||||
'status' => 'success',
|
'status' => 'success',
|
||||||
'data' => [
|
'data' => [
|
||||||
'userId' => $user->getUID(),
|
'userId' => $user->getUID(),
|
||||||
'avatarScope' => $data[AccountManager::PROPERTY_AVATAR]['scope'],
|
'avatarScope' => $data[IAccountManager::PROPERTY_AVATAR]['scope'],
|
||||||
'displayname' => $data[AccountManager::PROPERTY_DISPLAYNAME]['value'],
|
'displayname' => $data[IAccountManager::PROPERTY_DISPLAYNAME]['value'],
|
||||||
'displaynameScope' => $data[AccountManager::PROPERTY_DISPLAYNAME]['scope'],
|
'displaynameScope' => $data[IAccountManager::PROPERTY_DISPLAYNAME]['scope'],
|
||||||
'email' => $data[AccountManager::PROPERTY_EMAIL]['value'],
|
'email' => $data[IAccountManager::PROPERTY_EMAIL]['value'],
|
||||||
'emailScope' => $data[AccountManager::PROPERTY_EMAIL]['scope'],
|
'emailScope' => $data[IAccountManager::PROPERTY_EMAIL]['scope'],
|
||||||
'website' => $data[AccountManager::PROPERTY_WEBSITE]['value'],
|
'website' => $data[IAccountManager::PROPERTY_WEBSITE]['value'],
|
||||||
'websiteScope' => $data[AccountManager::PROPERTY_WEBSITE]['scope'],
|
'websiteScope' => $data[IAccountManager::PROPERTY_WEBSITE]['scope'],
|
||||||
'address' => $data[AccountManager::PROPERTY_ADDRESS]['value'],
|
'address' => $data[IAccountManager::PROPERTY_ADDRESS]['value'],
|
||||||
'addressScope' => $data[AccountManager::PROPERTY_ADDRESS]['scope'],
|
'addressScope' => $data[IAccountManager::PROPERTY_ADDRESS]['scope'],
|
||||||
'message' => $this->l10n->t('Settings saved')
|
'message' => $this->l10n->t('Settings saved')
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
@ -423,30 +425,30 @@ class UsersController extends Controller {
|
||||||
* @param array $data
|
* @param array $data
|
||||||
* @throws ForbiddenException
|
* @throws ForbiddenException
|
||||||
*/
|
*/
|
||||||
protected function saveUserSettings(IUser $user, array $data) {
|
protected function saveUserSettings(IUser $user, array $data): void {
|
||||||
// keep the user back-end up-to-date with the latest display name and email
|
// keep the user back-end up-to-date with the latest display name and email
|
||||||
// address
|
// address
|
||||||
$oldDisplayName = $user->getDisplayName();
|
$oldDisplayName = $user->getDisplayName();
|
||||||
$oldDisplayName = is_null($oldDisplayName) ? '' : $oldDisplayName;
|
$oldDisplayName = is_null($oldDisplayName) ? '' : $oldDisplayName;
|
||||||
if (isset($data[AccountManager::PROPERTY_DISPLAYNAME]['value'])
|
if (isset($data[IAccountManager::PROPERTY_DISPLAYNAME]['value'])
|
||||||
&& $oldDisplayName !== $data[AccountManager::PROPERTY_DISPLAYNAME]['value']
|
&& $oldDisplayName !== $data[IAccountManager::PROPERTY_DISPLAYNAME]['value']
|
||||||
) {
|
) {
|
||||||
$result = $user->setDisplayName($data[AccountManager::PROPERTY_DISPLAYNAME]['value']);
|
$result = $user->setDisplayName($data[IAccountManager::PROPERTY_DISPLAYNAME]['value']);
|
||||||
if ($result === false) {
|
if ($result === false) {
|
||||||
throw new ForbiddenException($this->l10n->t('Unable to change full name'));
|
throw new ForbiddenException($this->l10n->t('Unable to change full name'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$oldEmailAddress = $user->getEMailAddress();
|
$oldEmailAddress = $user->getEMailAddress();
|
||||||
$oldEmailAddress = is_null($oldEmailAddress) ? '' : strtolower($oldEmailAddress);
|
$oldEmailAddress = is_null($oldEmailAddress) ? '' : strtolower($oldEmailAddress);
|
||||||
if (isset($data[AccountManager::PROPERTY_EMAIL]['value'])
|
if (isset($data[IAccountManager::PROPERTY_EMAIL]['value'])
|
||||||
&& $oldEmailAddress !== $data[AccountManager::PROPERTY_EMAIL]['value']
|
&& $oldEmailAddress !== $data[IAccountManager::PROPERTY_EMAIL]['value']
|
||||||
) {
|
) {
|
||||||
// this is the only permission a backend provides and is also used
|
// this is the only permission a backend provides and is also used
|
||||||
// for the permission of setting a email address
|
// for the permission of setting a email address
|
||||||
if (!$user->canChangeDisplayName()) {
|
if (!$user->canChangeDisplayName()) {
|
||||||
throw new ForbiddenException($this->l10n->t('Unable to change email address'));
|
throw new ForbiddenException($this->l10n->t('Unable to change email address'));
|
||||||
}
|
}
|
||||||
$user->setEMailAddress($data[AccountManager::PROPERTY_EMAIL]['value']);
|
$user->setEMailAddress($data[IAccountManager::PROPERTY_EMAIL]['value']);
|
||||||
}
|
}
|
||||||
$this->accountManager->updateUser($user, $data);
|
$this->accountManager->updateUser($user, $data);
|
||||||
}
|
}
|
||||||
|
@ -479,19 +481,19 @@ class UsersController extends Controller {
|
||||||
|
|
||||||
switch ($account) {
|
switch ($account) {
|
||||||
case 'verify-twitter':
|
case 'verify-twitter':
|
||||||
$accountData[AccountManager::PROPERTY_TWITTER]['verified'] = AccountManager::VERIFICATION_IN_PROGRESS;
|
$accountData[IAccountManager::PROPERTY_TWITTER]['verified'] = AccountManager::VERIFICATION_IN_PROGRESS;
|
||||||
$msg = $this->l10n->t('In order to verify your Twitter account, post the following tweet on Twitter (please make sure to post it without any line breaks):');
|
$msg = $this->l10n->t('In order to verify your Twitter account, post the following tweet on Twitter (please make sure to post it without any line breaks):');
|
||||||
$code = $codeMd5;
|
$code = $codeMd5;
|
||||||
$type = AccountManager::PROPERTY_TWITTER;
|
$type = IAccountManager::PROPERTY_TWITTER;
|
||||||
$data = $accountData[AccountManager::PROPERTY_TWITTER]['value'];
|
$data = $accountData[IAccountManager::PROPERTY_TWITTER]['value'];
|
||||||
$accountData[AccountManager::PROPERTY_TWITTER]['signature'] = $signature;
|
$accountData[IAccountManager::PROPERTY_TWITTER]['signature'] = $signature;
|
||||||
break;
|
break;
|
||||||
case 'verify-website':
|
case 'verify-website':
|
||||||
$accountData[AccountManager::PROPERTY_WEBSITE]['verified'] = AccountManager::VERIFICATION_IN_PROGRESS;
|
$accountData[IAccountManager::PROPERTY_WEBSITE]['verified'] = AccountManager::VERIFICATION_IN_PROGRESS;
|
||||||
$msg = $this->l10n->t('In order to verify your Website, store the following content in your web-root at \'.well-known/CloudIdVerificationCode.txt\' (please make sure that the complete text is in one line):');
|
$msg = $this->l10n->t('In order to verify your Website, store the following content in your web-root at \'.well-known/CloudIdVerificationCode.txt\' (please make sure that the complete text is in one line):');
|
||||||
$type = AccountManager::PROPERTY_WEBSITE;
|
$type = IAccountManager::PROPERTY_WEBSITE;
|
||||||
$data = $accountData[AccountManager::PROPERTY_WEBSITE]['value'];
|
$data = $accountData[IAccountManager::PROPERTY_WEBSITE]['value'];
|
||||||
$accountData[AccountManager::PROPERTY_WEBSITE]['signature'] = $signature;
|
$accountData[IAccountManager::PROPERTY_WEBSITE]['signature'] = $signature;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return new DataResponse([], Http::STATUS_BAD_REQUEST);
|
return new DataResponse([], Http::STATUS_BAD_REQUEST);
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
/**
|
/**
|
||||||
* @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
|
* @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
|
||||||
*
|
*
|
||||||
|
@ -33,6 +35,7 @@ namespace OCA\Settings\Settings\Personal;
|
||||||
|
|
||||||
use OC\Accounts\AccountManager;
|
use OC\Accounts\AccountManager;
|
||||||
use OCA\FederatedFileSharing\FederatedShareProvider;
|
use OCA\FederatedFileSharing\FederatedShareProvider;
|
||||||
|
use OCP\Accounts\IAccountManager;
|
||||||
use OCP\App\IAppManager;
|
use OCP\App\IAppManager;
|
||||||
use OCP\AppFramework\Http\TemplateResponse;
|
use OCP\AppFramework\Http\TemplateResponse;
|
||||||
use OCP\Files\FileInfo;
|
use OCP\Files\FileInfo;
|
||||||
|
@ -62,14 +65,6 @@ class PersonalInfo implements ISettings {
|
||||||
/** @var IL10N */
|
/** @var IL10N */
|
||||||
private $l;
|
private $l;
|
||||||
|
|
||||||
/**
|
|
||||||
* @param IConfig $config
|
|
||||||
* @param IUserManager $userManager
|
|
||||||
* @param IGroupManager $groupManager
|
|
||||||
* @param AccountManager $accountManager
|
|
||||||
* @param IFactory $l10nFactory
|
|
||||||
* @param IL10N $l
|
|
||||||
*/
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
IConfig $config,
|
IConfig $config,
|
||||||
IUserManager $userManager,
|
IUserManager $userManager,
|
||||||
|
@ -88,11 +83,7 @@ class PersonalInfo implements ISettings {
|
||||||
$this->l = $l;
|
$this->l = $l;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getForm(): TemplateResponse {
|
||||||
* @return TemplateResponse returns the instance with all parameters set, ready to be rendered
|
|
||||||
* @since 9.1
|
|
||||||
*/
|
|
||||||
public function getForm() {
|
|
||||||
$federatedFileSharingEnabled = $this->appManager->isEnabledForUser('federatedfilesharing');
|
$federatedFileSharingEnabled = $this->appManager->isEnabledForUser('federatedfilesharing');
|
||||||
$lookupServerUploadEnabled = false;
|
$lookupServerUploadEnabled = false;
|
||||||
if ($federatedFileSharingEnabled) {
|
if ($federatedFileSharingEnabled) {
|
||||||
|
@ -126,23 +117,23 @@ class PersonalInfo implements ISettings {
|
||||||
'quota' => $storageInfo['quota'],
|
'quota' => $storageInfo['quota'],
|
||||||
'avatarChangeSupported' => $user->canChangeAvatar(),
|
'avatarChangeSupported' => $user->canChangeAvatar(),
|
||||||
'lookupServerUploadEnabled' => $lookupServerUploadEnabled,
|
'lookupServerUploadEnabled' => $lookupServerUploadEnabled,
|
||||||
'avatarScope' => $userData[AccountManager::PROPERTY_AVATAR]['scope'],
|
'avatarScope' => $userData[IAccountManager::PROPERTY_AVATAR]['scope'],
|
||||||
'displayNameChangeSupported' => $user->canChangeDisplayName(),
|
'displayNameChangeSupported' => $user->canChangeDisplayName(),
|
||||||
'displayName' => $userData[AccountManager::PROPERTY_DISPLAYNAME]['value'],
|
'displayName' => $userData[IAccountManager::PROPERTY_DISPLAYNAME]['value'],
|
||||||
'displayNameScope' => $userData[AccountManager::PROPERTY_DISPLAYNAME]['scope'],
|
'displayNameScope' => $userData[IAccountManager::PROPERTY_DISPLAYNAME]['scope'],
|
||||||
'email' => $userData[AccountManager::PROPERTY_EMAIL]['value'],
|
'email' => $userData[IAccountManager::PROPERTY_EMAIL]['value'],
|
||||||
'emailScope' => $userData[AccountManager::PROPERTY_EMAIL]['scope'],
|
'emailScope' => $userData[IAccountManager::PROPERTY_EMAIL]['scope'],
|
||||||
'emailVerification' => $userData[AccountManager::PROPERTY_EMAIL]['verified'],
|
'emailVerification' => $userData[IAccountManager::PROPERTY_EMAIL]['verified'],
|
||||||
'phone' => $userData[AccountManager::PROPERTY_PHONE]['value'],
|
'phone' => $userData[IAccountManager::PROPERTY_PHONE]['value'],
|
||||||
'phoneScope' => $userData[AccountManager::PROPERTY_PHONE]['scope'],
|
'phoneScope' => $userData[IAccountManager::PROPERTY_PHONE]['scope'],
|
||||||
'address' => $userData[AccountManager::PROPERTY_ADDRESS]['value'],
|
'address' => $userData[IAccountManager::PROPERTY_ADDRESS]['value'],
|
||||||
'addressScope' => $userData[AccountManager::PROPERTY_ADDRESS]['scope'],
|
'addressScope' => $userData[IAccountManager::PROPERTY_ADDRESS]['scope'],
|
||||||
'website' => $userData[AccountManager::PROPERTY_WEBSITE]['value'],
|
'website' => $userData[IAccountManager::PROPERTY_WEBSITE]['value'],
|
||||||
'websiteScope' => $userData[AccountManager::PROPERTY_WEBSITE]['scope'],
|
'websiteScope' => $userData[IAccountManager::PROPERTY_WEBSITE]['scope'],
|
||||||
'websiteVerification' => $userData[AccountManager::PROPERTY_WEBSITE]['verified'],
|
'websiteVerification' => $userData[IAccountManager::PROPERTY_WEBSITE]['verified'],
|
||||||
'twitter' => $userData[AccountManager::PROPERTY_TWITTER]['value'],
|
'twitter' => $userData[IAccountManager::PROPERTY_TWITTER]['value'],
|
||||||
'twitterScope' => $userData[AccountManager::PROPERTY_TWITTER]['scope'],
|
'twitterScope' => $userData[IAccountManager::PROPERTY_TWITTER]['scope'],
|
||||||
'twitterVerification' => $userData[AccountManager::PROPERTY_TWITTER]['verified'],
|
'twitterVerification' => $userData[IAccountManager::PROPERTY_TWITTER]['verified'],
|
||||||
'groups' => $this->getGroups($user),
|
'groups' => $this->getGroups($user),
|
||||||
] + $messageParameters + $languageParameters + $localeParameters;
|
] + $messageParameters + $languageParameters + $localeParameters;
|
||||||
|
|
||||||
|
@ -154,7 +145,7 @@ class PersonalInfo implements ISettings {
|
||||||
* @return string the section ID, e.g. 'sharing'
|
* @return string the section ID, e.g. 'sharing'
|
||||||
* @since 9.1
|
* @since 9.1
|
||||||
*/
|
*/
|
||||||
public function getSection() {
|
public function getSection(): string {
|
||||||
return 'personal-info';
|
return 'personal-info';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,7 +157,7 @@ class PersonalInfo implements ISettings {
|
||||||
* E.g.: 70
|
* E.g.: 70
|
||||||
* @since 9.1
|
* @since 9.1
|
||||||
*/
|
*/
|
||||||
public function getPriority() {
|
public function getPriority(): int {
|
||||||
return 10;
|
return 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,9 +167,9 @@ class PersonalInfo implements ISettings {
|
||||||
* @param IUser $user
|
* @param IUser $user
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function getGroups(IUser $user) {
|
private function getGroups(IUser $user): array {
|
||||||
$groups = array_map(
|
$groups = array_map(
|
||||||
function (IGroup $group) {
|
static function (IGroup $group) {
|
||||||
return $group->getDisplayName();
|
return $group->getDisplayName();
|
||||||
},
|
},
|
||||||
$this->groupManager->getUserGroups($user)
|
$this->groupManager->getUserGroups($user)
|
||||||
|
@ -195,7 +186,7 @@ class PersonalInfo implements ISettings {
|
||||||
* @param IUser $user
|
* @param IUser $user
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function getLanguages(IUser $user) {
|
private function getLanguages(IUser $user): array {
|
||||||
$forceLanguage = $this->config->getSystemValue('force_language', false);
|
$forceLanguage = $this->config->getSystemValue('force_language', false);
|
||||||
if ($forceLanguage !== false) {
|
if ($forceLanguage !== false) {
|
||||||
return [];
|
return [];
|
||||||
|
@ -228,7 +219,7 @@ class PersonalInfo implements ISettings {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getLocales(IUser $user) {
|
private function getLocales(IUser $user): array {
|
||||||
$forceLanguage = $this->config->getSystemValue('force_locale', false);
|
$forceLanguage = $this->config->getSystemValue('force_locale', false);
|
||||||
if ($forceLanguage !== false) {
|
if ($forceLanguage !== false) {
|
||||||
return [];
|
return [];
|
||||||
|
@ -273,8 +264,8 @@ class PersonalInfo implements ISettings {
|
||||||
* @param array $userData
|
* @param array $userData
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function getMessageParameters(array $userData) {
|
private function getMessageParameters(array $userData): array {
|
||||||
$needVerifyMessage = [AccountManager::PROPERTY_EMAIL, AccountManager::PROPERTY_WEBSITE, AccountManager::PROPERTY_TWITTER];
|
$needVerifyMessage = [IAccountManager::PROPERTY_EMAIL, IAccountManager::PROPERTY_WEBSITE, IAccountManager::PROPERTY_TWITTER];
|
||||||
$messageParameters = [];
|
$messageParameters = [];
|
||||||
foreach ($needVerifyMessage as $property) {
|
foreach ($needVerifyMessage as $property) {
|
||||||
switch ($userData[$property]['verified']) {
|
switch ($userData[$property]['verified']) {
|
||||||
|
|
|
@ -31,6 +31,7 @@ use OC\Accounts\AccountManager;
|
||||||
use OC\Encryption\Exceptions\ModuleDoesNotExistsException;
|
use OC\Encryption\Exceptions\ModuleDoesNotExistsException;
|
||||||
use OC\Group\Manager;
|
use OC\Group\Manager;
|
||||||
use OCA\Settings\Controller\UsersController;
|
use OCA\Settings\Controller\UsersController;
|
||||||
|
use OCP\Accounts\IAccountManager;
|
||||||
use OCP\App\IAppManager;
|
use OCP\App\IAppManager;
|
||||||
use OCP\AppFramework\Http;
|
use OCP\AppFramework\Http;
|
||||||
use OCP\BackgroundJob\IJobList;
|
use OCP\BackgroundJob\IJobList;
|
||||||
|
@ -196,41 +197,41 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
->method('getUser')
|
->method('getUser')
|
||||||
->with($user)
|
->with($user)
|
||||||
->willReturn([
|
->willReturn([
|
||||||
AccountManager::PROPERTY_DISPLAYNAME =>
|
IAccountManager::PROPERTY_DISPLAYNAME =>
|
||||||
[
|
[
|
||||||
'value' => 'Display name',
|
'value' => 'Display name',
|
||||||
'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY,
|
'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY,
|
||||||
'verified' => AccountManager::NOT_VERIFIED,
|
'verified' => AccountManager::NOT_VERIFIED,
|
||||||
],
|
],
|
||||||
AccountManager::PROPERTY_ADDRESS =>
|
IAccountManager::PROPERTY_ADDRESS =>
|
||||||
[
|
[
|
||||||
'value' => '',
|
'value' => '',
|
||||||
'scope' => AccountManager::VISIBILITY_PRIVATE,
|
'scope' => AccountManager::VISIBILITY_PRIVATE,
|
||||||
'verified' => AccountManager::NOT_VERIFIED,
|
'verified' => AccountManager::NOT_VERIFIED,
|
||||||
],
|
],
|
||||||
AccountManager::PROPERTY_WEBSITE =>
|
IAccountManager::PROPERTY_WEBSITE =>
|
||||||
[
|
[
|
||||||
'value' => '',
|
'value' => '',
|
||||||
'scope' => AccountManager::VISIBILITY_PRIVATE,
|
'scope' => AccountManager::VISIBILITY_PRIVATE,
|
||||||
'verified' => AccountManager::NOT_VERIFIED,
|
'verified' => AccountManager::NOT_VERIFIED,
|
||||||
],
|
],
|
||||||
AccountManager::PROPERTY_EMAIL =>
|
IAccountManager::PROPERTY_EMAIL =>
|
||||||
[
|
[
|
||||||
'value' => '',
|
'value' => '',
|
||||||
'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY,
|
'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY,
|
||||||
'verified' => AccountManager::NOT_VERIFIED,
|
'verified' => AccountManager::NOT_VERIFIED,
|
||||||
],
|
],
|
||||||
AccountManager::PROPERTY_AVATAR =>
|
IAccountManager::PROPERTY_AVATAR =>
|
||||||
[
|
[
|
||||||
'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY
|
'scope' => AccountManager::VISIBILITY_CONTACTS_ONLY
|
||||||
],
|
],
|
||||||
AccountManager::PROPERTY_PHONE =>
|
IAccountManager::PROPERTY_PHONE =>
|
||||||
[
|
[
|
||||||
'value' => '',
|
'value' => '',
|
||||||
'scope' => AccountManager::VISIBILITY_PRIVATE,
|
'scope' => AccountManager::VISIBILITY_PRIVATE,
|
||||||
'verified' => AccountManager::NOT_VERIFIED,
|
'verified' => AccountManager::NOT_VERIFIED,
|
||||||
],
|
],
|
||||||
AccountManager::PROPERTY_TWITTER =>
|
IAccountManager::PROPERTY_TWITTER =>
|
||||||
[
|
[
|
||||||
'value' => '',
|
'value' => '',
|
||||||
'scope' => AccountManager::VISIBILITY_PRIVATE,
|
'scope' => AccountManager::VISIBILITY_PRIVATE,
|
||||||
|
@ -289,21 +290,21 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
$user->method('getEMailAddress')->willReturn($oldEmailAddress);
|
$user->method('getEMailAddress')->willReturn($oldEmailAddress);
|
||||||
$user->method('canChangeDisplayName')->willReturn(true);
|
$user->method('canChangeDisplayName')->willReturn(true);
|
||||||
|
|
||||||
if ($data[AccountManager::PROPERTY_EMAIL]['value'] === $oldEmailAddress ||
|
if ($data[IAccountManager::PROPERTY_EMAIL]['value'] === $oldEmailAddress ||
|
||||||
($oldEmailAddress === null && $data[AccountManager::PROPERTY_EMAIL]['value'] === '')) {
|
($oldEmailAddress === null && $data[IAccountManager::PROPERTY_EMAIL]['value'] === '')) {
|
||||||
$user->expects($this->never())->method('setEMailAddress');
|
$user->expects($this->never())->method('setEMailAddress');
|
||||||
} else {
|
} else {
|
||||||
$user->expects($this->once())->method('setEMailAddress')
|
$user->expects($this->once())->method('setEMailAddress')
|
||||||
->with($data[AccountManager::PROPERTY_EMAIL]['value'])
|
->with($data[IAccountManager::PROPERTY_EMAIL]['value'])
|
||||||
->willReturn(true);
|
->willReturn(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($data[AccountManager::PROPERTY_DISPLAYNAME]['value'] === $oldDisplayName ||
|
if ($data[IAccountManager::PROPERTY_DISPLAYNAME]['value'] === $oldDisplayName ||
|
||||||
($oldDisplayName === null && $data[AccountManager::PROPERTY_DISPLAYNAME]['value'] === '')) {
|
($oldDisplayName === null && $data[IAccountManager::PROPERTY_DISPLAYNAME]['value'] === '')) {
|
||||||
$user->expects($this->never())->method('setDisplayName');
|
$user->expects($this->never())->method('setDisplayName');
|
||||||
} else {
|
} else {
|
||||||
$user->expects($this->once())->method('setDisplayName')
|
$user->expects($this->once())->method('setDisplayName')
|
||||||
->with($data[AccountManager::PROPERTY_DISPLAYNAME]['value'])
|
->with($data[IAccountManager::PROPERTY_DISPLAYNAME]['value'])
|
||||||
->willReturn(true);
|
->willReturn(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,48 +318,48 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
return [
|
return [
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
AccountManager::PROPERTY_EMAIL => ['value' => 'john@example.com'],
|
IAccountManager::PROPERTY_EMAIL => ['value' => 'john@example.com'],
|
||||||
AccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'],
|
IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'],
|
||||||
],
|
],
|
||||||
'john@example.com',
|
'john@example.com',
|
||||||
'john doe'
|
'john doe'
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
AccountManager::PROPERTY_EMAIL => ['value' => 'john@example.com'],
|
IAccountManager::PROPERTY_EMAIL => ['value' => 'john@example.com'],
|
||||||
AccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'],
|
IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'],
|
||||||
],
|
],
|
||||||
'johnNew@example.com',
|
'johnNew@example.com',
|
||||||
'john New doe'
|
'john New doe'
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
AccountManager::PROPERTY_EMAIL => ['value' => 'john@example.com'],
|
IAccountManager::PROPERTY_EMAIL => ['value' => 'john@example.com'],
|
||||||
AccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'],
|
IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'],
|
||||||
],
|
],
|
||||||
'johnNew@example.com',
|
'johnNew@example.com',
|
||||||
'john doe'
|
'john doe'
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
AccountManager::PROPERTY_EMAIL => ['value' => 'john@example.com'],
|
IAccountManager::PROPERTY_EMAIL => ['value' => 'john@example.com'],
|
||||||
AccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'],
|
IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'],
|
||||||
],
|
],
|
||||||
'john@example.com',
|
'john@example.com',
|
||||||
'john New doe'
|
'john New doe'
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
AccountManager::PROPERTY_EMAIL => ['value' => ''],
|
IAccountManager::PROPERTY_EMAIL => ['value' => ''],
|
||||||
AccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'],
|
IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'],
|
||||||
],
|
],
|
||||||
null,
|
null,
|
||||||
'john New doe'
|
'john New doe'
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
AccountManager::PROPERTY_EMAIL => ['value' => 'john@example.com'],
|
IAccountManager::PROPERTY_EMAIL => ['value' => 'john@example.com'],
|
||||||
AccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'],
|
IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'],
|
||||||
],
|
],
|
||||||
'john@example.com',
|
'john@example.com',
|
||||||
null
|
null
|
||||||
|
@ -391,14 +392,14 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
$user->method('getDisplayName')->willReturn($oldDisplayName);
|
$user->method('getDisplayName')->willReturn($oldDisplayName);
|
||||||
$user->method('getEMailAddress')->willReturn($oldEmailAddress);
|
$user->method('getEMailAddress')->willReturn($oldEmailAddress);
|
||||||
|
|
||||||
if ($data[AccountManager::PROPERTY_EMAIL]['value'] !== $oldEmailAddress) {
|
if ($data[IAccountManager::PROPERTY_EMAIL]['value'] !== $oldEmailAddress) {
|
||||||
$user->method('canChangeDisplayName')
|
$user->method('canChangeDisplayName')
|
||||||
->willReturn($canChangeEmail);
|
->willReturn($canChangeEmail);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($data[AccountManager::PROPERTY_DISPLAYNAME]['value'] !== $oldDisplayName) {
|
if ($data[IAccountManager::PROPERTY_DISPLAYNAME]['value'] !== $oldDisplayName) {
|
||||||
$user->method('setDisplayName')
|
$user->method('setDisplayName')
|
||||||
->with($data[AccountManager::PROPERTY_DISPLAYNAME]['value'])
|
->with($data[IAccountManager::PROPERTY_DISPLAYNAME]['value'])
|
||||||
->willReturn($setDisplayNameResult);
|
->willReturn($setDisplayNameResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -410,8 +411,8 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
return [
|
return [
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
AccountManager::PROPERTY_EMAIL => ['value' => 'john@example.com'],
|
IAccountManager::PROPERTY_EMAIL => ['value' => 'john@example.com'],
|
||||||
AccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'],
|
IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'],
|
||||||
],
|
],
|
||||||
'johnNew@example.com',
|
'johnNew@example.com',
|
||||||
'john New doe',
|
'john New doe',
|
||||||
|
@ -420,8 +421,8 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
AccountManager::PROPERTY_EMAIL => ['value' => 'john@example.com'],
|
IAccountManager::PROPERTY_EMAIL => ['value' => 'john@example.com'],
|
||||||
AccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'],
|
IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'],
|
||||||
],
|
],
|
||||||
'johnNew@example.com',
|
'johnNew@example.com',
|
||||||
'john New doe',
|
'john New doe',
|
||||||
|
@ -430,8 +431,8 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
[
|
[
|
||||||
AccountManager::PROPERTY_EMAIL => ['value' => 'john@example.com'],
|
IAccountManager::PROPERTY_EMAIL => ['value' => 'john@example.com'],
|
||||||
AccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'],
|
IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'john doe'],
|
||||||
],
|
],
|
||||||
'johnNew@example.com',
|
'johnNew@example.com',
|
||||||
'john New doe',
|
'john New doe',
|
||||||
|
@ -455,7 +456,7 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
$signature = 'theSignature';
|
$signature = 'theSignature';
|
||||||
|
|
||||||
$code = $message . ' ' . $signature;
|
$code = $message . ' ' . $signature;
|
||||||
if ($type === AccountManager::PROPERTY_TWITTER) {
|
if ($type === IAccountManager::PROPERTY_TWITTER) {
|
||||||
$code = $message . ' ' . md5($signature);
|
$code = $message . ' ' . md5($signature);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -492,25 +493,25 @@ class UsersControllerTest extends \Test\TestCase {
|
||||||
|
|
||||||
public function dataTestGetVerificationCode() {
|
public function dataTestGetVerificationCode() {
|
||||||
$accountDataBefore = [
|
$accountDataBefore = [
|
||||||
AccountManager::PROPERTY_WEBSITE => ['value' => 'https://nextcloud.com', 'verified' => AccountManager::NOT_VERIFIED],
|
IAccountManager::PROPERTY_WEBSITE => ['value' => 'https://nextcloud.com', 'verified' => AccountManager::NOT_VERIFIED],
|
||||||
AccountManager::PROPERTY_TWITTER => ['value' => '@nextclouders', 'verified' => AccountManager::NOT_VERIFIED, 'signature' => 'theSignature'],
|
IAccountManager::PROPERTY_TWITTER => ['value' => '@nextclouders', 'verified' => AccountManager::NOT_VERIFIED, 'signature' => 'theSignature'],
|
||||||
];
|
];
|
||||||
|
|
||||||
$accountDataAfterWebsite = [
|
$accountDataAfterWebsite = [
|
||||||
AccountManager::PROPERTY_WEBSITE => ['value' => 'https://nextcloud.com', 'verified' => AccountManager::VERIFICATION_IN_PROGRESS, 'signature' => 'theSignature'],
|
IAccountManager::PROPERTY_WEBSITE => ['value' => 'https://nextcloud.com', 'verified' => AccountManager::VERIFICATION_IN_PROGRESS, 'signature' => 'theSignature'],
|
||||||
AccountManager::PROPERTY_TWITTER => ['value' => '@nextclouders', 'verified' => AccountManager::NOT_VERIFIED, 'signature' => 'theSignature'],
|
IAccountManager::PROPERTY_TWITTER => ['value' => '@nextclouders', 'verified' => AccountManager::NOT_VERIFIED, 'signature' => 'theSignature'],
|
||||||
];
|
];
|
||||||
|
|
||||||
$accountDataAfterTwitter = [
|
$accountDataAfterTwitter = [
|
||||||
AccountManager::PROPERTY_WEBSITE => ['value' => 'https://nextcloud.com', 'verified' => AccountManager::NOT_VERIFIED],
|
IAccountManager::PROPERTY_WEBSITE => ['value' => 'https://nextcloud.com', 'verified' => AccountManager::NOT_VERIFIED],
|
||||||
AccountManager::PROPERTY_TWITTER => ['value' => '@nextclouders', 'verified' => AccountManager::VERIFICATION_IN_PROGRESS, 'signature' => 'theSignature'],
|
IAccountManager::PROPERTY_TWITTER => ['value' => '@nextclouders', 'verified' => AccountManager::VERIFICATION_IN_PROGRESS, 'signature' => 'theSignature'],
|
||||||
];
|
];
|
||||||
|
|
||||||
return [
|
return [
|
||||||
['verify-twitter', AccountManager::PROPERTY_TWITTER, $accountDataBefore, $accountDataAfterTwitter, false],
|
['verify-twitter', IAccountManager::PROPERTY_TWITTER, $accountDataBefore, $accountDataAfterTwitter, false],
|
||||||
['verify-website', AccountManager::PROPERTY_WEBSITE, $accountDataBefore, $accountDataAfterWebsite, false],
|
['verify-website', IAccountManager::PROPERTY_WEBSITE, $accountDataBefore, $accountDataAfterWebsite, false],
|
||||||
['verify-twitter', AccountManager::PROPERTY_TWITTER, $accountDataBefore, $accountDataAfterTwitter, true],
|
['verify-twitter', IAccountManager::PROPERTY_TWITTER, $accountDataBefore, $accountDataAfterTwitter, true],
|
||||||
['verify-website', AccountManager::PROPERTY_WEBSITE, $accountDataBefore, $accountDataAfterWebsite, true],
|
['verify-website', IAccountManager::PROPERTY_WEBSITE, $accountDataBefore, $accountDataAfterWebsite, true],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -173,7 +173,7 @@ class AccountManager implements IAccountManager {
|
||||||
'lastRun' => time()
|
'lastRun' => time()
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
$newData[AccountManager::PROPERTY_EMAIL]['verified'] = AccountManager::VERIFICATION_IN_PROGRESS;
|
$newData[self::PROPERTY_EMAIL]['verified'] = self::VERIFICATION_IN_PROGRESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $newData;
|
return $newData;
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
namespace OC\Accounts;
|
namespace OC\Accounts;
|
||||||
|
|
||||||
|
use OCP\Accounts\IAccountManager;
|
||||||
use OCP\IUser;
|
use OCP\IUser;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
|
@ -61,14 +62,14 @@ class Hooks {
|
||||||
|
|
||||||
switch ($feature) {
|
switch ($feature) {
|
||||||
case 'eMailAddress':
|
case 'eMailAddress':
|
||||||
if ($accountData[AccountManager::PROPERTY_EMAIL]['value'] !== $newValue) {
|
if ($accountData[IAccountManager::PROPERTY_EMAIL]['value'] !== $newValue) {
|
||||||
$accountData[AccountManager::PROPERTY_EMAIL]['value'] = $newValue;
|
$accountData[IAccountManager::PROPERTY_EMAIL]['value'] = $newValue;
|
||||||
$accountManager->updateUser($user, $accountData);
|
$accountManager->updateUser($user, $accountData);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'displayName':
|
case 'displayName':
|
||||||
if ($accountData[AccountManager::PROPERTY_DISPLAYNAME]['value'] !== $newValue) {
|
if ($accountData[IAccountManager::PROPERTY_DISPLAYNAME]['value'] !== $newValue) {
|
||||||
$accountData[AccountManager::PROPERTY_DISPLAYNAME]['value'] = $newValue;
|
$accountData[IAccountManager::PROPERTY_DISPLAYNAME]['value'] = $newValue;
|
||||||
$accountManager->updateUser($user, $accountData);
|
$accountManager->updateUser($user, $accountData);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -23,6 +23,7 @@ namespace Test\Accounts;
|
||||||
|
|
||||||
use OC\Accounts\AccountManager;
|
use OC\Accounts\AccountManager;
|
||||||
use OC\Accounts\Hooks;
|
use OC\Accounts\Hooks;
|
||||||
|
use OCP\Accounts\IAccountManager;
|
||||||
use OCP\IUser;
|
use OCP\IUser;
|
||||||
use PHPUnit\Framework\MockObject\MockObject;
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
@ -77,11 +78,11 @@ class HooksTest extends TestCase {
|
||||||
$this->accountManager->expects($this->once())->method('getUser')->willReturn($data);
|
$this->accountManager->expects($this->once())->method('getUser')->willReturn($data);
|
||||||
$newData = $data;
|
$newData = $data;
|
||||||
if ($setEmail) {
|
if ($setEmail) {
|
||||||
$newData[AccountManager::PROPERTY_EMAIL]['value'] = $params['value'];
|
$newData[IAccountManager::PROPERTY_EMAIL]['value'] = $params['value'];
|
||||||
$this->accountManager->expects($this->once())->method('updateUser')
|
$this->accountManager->expects($this->once())->method('updateUser')
|
||||||
->with($params['user'], $newData);
|
->with($params['user'], $newData);
|
||||||
} elseif ($setDisplayName) {
|
} elseif ($setDisplayName) {
|
||||||
$newData[AccountManager::PROPERTY_DISPLAYNAME]['value'] = $params['value'];
|
$newData[IAccountManager::PROPERTY_DISPLAYNAME]['value'] = $params['value'];
|
||||||
$this->accountManager->expects($this->once())->method('updateUser')
|
$this->accountManager->expects($this->once())->method('updateUser')
|
||||||
->with($params['user'], $newData);
|
->with($params['user'], $newData);
|
||||||
} else {
|
} else {
|
||||||
|
@ -98,48 +99,48 @@ class HooksTest extends TestCase {
|
||||||
[
|
[
|
||||||
['feature' => '', 'value' => ''],
|
['feature' => '', 'value' => ''],
|
||||||
[
|
[
|
||||||
AccountManager::PROPERTY_EMAIL => ['value' => ''],
|
IAccountManager::PROPERTY_EMAIL => ['value' => ''],
|
||||||
AccountManager::PROPERTY_DISPLAYNAME => ['value' => '']
|
IAccountManager::PROPERTY_DISPLAYNAME => ['value' => '']
|
||||||
],
|
],
|
||||||
false, false, true
|
false, false, true
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
['user' => $user, 'value' => ''],
|
['user' => $user, 'value' => ''],
|
||||||
[
|
[
|
||||||
AccountManager::PROPERTY_EMAIL => ['value' => ''],
|
IAccountManager::PROPERTY_EMAIL => ['value' => ''],
|
||||||
AccountManager::PROPERTY_DISPLAYNAME => ['value' => '']
|
IAccountManager::PROPERTY_DISPLAYNAME => ['value' => '']
|
||||||
],
|
],
|
||||||
false, false, true
|
false, false, true
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
['user' => $user, 'feature' => ''],
|
['user' => $user, 'feature' => ''],
|
||||||
[
|
[
|
||||||
AccountManager::PROPERTY_EMAIL => ['value' => ''],
|
IAccountManager::PROPERTY_EMAIL => ['value' => ''],
|
||||||
AccountManager::PROPERTY_DISPLAYNAME => ['value' => '']
|
IAccountManager::PROPERTY_DISPLAYNAME => ['value' => '']
|
||||||
],
|
],
|
||||||
false, false, true
|
false, false, true
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
['user' => $user, 'feature' => 'foo', 'value' => 'bar'],
|
['user' => $user, 'feature' => 'foo', 'value' => 'bar'],
|
||||||
[
|
[
|
||||||
AccountManager::PROPERTY_EMAIL => ['value' => 'oldMail@example.com'],
|
IAccountManager::PROPERTY_EMAIL => ['value' => 'oldMail@example.com'],
|
||||||
AccountManager::PROPERTY_DISPLAYNAME => ['value' => 'oldDisplayName']
|
IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'oldDisplayName']
|
||||||
],
|
],
|
||||||
false, false, false
|
false, false, false
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
['user' => $user, 'feature' => 'eMailAddress', 'value' => 'newMail@example.com'],
|
['user' => $user, 'feature' => 'eMailAddress', 'value' => 'newMail@example.com'],
|
||||||
[
|
[
|
||||||
AccountManager::PROPERTY_EMAIL => ['value' => 'oldMail@example.com'],
|
IAccountManager::PROPERTY_EMAIL => ['value' => 'oldMail@example.com'],
|
||||||
AccountManager::PROPERTY_DISPLAYNAME => ['value' => 'oldDisplayName']
|
IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'oldDisplayName']
|
||||||
],
|
],
|
||||||
true, false, false
|
true, false, false
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
['user' => $user, 'feature' => 'displayName', 'value' => 'newDisplayName'],
|
['user' => $user, 'feature' => 'displayName', 'value' => 'newDisplayName'],
|
||||||
[
|
[
|
||||||
AccountManager::PROPERTY_EMAIL => ['value' => 'oldMail@example.com'],
|
IAccountManager::PROPERTY_EMAIL => ['value' => 'oldMail@example.com'],
|
||||||
AccountManager::PROPERTY_DISPLAYNAME => ['value' => 'oldDisplayName']
|
IAccountManager::PROPERTY_DISPLAYNAME => ['value' => 'oldDisplayName']
|
||||||
],
|
],
|
||||||
false, true, false
|
false, true, false
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in New Issue