Merge pull request #124 from pranavk/testserver

New test server option for specific groups
pull/1/head
Andras Timar 8 years ago committed by GitHub
commit 974318a056

@ -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") {
@ -262,16 +292,22 @@ class DocumentController extends Controller {
return $this->responseError($this->l10n->t('Collabora Online: Invalid URL "%s".', array($wopiRemote)), $this->l10n->t('Please ask your administrator to check the Collabora Online server setting.'));
}
$user = \OC::$server->getUserSession()->getUser();
$usergroups = array_filter(\OC::$server->getGroupManager()->getUserGroupIds($user));
$usergroups = join('|', $usergroups);
\OC::$server->getLogger()->debug('User is in groups: {groups}', [ 'app' => $this->appName, 'groups' => $usergroups ]);
\OC::$server->getNavigationManager()->setActiveEntry( 'richdocuments_index' );
$maxUploadFilesize = \OCP\Util::maxUploadFilesize("/");
$response = new TemplateResponse('richdocuments', 'documents', [
'enable_previews' => $this->settings->getSystemValue('enable_previews', true),
'enable_previews' => $this->settings->getSystemValue('enable_previews', true),
'uploadMaxFilesize' => $maxUploadFilesize,
'uploadMaxHumanFilesize' => \OCP\Util::humanFileSize($maxUploadFilesize),
'allowShareWithLink' => $this->settings->getAppValue('core', 'shareapi_allow_links', 'yes'),
'allowShareWithLink' => $this->settings->getAppValue('core', 'shareapi_allow_links', 'yes'),
'wopi_url' => $webSocket,
'edit_groups' => $this->appConfig->getAppValue('edit_groups'),
'doc_format' => $this->appConfig->getAppValue('doc_format')
'doc_format' => $this->appConfig->getAppValue('doc_format'),
'usergroups' => $usergroups
]);
$policy = new ContentSecurityPolicy();
@ -350,7 +386,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');

@ -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,52 @@ var documentsSettings = {
}
},
initTestWopiServer: function() {
var groups = $(document).find('#test_server_group_select').val();
var testserver = $(document).find('#test_wopi_url').val();
if (groups === '' || testserver === '') {
$('.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('');
page.find('#test-server-section').toggleClass('hidden', !this.checked);
if (this.checked) {
OC.Settings.setupGroupsSelect($select, {
placeholder: t('core', 'None')
});
} else {
$select.select2('destroy');
page.find('#test_wopi_url').val('');
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;

@ -19,27 +19,17 @@ $.widget('oc.documentGrid', {
that._render();
if (!documentsMain.isGuest) {
$.ajax({
url: OC.generateUrl('/settings/users/users'),
type: 'get',
data: { limit: 1, pattern: OC.currentUser },
async: false,
success: function(result) {
var editGroups = $('#edit_groups').val();
documentsMain.canEdit = (editGroups === '');
if (!documentsMain.canEdit && result.length >= 1) {
for (var idx in result[0].groups) {
if (editGroups.indexOf(result[0].groups[idx]) !== -1) {
documentsMain.canEdit = true;
break;
}
}
var editGroups = $('#edit_groups').val().split('|');
var usergroups = $('#usergroups').val().split('|');
documentsMain.canEdit = (editGroups.length === 0);
if (!documentsMain.canEdit && usergroups.length >= 1) {
for (var idx in usergroups) {
if (editGroups.indexOf(usergroups[idx]) !== -1) {
documentsMain.canEdit = true;
break;
}
},
error: function() {
console.log('Error fetching information about current user.');
}
});
}
}
documentsMain.renderComplete = true;

@ -5,14 +5,28 @@ script('richdocuments', 'admin');
<h2><?php p($l->t('Collabora Online')) ?></h2>
<label for="wopi_url"><?php p($l->t('Collabora Online server')) ?></label>
<input type="text" name="wopi_url" id="wopi_url" value="<?php p($_['wopi_url'])?>" style="width:300px;">
<br /><em><?php p($l->t('URL (and port) of the Collabora Online server that provides the editing functionality as a WOPI client.')) ?></em>
<br /><button type="button" id="wopi_apply"><?php p($l->t('Apply')) ?></button>
<br/><em><?php p($l->t('URL (and port) of the Collabora Online server that provides the editing functionality as a WOPI client.')) ?></em>
<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 server for specific groups')) ?></label><br/>
<p id="test-server-section" class="indent <?php if ($_['test_server_groups'] === '' || $_['test_wopi_url'] === '') p('hidden') ?>">
<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" /><br/>
<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/>
<em><?php p($l->t('URL (and port) of the Collabora Online test server.')) ?></em><br/>
<button type="button" id="test_wopi_apply"><?php p($l->t('Apply')) ?></button>
<span id="test-documents-admin-msg" class="msg"></span>
</p>
<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>

@ -53,3 +53,4 @@ script('files', 'jquery.fileupload');
<?php endif; ?>
<input type="hidden" name="allowShareWithLink" id="allowShareWithLink" value="<?php p($_['allowShareWithLink']) ?>" />
<input type="hidden" name="edit_groups" id="edit_groups" value="<?php p($_['edit_groups']) ?>" />
<input type="hidden" name="usergroups" id="usergroups" value="<?php p($_['usergroups']) ?>" />

Loading…
Cancel
Save