-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to tweak default scopes for accounts
Close #6582 Signed-off-by: Thomas Citharel <[email protected]>
- Loading branch information
Showing
4 changed files
with
60 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
* @author Julius Härtl <[email protected]> | ||
* @author Morris Jobke <[email protected]> | ||
* @author Roeland Jago Douma <[email protected]> | ||
* @author Thomas Citharel <[email protected]> | ||
* | ||
* @license AGPL-3.0 | ||
* | ||
|
@@ -34,6 +35,7 @@ | |
use OCP\Accounts\IAccount; | ||
use OCP\Accounts\IAccountManager; | ||
use OCP\BackgroundJob\IJobList; | ||
use OCP\IConfig; | ||
use OCP\IDBConnection; | ||
use OCP\ILogger; | ||
use OCP\IUser; | ||
|
@@ -67,21 +69,29 @@ class AccountManager implements IAccountManager { | |
/** @var ILogger */ | ||
private $logger; | ||
|
||
/** | ||
* AccountManager constructor. | ||
* | ||
* @param IDBConnection $connection | ||
* @param EventDispatcherInterface $eventDispatcher | ||
* @param IJobList $jobList | ||
*/ | ||
/** @var IConfig */ | ||
private $config; | ||
|
||
public const DEFAULT_SCOPE_VALUES = [ | ||
self::PROPERTY_DISPLAYNAME => self::VISIBILITY_CONTACTS_ONLY, | ||
self::PROPERTY_ADDRESS => self::VISIBILITY_PRIVATE, | ||
self::PROPERTY_WEBSITE => self::VISIBILITY_PRIVATE, | ||
self::PROPERTY_EMAIL => self::VISIBILITY_CONTACTS_ONLY, | ||
self::PROPERTY_AVATAR => self::VISIBILITY_CONTACTS_ONLY, | ||
self::PROPERTY_PHONE => self::VISIBILITY_PRIVATE, | ||
self::PROPERTY_TWITTER => self::VISIBILITY_PRIVATE | ||
]; | ||
|
||
public function __construct(IDBConnection $connection, | ||
EventDispatcherInterface $eventDispatcher, | ||
IJobList $jobList, | ||
ILogger $logger) { | ||
ILogger $logger, | ||
IConfig $config) { | ||
$this->connection = $connection; | ||
$this->eventDispatcher = $eventDispatcher; | ||
$this->jobList = $jobList; | ||
$this->logger = $logger; | ||
$this->config = $config; | ||
} | ||
|
||
/** | ||
|
@@ -298,45 +308,48 @@ protected function updateExistingUser(IUser $user, $data) { | |
* @return array | ||
*/ | ||
protected function buildDefaultUserRecord(IUser $user) { | ||
$scopes = array_merge(self::DEFAULT_SCOPE_VALUES, array_filter($this->config->getSystemValue('account_manager_default_property_scope', []), function (string $scope) { | ||
return in_array($scope, self::VISIBILITIES_LIST, true); | ||
})); | ||
return [ | ||
self::PROPERTY_DISPLAYNAME => | ||
[ | ||
'value' => $user->getDisplayName(), | ||
'scope' => self::VISIBILITY_CONTACTS_ONLY, | ||
'scope' => $scopes[self::PROPERTY_DISPLAYNAME], | ||
'verified' => self::NOT_VERIFIED, | ||
], | ||
self::PROPERTY_ADDRESS => | ||
[ | ||
'value' => '', | ||
'scope' => self::VISIBILITY_PRIVATE, | ||
'scope' => $scopes[self::PROPERTY_ADDRESS], | ||
'verified' => self::NOT_VERIFIED, | ||
], | ||
self::PROPERTY_WEBSITE => | ||
[ | ||
'value' => '', | ||
'scope' => self::VISIBILITY_PRIVATE, | ||
'scope' => $scopes[self::PROPERTY_WEBSITE], | ||
'verified' => self::NOT_VERIFIED, | ||
], | ||
self::PROPERTY_EMAIL => | ||
[ | ||
'value' => $user->getEMailAddress(), | ||
'scope' => self::VISIBILITY_CONTACTS_ONLY, | ||
'scope' => $scopes[self::PROPERTY_EMAIL], | ||
'verified' => self::NOT_VERIFIED, | ||
], | ||
self::PROPERTY_AVATAR => | ||
[ | ||
'scope' => self::VISIBILITY_CONTACTS_ONLY | ||
'scope' => $scopes[self::PROPERTY_AVATAR], | ||
], | ||
self::PROPERTY_PHONE => | ||
[ | ||
'value' => '', | ||
'scope' => self::VISIBILITY_PRIVATE, | ||
'scope' => $scopes[self::PROPERTY_PHONE], | ||
'verified' => self::NOT_VERIFIED, | ||
], | ||
self::PROPERTY_TWITTER => | ||
[ | ||
'value' => '', | ||
'scope' => self::VISIBILITY_PRIVATE, | ||
'scope' => $scopes[self::PROPERTY_TWITTER], | ||
'verified' => self::NOT_VERIFIED, | ||
], | ||
]; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
* @copyright Copyright (c) 2018 Julius Härtl <[email protected]> | ||
* | ||
* @author Julius Härtl <[email protected]> | ||
* @author Thomas Citharel <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
|
@@ -41,9 +42,15 @@ interface IAccountManager { | |
public const VISIBILITY_PRIVATE = 'private'; | ||
/** only contacts, especially trusted servers can see my contact details */ | ||
public const VISIBILITY_CONTACTS_ONLY = 'contacts'; | ||
/** every body ca see my contact detail, will be published to the lookup server */ | ||
/** everybody can see my contact details, will be published to the lookup server */ | ||
public const VISIBILITY_PUBLIC = 'public'; | ||
|
||
public const VISIBILITIES_LIST = [ | ||
self::VISIBILITY_PRIVATE, | ||
self::VISIBILITY_CONTACTS_ONLY, | ||
self::VISIBILITY_PUBLIC | ||
]; | ||
|
||
public const PROPERTY_AVATAR = 'avatar'; | ||
public const PROPERTY_DISPLAYNAME = 'displayname'; | ||
public const PROPERTY_PHONE = 'phone'; | ||
|
@@ -52,6 +59,16 @@ interface IAccountManager { | |
public const PROPERTY_ADDRESS = 'address'; | ||
public const PROPERTY_TWITTER = 'twitter'; | ||
|
||
public const PROPERTIES_LIST = [ | ||
self::PROPERTY_AVATAR, | ||
self::PROPERTY_DISPLAYNAME, | ||
self::PROPERTY_PHONE, | ||
self::PROPERTY_EMAIL, | ||
self::PROPERTY_WEBSITE, | ||
self::PROPERTY_ADDRESS, | ||
self::PROPERTY_TWITTER | ||
]; | ||
|
||
public const NOT_VERIFIED = '0'; | ||
public const VERIFICATION_IN_PROGRESS = '1'; | ||
public const VERIFIED = '2'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
<?php | ||
/** | ||
* @author Björn Schießle <[email protected]> | ||
* @author Thomas Citharel <[email protected]> | ||
* | ||
* @copyright Copyright (c) 2016, ownCloud, Inc. | ||
* @license AGPL-3.0 | ||
|
@@ -25,6 +26,7 @@ | |
use OC\Accounts\AccountManager; | ||
use OCP\Accounts\IAccountManager; | ||
use OCP\BackgroundJob\IJobList; | ||
use OCP\IConfig; | ||
use OCP\ILogger; | ||
use OCP\IUser; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
|
@@ -55,12 +57,16 @@ class AccountsManagerTest extends TestCase { | |
/** @var ILogger|MockObject */ | ||
private $logger; | ||
|
||
/** @var IConfig|MockObject */ | ||
private $config; | ||
|
||
protected function setUp(): void { | ||
parent::setUp(); | ||
$this->eventDispatcher = $this->createMock(EventDispatcherInterface::class); | ||
$this->connection = \OC::$server->getDatabaseConnection(); | ||
$this->jobList = $this->createMock(IJobList::class); | ||
$this->logger = $this->createMock(ILogger::class); | ||
$this->config = $this->createMock(IConfig::class); | ||
} | ||
|
||
protected function tearDown(): void { | ||
|
@@ -77,7 +83,7 @@ protected function tearDown(): void { | |
*/ | ||
public function getInstance($mockedMethods = null) { | ||
return $this->getMockBuilder(AccountManager::class) | ||
->setConstructorArgs([$this->connection, $this->eventDispatcher, $this->jobList, $this->logger]) | ||
->setConstructorArgs([$this->connection, $this->eventDispatcher, $this->jobList, $this->logger, $this->config]) | ||
->setMethods($mockedMethods) | ||
->getMock(); | ||
} | ||
|