Merge pull request #13 from hcvcastro/master

Add initial cache support
pull/1/head
Andras Timar 8 years ago
commit 789d0050fb

@ -22,21 +22,21 @@ use \OCA\Richdocuments\AppConfig;
class Application extends App {
public function __construct (array $urlParams = array()) {
parent::__construct('richdocuments', $urlParams);
$container = $this->getContainer();
/**
* Controllers
*/
$container->registerService('UserController', function($c) {
return new UserController(
$c->query('AppName'),
$c->query('AppName'),
$c->query('Request')
);
});
$container->registerService('SessionController', function($c) {
return new SessionController(
$c->query('AppName'),
$c->query('AppName'),
$c->query('Request'),
$c->query('Logger'),
$c->query('UserId')
@ -44,29 +44,31 @@ class Application extends App {
});
$container->registerService('DocumentController', function($c) {
return new DocumentController(
$c->query('AppName'),
$c->query('AppName'),
$c->query('Request'),
$c->query('CoreConfig'),
$c->query('L10N'),
$c->query('UserId')
$c->query('UserId'),
$c->query('ICacheFactory'),
$c->query('Logger')
);
});
$container->registerService('SettingsController', function($c) {
return new SettingsController(
$c->query('AppName'),
$c->query('AppName'),
$c->query('Request'),
$c->query('L10N'),
$c->query('AppConfig'),
$c->query('UserId')
);
});
$container->registerService('AppConfig', function($c) {
return new AppConfig(
$c->query('CoreConfig')
);
});
/**
* Core
*/
@ -84,5 +86,8 @@ class Application extends App {
$uid = is_null($user) ? '' : $user->getUID();
return $uid;
});
$container->registerService('ICacheFactory', function($c) {
return $c->query('ServerContainer')->getMemCacheFactory();
});
}
}

@ -25,23 +25,29 @@ use \OCA\Richdocuments\Storage;
use \OCA\Richdocuments\Download;
use \OCA\Richdocuments\DownloadResponse;
use \OCA\Richdocuments\File;
use OCA\Richdocuments\Genesis;
use \OCA\Richdocuments\Genesis;
use \OC\Files\View;
use \OCP\ICacheFactory;
use \OCP\ILogger;
class DocumentController extends Controller{
private $uid;
private $l10n;
private $settings;
private $cache;
private $logger;
const ODT_TEMPLATE_PATH = '/assets/odttemplate.odt';
const CLOUDSUITE_TMP_PATH = '/documents-tmp/';
public function __construct($appName, IRequest $request, IConfig $settings, IL10N $l10n, $uid){
public function __construct($appName, IRequest $request, IConfig $settings, IL10N $l10n, $uid, ICacheFactory $cache, ILogger $logger){
parent::__construct($appName, $request);
$this->uid = $uid;
$this->l10n = $l10n;
$this->settings = $settings;
$this->cache = $cache->create($appName);
$this->logger = $logger;
}
/**
@ -51,6 +57,7 @@ class DocumentController extends Controller{
public function index(){
\OC::$server->getNavigationManager()->setActiveEntry( 'richdocuments_index' );
$maxUploadFilesize = \OCP\Util::maxUploadFilesize("/");
$wopiRemote = $this->settings->getAppValue('richdocuments', 'wopi_url');
$response = new TemplateResponse('richdocuments', 'documents', [
'enable_previews' => $this->settings->getSystemValue('enable_previews', true),
'useUnstable' => $this->settings->getAppValue('richdocuments', 'unstable', 'false'),
@ -58,17 +65,55 @@ class DocumentController extends Controller{
'uploadMaxFilesize' => $maxUploadFilesize,
'uploadMaxHumanFilesize' => \OCP\Util::humanFileSize($maxUploadFilesize),
'allowShareWithLink' => $this->settings->getAppValue('core', 'shareapi_allow_links', 'yes'),
'wopi_url' => $this->settings->getAppValue('richdocuments', 'wopi_url'),
'wopi_url' => $wopiRemote,
]);
$policy = new ContentSecurityPolicy();
+ $policy->addAllowedScriptDomain('\'self\' http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js http://cdnjs.cloudflare.com/ajax/libs/jquery-mousewheel/3.1.12/jquery.mousewheel.min.js \'unsafe-eval\' ' . $this->settings->getAppValue('richdocuments', 'wopi_url'));
+ $policy->addAllowedFrameDomain('\'self\' http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js http://cdnjs.cloudflare.com/ajax/libs/jquery-mousewheel/3.1.12/jquery.mousewheel.min.js \'unsafe-eval\' ' . $this->settings->getAppValue('richdocuments', 'wopi_url'));
$policy->addAllowedScriptDomain('\'self\' http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js http://cdnjs.cloudflare.com/ajax/libs/jquery-mousewheel/3.1.12/jquery.mousewheel.min.js \'unsafe-eval\' ' . $wopiRemote);
$policy->addAllowedFrameDomain('\'self\' http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js http://cdnjs.cloudflare.com/ajax/libs/jquery-mousewheel/3.1.12/jquery.mousewheel.min.js \'unsafe-eval\' ' . $wopiRemote);
$policy->addAllowedConnectDomain('ws://' . $_SERVER['SERVER_NAME'] . ':9980');
$policy->addAllowedImageDomain('*');
$policy->allowInlineScript(true);
$policy->addAllowedFontDomain('data:');
$response->setContentSecurityPolicy($policy);
$discovery = $this->cache->get('discovery.xml');
if(is_null($discovery)) {
if (($parts = parse_url($wopiRemote))) {
// Provides access to information about the capabilities of a WOPI client
// and the mechanisms for invoking those abilities through URIs.
// HTTP://server/hosting/discovery
$wopiDiscovery = sprintf(
"%s%s%s%s",
isset($parts['scheme']) ? $parts['scheme'] . "://" : '',
isset($parts['host']) ? $parts['host'] : '',
isset($parts['port']) ? ":" . $parts['port'] : '',
"/hosting/discovery" );
try {
$wopiClient = \OC::$server->getHTTPClientService()->newClient();
$xml = $wopiClient->get($wopiDiscovery)->getBody();
if ($xml) {
$loadEntities = libxml_disable_entity_loader(true);
$data = simplexml_load_string($xml);
libxml_disable_entity_loader($loadEntities);
if ($data !== false) {
// default ttl
$this->cache->set('discovery.xml', $xml);
}
else {
$this->logger->error('failure discovery.xml not well-formed XML string');
}
}
else {
$this->logger->error('failure response discovery.xml');
}
} catch (\Exception $e) {
$this->logger->error(
sprintf('Error getting discovery.xml: %s', $e->getMessage()));
}
}
}
return $response;
}

@ -16,10 +16,12 @@ class DocumentControllerTest extends \PHPUnit_Framework_TestCase {
private $request;
private $l10n;
private $settings;
private $cache;
private $logger;
private $uid = 'jack_the_documents_tester';
private $password = 'password';
private $controller;
public function setUp(){
$this->request = $this->getMockBuilder('\OCP\IRequest')
->disableOriginalConstructor()
@ -33,14 +35,24 @@ class DocumentControllerTest extends \PHPUnit_Framework_TestCase {
->disableOriginalConstructor()
->getMock()
;
$this->cache = $this->getMockBuilder('\OCP\ICacheFactory')
->disableOriginalConstructor()
->getMock()
;
$this->logger = $this->getMockBuilder('\OCP\ILogger')
->disableOriginalConstructor()
->getMock()
;
$this->controller = new DocumentController(
$this->appName,
$this->request,
$this->settings,
$this->l10n,
$this->uid
$this->uid,
$this->cache,
$this->logger
);
$userManager = \OC::$server->getUserManager();
$userSession = \OC::$server->getUserSession();
if (!$userManager->userExists($this->uid)){

Loading…
Cancel
Save