Compare commits

...

1 Commits

Author SHA1 Message Date
Thomas Citharel f4fe762859
Allow to tweak default scopes for accounts
Close #6582

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
2020-04-27 18:59:12 +02:00
4 changed files with 60 additions and 17 deletions

View File

@ -1805,4 +1805,11 @@ $CONFIG = [
*/
'login_form_autocomplete' => true,
/**
* Allows to override the default visibility scopes for Account data.
* The list of overridable properties and valid values for visibility are in
* OCP\Accounts\IAccountManager. Default values are in OC\Accounts\AccountManager
*/
'account_manager_default_property_scope' => []
];

View File

@ -11,6 +11,7 @@
* @author Julius Härtl <jus@bitgrid.net>
* @author Morris Jobke <hey@morrisjobke.de>
* @author Roeland Jago Douma <roeland@famdouma.nl>
* @author Thomas Citharel <nextcloud@tcit.fr>
*
* @license AGPL-3.0
*
@ -34,6 +35,7 @@ use OCA\Settings\BackgroundJobs\VerifyUserData;
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 @@ class AccountManager implements IAccountManager {
* @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,
],
];

View File

@ -6,6 +6,7 @@ declare(strict_types=1);
* @copyright Copyright (c) 2018 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
* @author Thomas Citharel <nextcloud@tcit.fr>
*
* @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';

View File

@ -1,6 +1,7 @@
<?php
/**
* @author Björn Schießle <schiessle@owncloud.com>
* @author Thomas Citharel <nextcloud@tcit.fr>
*
* @copyright Copyright (c) 2016, ownCloud, Inc.
* @license AGPL-3.0
@ -25,6 +26,7 @@ use OC\Accounts\Account;
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 @@ class AccountsManagerTest extends TestCase {
*/
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();
}