New test server option for specific groups
This commit is contained in:
parent
419bd3b65e
commit
e593c34fdd
@ -121,12 +121,42 @@ class DocumentController extends Controller {
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the original wopi url or test wopi url
|
||||
* This depends on whether current user is the member of one of the groups
|
||||
* mentioned in settings in which case different wopi url (aka
|
||||
* test_wopi_url) is used
|
||||
*/
|
||||
private function getWopiUrl() {
|
||||
$wopiurl = $this->appConfig->getAppValue('wopi_url');
|
||||
|
||||
$user = \OC::$server->getUserSession()->getUser()->getUID();
|
||||
$testgroups = array_filter(explode('|', $this->appConfig->getAppValue('test_server_groups')));
|
||||
\OC::$server->getLogger()->debug('Testgroups are {testgroups}', [
|
||||
'app' => $this->appName,
|
||||
'testgroups' => $testgroups
|
||||
]);
|
||||
foreach ($testgroups as $testgroup) {
|
||||
$test = \OC::$server->getGroupManager()->get($testgroup);
|
||||
if (sizeof($test->searchUsers($user)) > 0) {
|
||||
\OC::$server->getLogger()->debug('User {user} found in {group}', [
|
||||
'app' => $this->appName,
|
||||
'user' => $user,
|
||||
'group' => $testgroup
|
||||
]);
|
||||
return $this->appConfig->getAppValue('test_wopi_url');
|
||||
}
|
||||
}
|
||||
|
||||
return $wopiurl;
|
||||
}
|
||||
|
||||
/** Return the content of discovery.xml - either from cache, or download it.
|
||||
*/
|
||||
private function getDiscovery(){
|
||||
\OC::$server->getLogger()->debug('getDiscovery(): Getting discovery.xml from the cache.');
|
||||
|
||||
$wopiRemote = $this->appConfig->getAppValue('wopi_url');
|
||||
$wopiRemote = $this->getWopiUrl();
|
||||
|
||||
// Provides access to information about the capabilities of a WOPI client
|
||||
// and the mechanisms for invoking those abilities through URIs.
|
||||
@ -188,7 +218,7 @@ class DocumentController extends Controller {
|
||||
|
||||
if ($discovery_parsed === false) {
|
||||
$this->cache->remove('discovery.xml');
|
||||
$wopiRemote = $this->appConfig->getAppValue('wopi_url');
|
||||
$wopiRemote = $this->getWopiUrl();
|
||||
|
||||
return array(
|
||||
'status' => 'error',
|
||||
@ -246,7 +276,7 @@ class DocumentController extends Controller {
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function index(){
|
||||
$wopiRemote = $this->appConfig->getAppValue('wopi_url');
|
||||
$wopiRemote = $this->getWopiUrl();
|
||||
if (($parts = parse_url($wopiRemote)) && isset($parts['scheme']) && isset($parts['host'])) {
|
||||
$webSocketProtocol = "ws://";
|
||||
if ($parts['scheme'] == "https") {
|
||||
@ -350,7 +380,7 @@ class DocumentController extends Controller {
|
||||
|
||||
if ($discovery_parsed === false) {
|
||||
$this->cache->remove('discovery.xml');
|
||||
$wopiRemote = $this->appConfig->getAppValue('wopi_url');
|
||||
$wopiRemote = $this->getWopiUrl();
|
||||
|
||||
return array(
|
||||
'status' => 'error',
|
||||
|
@ -49,7 +49,9 @@ class SettingsController extends Controller{
|
||||
public function getSettings() {
|
||||
return array(
|
||||
'doc_format' => $this->appConfig->getAppValue('doc_format'),
|
||||
'wopi_url' => $this->appConfig->getAppValue('wopi_url')
|
||||
'wopi_url' => $this->appConfig->getAppValue('wopi_url'),
|
||||
'test_wopi_url' => $this->appConfig->getAppValue('test_wopi_url'),
|
||||
'test_server_groups' => $this->appConfig->getAppValue('test_server_groups')
|
||||
);
|
||||
}
|
||||
|
||||
@ -74,13 +76,15 @@ class SettingsController extends Controller{
|
||||
[
|
||||
'wopi_url' => $this->appConfig->getAppValue('wopi_url'),
|
||||
'edit_groups' => $this->appConfig->getAppValue('edit_groups'),
|
||||
'doc_format' => $this->appConfig->getAppValue('doc_format')
|
||||
'doc_format' => $this->appConfig->getAppValue('doc_format'),
|
||||
'test_wopi_url' => $this->appConfig->getAppValue('test_wopi_url'),
|
||||
'test_server_groups' => $this->appConfig->getAppValue('test_server_groups')
|
||||
],
|
||||
'blank'
|
||||
);
|
||||
}
|
||||
|
||||
public function setSettings($wopi_url, $edit_groups, $doc_format){
|
||||
public function setSettings($wopi_url, $edit_groups, $doc_format, $test_wopi_url, $test_server_groups){
|
||||
if (!is_null($wopi_url)){
|
||||
$this->appConfig->setAppValue('wopi_url', $wopi_url);
|
||||
}
|
||||
@ -93,6 +97,14 @@ class SettingsController extends Controller{
|
||||
$this->appConfig->setAppValue('doc_format', $doc_format);
|
||||
}
|
||||
|
||||
if (!is_null($test_wopi_url)){
|
||||
$this->appConfig->setAppValue('test_wopi_url', $test_wopi_url);
|
||||
}
|
||||
|
||||
if (!is_null($test_server_groups)){
|
||||
$this->appConfig->setAppValue('test_server_groups', $test_server_groups);
|
||||
}
|
||||
|
||||
$richMemCache = \OC::$server->getMemCacheFactory()->create('richdocuments');
|
||||
$richMemCache->clear('discovery.xml');
|
||||
|
||||
|
76
js/admin.js
76
js/admin.js
@ -33,6 +33,25 @@ var documentsSettings = {
|
||||
);
|
||||
},
|
||||
|
||||
saveTestWopi: function(groups, server) {
|
||||
var data = {
|
||||
'test_wopi_url': server,
|
||||
'test_server_groups': groups
|
||||
};
|
||||
|
||||
OC.msg.startAction('#test-documents-admin-msg', t('richdocuments', 'Saving...'));
|
||||
$.post(
|
||||
OC.filePath('richdocuments', 'ajax', 'admin.php'),
|
||||
data,
|
||||
documentsSettings.afterSaveTestWopi
|
||||
);
|
||||
},
|
||||
|
||||
afterSaveTestWopi: function(response) {
|
||||
$('#test_wopi_apply').attr('disabled', false);
|
||||
OC.msg.finishedAction('#test-documents-admin-msg', response);
|
||||
},
|
||||
|
||||
afterSave : function(response){
|
||||
$('#wopi_apply').attr('disabled', false);
|
||||
OC.msg.finishedAction('#documents-admin-msg', response);
|
||||
@ -48,9 +67,64 @@ var documentsSettings = {
|
||||
}
|
||||
},
|
||||
|
||||
initTestWopiServer: function() {
|
||||
var groups = $(document).find('#test_server_group_select').val();
|
||||
var testserver = $(document).find('#test_wopi_url').val();
|
||||
|
||||
if (groups === '' || testserver === '') {
|
||||
$(document).find('label[for="test_server_group_select"]').hide();
|
||||
$(document).find('label[for="test_wopi_url"]').hide();
|
||||
$(document).find('#test_wopi_url').hide();
|
||||
$(document).find('#test_wopi_apply').hide();
|
||||
$('.test-server-enable').attr('checked', null);
|
||||
} else {
|
||||
OC.Settings.setupGroupsSelect($('#test_server_group_select'));
|
||||
$('.test-server-enable').attr('checked', 'checked');
|
||||
}
|
||||
},
|
||||
|
||||
initialize: function() {
|
||||
$('#wopi_apply').on('click', documentsSettings.save);
|
||||
documentsSettings.initEditGroups();
|
||||
documentsSettings.initTestWopiServer();
|
||||
|
||||
$('#wopi_apply').on('click', documentsSettings.save);
|
||||
|
||||
$(document).on('change', '.test-server-enable', function() {
|
||||
var page = $(this).parent();
|
||||
var $select = page.find('#test_server_group_select');
|
||||
$select.val('');
|
||||
|
||||
if (this.checked) {
|
||||
page.find('label[for="test_server_group_select"]').show();
|
||||
page.find('label[for="test_wopi_url"]').show();
|
||||
page.find('#test_wopi_apply').show();
|
||||
page.find('#test_wopi_url').show();
|
||||
|
||||
OC.Settings.setupGroupsSelect($select, {
|
||||
placeholder: t('core', 'None')
|
||||
});
|
||||
} else {
|
||||
page.find('label[for="test_server_group_select"]').hide();
|
||||
page.find('label[for="test_wopi_url"]').hide();
|
||||
page.find('#test_wopi_apply').hide();
|
||||
page.find('#test_wopi_url').val('');
|
||||
page.find('#test_wopi_url').hide();
|
||||
$select.select2('destroy');
|
||||
|
||||
documentsSettings.saveTestWopi('', '');
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on('click', '#test_wopi_apply', function() {
|
||||
var groups = $(this).parent().find('#test_server_group_select').val();
|
||||
var testserver = $(this).parent().find('#test_wopi_url').val();
|
||||
|
||||
if (groups !== '' && testserver !== '') {
|
||||
documentsSettings.saveTestWopi(groups, testserver);
|
||||
} else {
|
||||
OC.msg.finishedError('#test-documents-admin-msg', 'Both fields required');
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on('change', '.doc-format-ooxml', function() {
|
||||
var ooxml = this.checked;
|
||||
|
@ -9,10 +9,23 @@ script('richdocuments', 'admin');
|
||||
<br /><button type="button" id="wopi_apply"><?php p($l->t('Apply')) ?></button>
|
||||
<span id="documents-admin-msg" class="msg"></span>
|
||||
<br/>
|
||||
<input type="checkbox" class="edit-groups-enable" id="edit_groups_enable-richdocuments" data-appid="richdocuments" />
|
||||
|
||||
<input type="checkbox" class="test-server-enable" id="test_server_enable-richdocuments" />
|
||||
<label for="test-server-enable"><?php p($l->t('Enable test servers for specific groups')) ?></label>
|
||||
<br/>
|
||||
<label for="test_server_group_select"><?php p($l->t('Groups')) ?></label>
|
||||
<input type="hidden" id="test_server_group_select" value="<?php p($_['test_server_groups'])?>" title="<?php p($l->t('None')); ?>" style="width: 200px" />
|
||||
|
||||
<label for="test_wopi_url"><?php p($l->t('Test server')) ?></label>
|
||||
<input type="text" name="test_wopi_url" id="test_wopi_url" value="<?php p($_['test_wopi_url'])?>" style="width:300px;" />
|
||||
<br/>
|
||||
<button type="button" id="test_wopi_apply"><?php p($l->t('Apply')) ?></button>
|
||||
<span id="test-documents-admin-msg" class="msg"></span>
|
||||
<br/>
|
||||
<input type="checkbox" class="edit-groups-enable" id="edit_groups_enable-richdocuments" />
|
||||
<label for="edit_groups_enable-richdocuments"><?php p($l->t('Enable edit for specific groups')) ?></label>
|
||||
<input type="hidden" id="edit_group_select" value="<?php p($_['edit_groups'])?>" title="<?php p($l->t('All')); ?>" style="width: 200px">
|
||||
<br/>
|
||||
<input type="checkbox" class="doc-format-ooxml" id="doc_format_ooxml_enable-richdocuments" <?php p($_['doc_format'] === 'ooxml' ? 'checked' : '') ?> data-appid="richdocuments" />
|
||||
<input type="checkbox" class="doc-format-ooxml" id="doc_format_ooxml_enable-richdocuments" <?php p($_['doc_format'] === 'ooxml' ? 'checked' : '') ?> />
|
||||
<label for="doc_format_ooxml_enable-richdocuments"><?php p($l->t('Use OOXML by default for new files')) ?></label>
|
||||
</div>
|
||||
</div>
|
Loading…
x
Reference in New Issue
Block a user