Merge pull request #124 from pranavk/testserver
New test server option for specific groups
This commit is contained in:
commit
974318a056
@ -121,12 +121,42 @@ class DocumentController extends Controller {
|
|||||||
return $response;
|
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.
|
/** Return the content of discovery.xml - either from cache, or download it.
|
||||||
*/
|
*/
|
||||||
private function getDiscovery(){
|
private function getDiscovery(){
|
||||||
\OC::$server->getLogger()->debug('getDiscovery(): Getting discovery.xml from the cache.');
|
\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
|
// Provides access to information about the capabilities of a WOPI client
|
||||||
// and the mechanisms for invoking those abilities through URIs.
|
// and the mechanisms for invoking those abilities through URIs.
|
||||||
@ -188,7 +218,7 @@ class DocumentController extends Controller {
|
|||||||
|
|
||||||
if ($discovery_parsed === false) {
|
if ($discovery_parsed === false) {
|
||||||
$this->cache->remove('discovery.xml');
|
$this->cache->remove('discovery.xml');
|
||||||
$wopiRemote = $this->appConfig->getAppValue('wopi_url');
|
$wopiRemote = $this->getWopiUrl();
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'status' => 'error',
|
'status' => 'error',
|
||||||
@ -246,7 +276,7 @@ class DocumentController extends Controller {
|
|||||||
* @NoCSRFRequired
|
* @NoCSRFRequired
|
||||||
*/
|
*/
|
||||||
public function index(){
|
public function index(){
|
||||||
$wopiRemote = $this->appConfig->getAppValue('wopi_url');
|
$wopiRemote = $this->getWopiUrl();
|
||||||
if (($parts = parse_url($wopiRemote)) && isset($parts['scheme']) && isset($parts['host'])) {
|
if (($parts = parse_url($wopiRemote)) && isset($parts['scheme']) && isset($parts['host'])) {
|
||||||
$webSocketProtocol = "ws://";
|
$webSocketProtocol = "ws://";
|
||||||
if ($parts['scheme'] == "https") {
|
if ($parts['scheme'] == "https") {
|
||||||
@ -262,6 +292,11 @@ 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.'));
|
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' );
|
\OC::$server->getNavigationManager()->setActiveEntry( 'richdocuments_index' );
|
||||||
$maxUploadFilesize = \OCP\Util::maxUploadFilesize("/");
|
$maxUploadFilesize = \OCP\Util::maxUploadFilesize("/");
|
||||||
$response = new TemplateResponse('richdocuments', 'documents', [
|
$response = new TemplateResponse('richdocuments', 'documents', [
|
||||||
@ -271,7 +306,8 @@ class DocumentController extends Controller {
|
|||||||
'allowShareWithLink' => $this->settings->getAppValue('core', 'shareapi_allow_links', 'yes'),
|
'allowShareWithLink' => $this->settings->getAppValue('core', 'shareapi_allow_links', 'yes'),
|
||||||
'wopi_url' => $webSocket,
|
'wopi_url' => $webSocket,
|
||||||
'edit_groups' => $this->appConfig->getAppValue('edit_groups'),
|
'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();
|
$policy = new ContentSecurityPolicy();
|
||||||
@ -350,7 +386,7 @@ class DocumentController extends Controller {
|
|||||||
|
|
||||||
if ($discovery_parsed === false) {
|
if ($discovery_parsed === false) {
|
||||||
$this->cache->remove('discovery.xml');
|
$this->cache->remove('discovery.xml');
|
||||||
$wopiRemote = $this->appConfig->getAppValue('wopi_url');
|
$wopiRemote = $this->getWopiUrl();
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'status' => 'error',
|
'status' => 'error',
|
||||||
|
@ -49,7 +49,9 @@ class SettingsController extends Controller{
|
|||||||
public function getSettings() {
|
public function getSettings() {
|
||||||
return array(
|
return array(
|
||||||
'doc_format' => $this->appConfig->getAppValue('doc_format'),
|
'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'),
|
'wopi_url' => $this->appConfig->getAppValue('wopi_url'),
|
||||||
'edit_groups' => $this->appConfig->getAppValue('edit_groups'),
|
'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'
|
'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)){
|
if (!is_null($wopi_url)){
|
||||||
$this->appConfig->setAppValue('wopi_url', $wopi_url);
|
$this->appConfig->setAppValue('wopi_url', $wopi_url);
|
||||||
}
|
}
|
||||||
@ -93,6 +97,14 @@ class SettingsController extends Controller{
|
|||||||
$this->appConfig->setAppValue('doc_format', $doc_format);
|
$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 = \OC::$server->getMemCacheFactory()->create('richdocuments');
|
||||||
$richMemCache->clear('discovery.xml');
|
$richMemCache->clear('discovery.xml');
|
||||||
|
|
||||||
|
64
js/admin.js
64
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){
|
afterSave : function(response){
|
||||||
$('#wopi_apply').attr('disabled', false);
|
$('#wopi_apply').attr('disabled', false);
|
||||||
OC.msg.finishedAction('#documents-admin-msg', response);
|
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() {
|
initialize: function() {
|
||||||
$('#wopi_apply').on('click', documentsSettings.save);
|
|
||||||
documentsSettings.initEditGroups();
|
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() {
|
$(document).on('change', '.doc-format-ooxml', function() {
|
||||||
var ooxml = this.checked;
|
var ooxml = this.checked;
|
||||||
|
@ -19,27 +19,17 @@ $.widget('oc.documentGrid', {
|
|||||||
that._render();
|
that._render();
|
||||||
|
|
||||||
if (!documentsMain.isGuest) {
|
if (!documentsMain.isGuest) {
|
||||||
$.ajax({
|
var editGroups = $('#edit_groups').val().split('|');
|
||||||
url: OC.generateUrl('/settings/users/users'),
|
var usergroups = $('#usergroups').val().split('|');
|
||||||
type: 'get',
|
documentsMain.canEdit = (editGroups.length === 0);
|
||||||
data: { limit: 1, pattern: OC.currentUser },
|
if (!documentsMain.canEdit && usergroups.length >= 1) {
|
||||||
async: false,
|
for (var idx in usergroups) {
|
||||||
success: function(result) {
|
if (editGroups.indexOf(usergroups[idx]) !== -1) {
|
||||||
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;
|
documentsMain.canEdit = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
error: function() {
|
|
||||||
console.log('Error fetching information about current user.');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
documentsMain.renderComplete = true;
|
documentsMain.renderComplete = true;
|
||||||
|
@ -9,10 +9,24 @@ script('richdocuments', 'admin');
|
|||||||
<br/><button type="button" id="wopi_apply"><?php p($l->t('Apply')) ?></button>
|
<br/><button type="button" id="wopi_apply"><?php p($l->t('Apply')) ?></button>
|
||||||
<span id="documents-admin-msg" class="msg"></span>
|
<span id="documents-admin-msg" class="msg"></span>
|
||||||
<br/>
|
<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>
|
<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">
|
<input type="hidden" id="edit_group_select" value="<?php p($_['edit_groups'])?>" title="<?php p($l->t('All')); ?>" style="width: 200px">
|
||||||
<br/>
|
<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>
|
<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; ?>
|
<?php endif; ?>
|
||||||
<input type="hidden" name="allowShareWithLink" id="allowShareWithLink" value="<?php p($_['allowShareWithLink']) ?>" />
|
<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="edit_groups" id="edit_groups" value="<?php p($_['edit_groups']) ?>" />
|
||||||
|
<input type="hidden" name="usergroups" id="usergroups" value="<?php p($_['usergroups']) ?>" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user