add option to auto add servers to the list of trusted servers once a federated share was created and accepted successfully

This commit is contained in:
Björn Schießle 2015-11-18 15:07:41 +01:00
parent 8f55b1a27d
commit 2754afc074
9 changed files with 67 additions and 8 deletions

View File

@ -73,7 +73,8 @@ class Application extends \OCP\AppFramework\App {
\OC::$server->getHTTPClientService(),
\OC::$server->getLogger(),
\OC::$server->getJobList(),
\OC::$server->getSecureRandom()
\OC::$server->getSecureRandom(),
\OC::$server->getConfig()
);
});

View File

@ -35,6 +35,11 @@ $application->registerRoutes(
'url' => '/trusted-servers/{id}',
'verb' => 'DELETE'
],
[
'name' => 'Settings#autoAddServers',
'url' => '/auto-add-servers',
'verb' => 'POST'
],
]
]
);

View File

@ -85,7 +85,8 @@ class GetSharedSecret extends QueuedJob{
\OC::$server->getHTTPClientService(),
\OC::$server->getLogger(),
$this->jobList,
\OC::$server->getSecureRandom()
\OC::$server->getSecureRandom(),
\OC::$server->getConfig()
);
}
}

View File

@ -77,7 +77,8 @@ class RequestSharedSecret extends QueuedJob {
\OC::$server->getHTTPClientService(),
\OC::$server->getLogger(),
$this->jobList,
\OC::$server->getSecureRandom()
\OC::$server->getSecureRandom(),
\OC::$server->getConfig()
);
}
}

View File

@ -26,6 +26,7 @@ use OCA\Federation\TrustedServers;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IRequest;
@ -86,6 +87,16 @@ class SettingsController extends Controller {
return new DataResponse();
}
/**
* enable/disable to automatically add servers to the list of trusted servers
* once a federated share was created and accepted successfully
*
* @param bool $autoAddServers
*/
public function autoAddServers($autoAddServers) {
$this->trustedServers->setAutoAddServers($autoAddServers);
}
/**
* check if the server should be added to the list of trusted servers or not
*

View File

@ -70,4 +70,13 @@ $(document).ready(function () {
});
$("#ocFederationSettings #autoAddServers").change(function() {
$.post(
OC.generateUrl('/apps/federation/auto-add-servers'),
{
autoAddServers: $(this).is(":checked")
}
);
});
});

View File

@ -25,6 +25,7 @@ namespace OCA\Federation;
use OCP\AppFramework\Http;
use OCP\BackgroundJob\IJobList;
use OCP\Http\Client\IClientService;
use OCP\IConfig;
use OCP\ILogger;
use OCP\Security\ISecureRandom;
@ -52,25 +53,31 @@ class TrustedServers {
/** @var ISecureRandom */
private $secureRandom;
/** @var IConfig */
private $config;
/**
* @param DbHandler $dbHandler
* @param IClientService $httpClientService
* @param ILogger $logger
* @param IJobList $jobList
* @param ISecureRandom $secureRandom
* @param IConfig $config
*/
public function __construct(
DbHandler $dbHandler,
IClientService $httpClientService,
ILogger $logger,
IJobList $jobList,
ISecureRandom $secureRandom
ISecureRandom $secureRandom,
IConfig $config
) {
$this->dbHandler = $dbHandler;
$this->httpClientService = $httpClientService;
$this->logger = $logger;
$this->jobList = $jobList;
$this->secureRandom = $secureRandom;
$this->config = $config;
}
/**
@ -97,6 +104,28 @@ class TrustedServers {
return $result;
}
/**
* enable/disable to automatically add servers to the list of trusted servers
* once a federated share was created and accepted successfully
*
* @param bool $status
*/
public function setAutoAddServers($status) {
$value = $status ? '1' : '0';
$this->config->setAppValue('federation', 'autoAddServers', $value);
}
/**
* return if we automatically add servers to the list of trusted servers
* once a federated share was created and accepted successfully
*
* @return bool
*/
public function getAutoAddServers() {
$value = $this->config->getAppValue('federation', 'autoAddServers', '1');
return $value === '1';
}
/**
* get shared secret for the given server
*

View File

@ -33,9 +33,11 @@ $trustedServers = new \OCA\Federation\TrustedServers(
\OC::$server->getHTTPClientService(),
\OC::$server->getLogger(),
\OC::$server->getJobList(),
\OC::$server->getSecureRandom()
\OC::$server->getSecureRandom(),
\OC::$server->getConfig()
);
$template->assign('trustedServers', $trustedServers->getServers());
$template->assign('autoAddServers', $trustedServers->getAutoAddServers());
return $template->fetchPage();

View File

@ -10,9 +10,9 @@ style('federation', 'settings-admin')
<h2><?php p($l->t('Federation')); ?></h2>
<em><?php p($l->t('ownCloud Federation allows you to connect with other trusted ownClouds to exchange the user directory. For example this will be used to auto-complete external users for federated sharing.')); ?></em>
<p id="ocFederationShareUsers">
<input type="checkbox" class="checkbox" id="shareUsers" />
<label for="shareUsers">Share internal user list with other ownClouds</label>
<p>
<input id="autoAddServers" type="checkbox" class="checkbox" <?php if($_['autoAddServers']) p('checked'); ?> />
<label for="autoAddServers">Add server automatically once a federated share was created successfully</label>
</p>
<h3>Trusted ownCloud Servers</h3>